- 环境准备
每台都需要安装
CentOS7.6 master 172.20.0.100 4.0.14
CentOS7.6 slave 172.20.0.101 4.0.14
[root@master redis-4.0.14]
mkdir: created directory ‘/apps/redis/etc’
mkdir: created directory ‘/apps/redis/logs’
mkdir: created directory ‘/apps/redis/data’
[root@master ~]useradd -r redis -s /sbin/nologin
[root@master ~]chown -R redis.redis /apps/redis
[root@master ~]
[root@master ~]
[root@master redis-4.0.14]
cp redis.conf /apps/redis/etc/
- 服务脚本
[root@master ~]
[Unit]
Description=Redis persistent key-value database
After=network.target
After=network-online.target
Wants=network-online.target
[Service]
ExecStart=/apps/redis/bin/redis-server /apps/redis/etc/redis.conf --supervised systemd
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
Type=notify
User=redis
Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=0755
[Install]
WantedBy=multi-user.target
- 启动服务
systemctl daemon-reload
systemctl start redis
- 参数
vim /etc/sysctl.conf
net.core.somaxconn = 512
vm.overcommit_memory = 1
echo never > /sys/kernel/mm/transparent_hugepage/enabled
- 搭建主从
[root@master ~]
127.0.0.1:6379> get name
"linux"
[root@slave ~]
127.0.0.1:6379> slaveof 172.20.0.100 6379
OK
127.0.0.1:6379> info Replication
role:slave
master_host:172.20.0.100
master_port:6379
master_link_status:up
master_last_io_seconds_ago:1
master_sync_in_progress:0
slave_repl_offset:14
slave_priority:100
slave_read_only:1
connected_slaves:0
master_replid:edef40b178a70998e7953c53832a29f18ee35e59
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:14
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:14
127.0.0.1:6379> get name
"linux"
- 重启节点依然生效
[root@slave ~]
slaveof 172.20.0.100 6379
- 断开主从操作如下
127.0.0.1:6379> slaveof no one
OK