1.安装主redis
1.1.搭建安装环境
#yum install -y tcl
1.2.编译安装redis
#tar -zvxf redis-2.6.7.tar.gz
#cd redis-2.6.7
#make
#make (检查make文件)
#make install
1.3.创建redis用户
#useradd redis
1.4.修改配置文件
#cp /root/redis-2.6.7/redis.conf /home/redis/
#vim /home/redis/redis.conf
daemonize yes #后台启动
pidfile /var/run/redis.pid #后台启动的pid
port 6379 #端口
bind 192.168.1.200 #设置IP,默认为127.0.0.1
timeout 300 #等待时间
loglevel notice
logfile stdout
syslog-enabled yes #开启日志功能,默认存放在/var/log/message
#syslog-facility local5 #rsyslog 输出格式local0-7
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /home/redis/ #数据库存放位置,这里应该存放在redis用户有权限修改的 地方
slave-serve-stale-data yes
slave-read-only yes
slave-priority 100
appendonly yes #打开AOF功能
appendfsync always #即时写入AOF日志
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
1.5.使用redis用户启动redis
#su - redis
#redis-server /home/redis/redis.conf
2.安装从redis
2.1.安装redis,安装方法同上
2.2.修改配置文件
#cp /root/redis-2.6.7/redis.conf /home/redis/
#vim /home/redis/redis.conf
daemonize yes
pidfile /var/run/redis.pid
port 6379
bind 192.168.1.201
timeout 300
loglevel notice
logfile stdout
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename salve.rdb #修改数据库名字
dir /home/redis/ #数据库路径
slaveof 192.168.1.200 6379 #写入主服务器的位置和端口号
slave-serve-stale-data yes
slave-read-only yes
slave-priority 100
appendonly yes
appendfsync always
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
2.3.使用redis用户启动redis,即可实现redis主从。