首页 > 代码库 > redis
redis
172.25.45.11
172.25.45.12
172.25.45.13
redis 是一个高性能的 key-value 数据库。 redis 的出现,很大程度补偿了
memcached 这类 keyvalue 存储的不足,在部分场合可以对关系数据库起到很
好的补充作用。它提供了 Python,Ruby,Erlang,PHP 客户端,使用很方便。
Redis 的所有数据都是保存在内存中,然后不定期的通过异步方式保存到磁盘上
(这称为“半持久化模式”);也可以把每一次数据变化都写入到一个 append
only file(aof)里面(这称为“全持久化模式”)。
主机环境 rhel6.5 selinx and iptales disabled
所需软件包redis-3.0.2.tar.gz
jemalloc-3.6.0-1.el6.x86_64.rpm
jemalloc-devel-3.6.0-1.el6.x86_64.rpm
libevent-1.4.13-4.el6.x86_64.rpm
libevent-devel-1.4.13-4.el6.x86_64.rpm
libevent-headers-1.4.13-4.el6.noarch.rpm
libevent-doc-1.4.13-4.el6.noarch.rpm
Lnmp架构软件包
nginx-1.8.0-1.el6.ngx.x86_64.rpm
php-5.3.3-38.el6.x86_64.rpm
php-cli-5.3.3-38.el6.x86_64.rpm
php-common-5.3.3-38.el6.x86_64.rpm
php-devel-5.3.3-38.el6.x86_64.rpm
php-fpm-5.3.3-38.el6.x86_64.rpm
php-gd-5.3.3-38.el6.x86_64.rpm
php-mbstring-5.3.3-38.el6.x86_64.rpm
php-mysql-5.3.3-38.el6.x86_64.rpm
php-pdo-5.3.3-38.el6.x86_64.rpm
编译依赖包
re2c-0.13.5-1.el6.x86_64.rpm
Server11
yum install -y php-5.3.3-38.el6.x86_64.rpm php-common-5.3.3-38.el6.x86_64.rpm php-cli-5.3.3-38.el6.x86_64.rpm
rpm -ivh php-fpm-5.3.3-38.el6.x86_64.rpm
rpm -ivh php-mysql-5.3.3-38.el6.x86_64.rpm php-pdo-5.3.3-38.el6.x86_64.rpm
vim /etc/php-fpm.d/www.conf
将39、41行改为nginx
yum install -y nginx-1.8.0-1.el6.ngx.x86_64.rpm
vim /etc/nginx/conf.d/default.conf
启动php-fpm
/etc/init.d/php-fpm start
启动nginx
nginx -t
Nginx
vim /usr/share/nginx/html/index.php
测试
真机上 输入172.25.45.11
将数据库、redis、和php、nginx联系起来
Server13
yum install -y mysql-server
/etc/init.d/mysqld start
Mysql
Server12
tar zxf redis-3.2.5.tar.gz
cd redis-3.2.5
yum -y install gcc
Make
make install
cd utils/
./install_server.sh
vim /etc/redis/6379.conf
/etc/init.d/redis_6379 start
Server11
yum -y install unzip
unzip phpredis-master.zip
yum -y install php-devel-5.3.3-38.el6.x86_64.rpm
cd phpredis-master
Phpize
yum install gcc -y
./configure
Make
make install
cp /etc/php.d/mysql.ini /etc/php.d/redis.ini
vim /etc/php.d/redis.ini
vim /usr/share/nginx/html/index.php
改变3和10行
scp test.sql root@172.25.45.13:
vim /etc/php.ini
/etc/init.d/php-fpm reload
Server13
Mysql
grant select on test.* to redis@‘172.25.45.%‘ identified by ‘westos‘;
mysql < test.sql
vim test.sql
Mysql
测试
Server12
真机
Server12和13作同步
Server13
tar zxf redis-3.2.5.tar.gz
cd redis-3.2.5
yum -y install gcc
Make
make install
cd utils/
./install_server.sh
vim /etc/redis/6379.conf
/etc/init.d/redis_6379 restart
测试
Server12
一主多从
Server11
tar zxf redis-3.2.5.tar.gz
cd redis-3.2.5
Make
make install
cd utils/
./install_server.sh
Cp ../sentinel.conf /etc/redis
vim /etc/redis/sentinel.conf
17 protected-mode no
98 sentinel monitor mymaster 172.25.45.12 6379 2
106 sentinel down-after-milliseconds mymaster 5000
131 sentinel failover-timeout mymaster 90000
scp /etc/redis/sentinel.conf root@172.25.45.12:/etc/redis/
scp /etc/redis/sentinel.conf root@172.25.45.13:/etc/redis/
############server11、12、13的sentinel.conf文件必须相同后,才能打开redis服务,先打开server12上的服务,在开server11和server13
/etc/init.d/redis_6379 restart
redis-server /etc/redis/sentinel.conf --sentinel
server12是master,Server11和server13是slave,当shutdown掉server12时,其他两台中一台接管server12,成为master
Redis集群
关掉三台服务器的redis服务
Server12
cd /usr/local/
mkdir redis
cd redis/
mkdir 3000{1..6}
cd 30001
vim redis.conf
cp redis.conf ../30002/
cp redis.conf ../30003/
cp redis.conf ../30004/
cp redis.conf ../30005/
cp redis.conf ../30006/
分别将里面的port改为30002、30003、30004、30005、30006
cd ..
redis-server /usr/local/redis/30001/redis.conf
redis-server /usr/local/redis/30002/redis.conf
redis-server /usr/local/redis/30003/redis.conf
redis-server /usr/local/redis/30004/redis.conf
redis-server /usr/local/redis/30005/redis.conf
redis-server /usr/local/redis/30006/redis.conf
Ps ax
redis-cli -c -p 3001 shutdown
这是一个完整的块设备,不不能有缺失,如果同时删除1和4,或者2和5,或者3和6,此集群服务便被破坏
redis