码迷,mamicode.com
首页 > 其他好文 > 详细

Redis主从复制部署

时间:2021-01-04 10:45:03      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:通信   cte   name   exe   evel   hash   put   bin   red   

安装redis

源码编译安装redis 4.0

1.首先下载软件包;到服务器中

[root@deeam ~]# tar xf redis-4.0.9.tar.gz

[root@deeam ~]# cd redis-4.0.9
[root@deeam redis-4.0.9]# make

[root@deeam redis-4.0.9]# echo $?
0

2.编译完后的配置

[root@deeam local]# mkdir  /usr/local/redis ##创建服务目录

[root@deeam local]# cp /root/redis-4.0.9/src/redis-server /usr/local/redis/ ##复制服务端程序

[root@deeam local]# cp /root/redis-4.0.9/src/redis-cli /usr/local/redis/ ##复制客户端程序

[root@deeam local]# cp /root/redis-4.0.9/redis.conf /usr/local/redis/   ##复制服务主配置文件

[root@deeam local]# ls /usr/local/redis/
redis-cli  redis.conf  redis-server

--redis-cli :客户端程序
--redis-server :服务端程序
--redis.conf :主配置文件

3.进行配置主配置文件

[root@deeam local]# vim /usr/local/redis/redis.conf  ##进入到配置文件里;修改如下几行

  69 bind 192.168.100.101 ##修改监听地址为本地服务器的IP
  
  88 protected-mode yes ##关闭redis的保护模式
  
  136 daemonize yes ##开启redis的后台守护进程模式
  
  109 unixsocket /tmp/redis.sock  ##打开sock文件;基于sock服务端与客户通信直接在内存中交换;数据包就不经由TCP协议层封装了

  
  500 requirepass 123123 ##设置redis的密码为123123(生产环境中要强制密码)

4.添加环境变量

[root@deeam local]# vim /etc/profile.d/redis.sh
export PATH=/usr/local/redis:$PATH

[root@deeam local]# . /etc/profile.d/redis.sh

5.编写启动脚本

[root@deeam local]# vim /usr/lib/systemd/system/redis.service

[Unit]
Description=Redis
After=network.target

[Service]
ExecStart=/usr/local/redis/redis-server /usr/local/redis/redis.conf  --daemonize no
ExecStop=/usr/local/redis/redis-cli -h 192.168.100.101 -p 6379 shutdown

[Install]
WantedBy=multi-user.target

[root@deeam local]# systemctl daemon-reload
[root@deeam local]# systemctl start redis

6.最后连接验证;保证6379端口监听

[root@deeam local]# redis-cli -h 192.168.100.101 -p 6379 -a 123123
192.168.100.101:6379>

-h :指定本地监听的IP地址
-p : 指定端口
-a : 指定密码

配置主从复制

复制master redis(修改配置文件)

daemonize yes
bind 0.0.0.0
protected-mode no
pidfile "/usr/local/redis/redis.pid"
port 6379
tcp-backlog 1024
timeout 0
tcp-keepalive 300
loglevel notice
logfile "/usr/local/redis/log/redis.log"
requirepass "HKrCL$e$acZ9"
masterauth "HKrCL$e$acZ9"
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 "/usr/local/redis/data"
slave-serve-stale-data yes
slave-read-only yes
repl-disable-tcp-nodelay no
slave-priority 100
appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec
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
notify-keyspace-events ""
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
hz 10
aof-rewrite-incremental-fsync yes
min-slaves-to-write 1
min-slaves-max-lag 10

复制slave redis(修改配置文件)

daemonize yes
bind 0.0.0.0
protected-mode no
pidfile "/usr/local/redis/redis.pid"
port 6379
tcp-backlog 1024
timeout 0
tcp-keepalive 300
loglevel notice
logfile "/usr/local/redis/log/redis.log"
requirepass "HKrCL$e$acZ9"
masterauth "HKrCL$e$acZ9"
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 "/usr/local/redis/data"
slave-serve-stale-data yes
slave-read-only yes
slaveof 192.168.29.128 6379                 #指定master地址
repl-disable-tcp-nodelay no
slave-priority 100
appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec
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
notify-keyspace-events ""
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
hz 10
aof-rewrite-incremental-fsync yes
min-slaves-to-write 1
min-slaves-max-lag 10

master 创建键值验证

[root@node1 redis]# ./redis-cli 
127.0.0.1:6379> AUTH HKrCL$e$acZ9
OK
127.0.0.1:6379> KEYS *
(empty list or set)
127.0.0.1:6379> SET name test
OK
127.0.0.1:6379> KEYS 8
(empty list or set)
127.0.0.1:6379> KEYS *
1) "name"
127.0.0.1:6379> GET name
"test"

验证

[root@node3 redis]# ./redis-cli 
127.0.0.1:6379> 
127.0.0.1:6379> AUTH HKrCL$e$acZ9
OK
127.0.0.1:6379> 
127.0.0.1:6379> GET name
"test"

Redis主从复制部署

标签:通信   cte   name   exe   evel   hash   put   bin   red   

原文地址:https://www.cnblogs.com/precipitation/p/14211432.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!