赞
踩
IP | 操作系统 | 服务 | 版本 |
192.168.140.153 | CentOS 7 | remaster | 7.2.5 |
192.168.140.159 | CentOS 7 | redis-slave | 7.2.5 |
yum -y install gcc gcc-c++
wget http://download.redis.io/releases/redis-7.2.5.tar.gz
tar -zxvf redis-7.2.5.tar.gz -C /opt/
- mkdir -p /opt/redis/
- mkdir -p /opt/redis/logs/
- # 进入解压目录
- cd /opt/redis-7.2.5
-
- # 编译
- make
-
- # 安装
- make install PREFIX=/opt/redis/
- cp /opt/redis-7.2.5/redis.conf /opt/redis/
-
- vi /opt/redis/redis.conf
- # 修改如下内容
- bind 192.168.140.153 -::1
- # 允许后台运行
- daemonize yes
- # pid文件位置
- pidfile /opr/redis/redis_6379.pid
- # 日志位置
- logfile "/opt/redis/logs/redis.log"
- # 工作目录
- dir /opt/redis/
- # 主从同步密码
- masterauth final123
- # redis密码
- requirepass final123
- cp /opt/redis-7.2.5/redis.conf /opt/redis/
-
- vi /opt/redis/redis.conf
- # 修改如下内容
- bind 192.168.140.153 -::1
- # 允许后台运行
- daemonize yes
- # pid文件位置
- pidfile /opr/redis/redis_6379.pid
- # 日志位置
- logfile "/opt/redis/logs/redis.log"
- # 工作目录
- dir /opt/redis/
- # 主从同步密码
- masterauth final123
- # redis密码
- requirepass final123
-
- replilcaof 192.168.140.153 6379
- [root@localhost redis]# vi /etc/systemd/system/redis.service
- [Unit]
- Description=Redis
- After=network.target
-
- [Service]
- Type=simple
- User=root
- Group=root
- ExecStart=/opt/redis/bin/redis-server /opt/redis/redis.conf --daemonize no
- Restart=always
- LimitNPROC=65535
- LimitNOFILE=65535
-
- [Install]
- WantedBy=multi-user.target
- systemctl daemon-reload
- systemctl start redis.service
- systemctl enable redis.service
- [root@localhost redis]# vi /etc/profile
- # 在最后添加如下内容
- PATH=${PATH}:/opt/redis/bin/
-
- [root@localhost redis]# source /etc/profile
- [root@localhost redis]# redis-cli -h 192.168.140.153
- 192.168.140.153:6379> auth final123
- OK
- 192.168.140.153:6379> info replication
- # Replication
- role:master
- connected_slaves:1
- slave0:ip=192.168.140.159,port=6379,state=online,offset=350,lag=1
- master_failover_state:no-failover
- master_replid:28a3b660f11504c07b2cc4bc07a093970af1544b
- master_replid2:0000000000000000000000000000000000000000
- master_repl_offset:350
- second_repl_offset:-1
- repl_backlog_active:1
- repl_backlog_size:1048576
- repl_backlog_first_byte_offset:1
- repl_backlog_histlen:350
- [root@localhost redis]# redis-cli -h 192.168.140.159
- 192.168.140.159:6379> auth final123
- OK
- 192.168.140.159:6379> info replication
- # Replication
- role:slave
- master_host:192.168.140.153
- master_port:6379
- master_link_status:up
- master_last_io_seconds_ago:6
- master_sync_in_progress:0
- slave_read_repl_offset:406
- slave_repl_offset:406
- slave_priority:100
- slave_read_only:1
- replica_announced:1
- connected_slaves:0
- master_failover_state:no-failover
- master_replid:28a3b660f11504c07b2cc4bc07a093970af1544b
- master_replid2:0000000000000000000000000000000000000000
- master_repl_offset:406
- second_repl_offset:-1
- repl_backlog_active:1
- repl_backlog_size:1048576
- repl_backlog_first_byte_offset:1
- repl_backlog_histlen:406
- 192.168.140.153:6379> set test "master"
- OK
- 192.168.140.153:6379> get test
- "master"
- 192.168.140.159:6379> get test
- "master"
- # slave节点只能读取,不能写入。
- 192.168.140.159:6379> set test1 "ceshi"
- (error) READONLY You can't write against a read only replica.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。