Redis集群做法的难点,百万并发客户端「实战」( 二 )

# chmod +x /usr/libexec/redis-shutdown# useradd -s /sbin/nologin redis# chown -R redis:redis /usr/local/redis# chown -R reids:redis /data/redis# yum install -y bash-completion--tt-darkmode-color: #999999;">192.168.30.128
# mkdir -p /data/redis # vim /usr/local/redis/redis.conf bind 192.168.30.128 #监听ip , 多个ip用空格分隔 daemonize yes #允许后台启动 logfile "/usr/local/redis/redis.log"#日志路径 dir /data/redis #数据库备份文件存放目录 masterauth 123456 #slave连接master密码 , master可省略 requirepass 123456 #设置master连接密码 , slave可省略 appendonly yes #在/data/redis/目录生成appendonly.aof文件 , 将每一次写操作请求都追加到appendonly.aof 文件中# echo 'vm.overcommit_memory=1' >> /etc/sysctl.conf # sysctl -p192.168.30.129
# mkdir -p /data/redis # vim /usr/local/redis/redis.conf bind 192.168.30.129 daemonize yes logfile "/usr/local/redis/redis.log" dir /data/redis replicaof 192.168.30.128 6379 masterauth 123456 requirepass 123456 appendonly yes # echo 'vm.overcommit_memory=1' >> /etc/sysctl.conf# sysctl -p192.168.30.130
# mkdir -p /data/redis# vim /usr/local/redis/redis.conf bind 192.168.30.130 daemonize yes logfile "/usr/local/redis/redis.log" dir /data/redis replicaof 192.168.30.128 6379 masterauth 123456 requirepass 123456 appendonly yes # echo 'vm.overcommit_memory=1' >> /etc/sysctl.conf # sysctl -p

  • 全部启动redis:
# systemctl start redis
  • 查看集群状态:
# redis-cli -h 192.168.30.128 -a 123456 Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. 192.168.30.128:6379> info replication # Replication role:master connected_slaves:2 slave0:ip=192.168.30.129,port=6379,state=online,offset=168,lag=1 slave1:ip=192.168.30.130,port=6379,state=online,offset=168,lag=1 master_replid:fb4941e02d5032ad74c6e2383211fc58963dbe90 master_replid2:0000000000000000000000000000000000000000 master_repl_offset:168 second_repl_offset:-1 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:1 repl_backlog_histlen:168# redis-cli -h 192.168.30.129 -a 123456 info replication Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. # Replication role:slave master_host:192.168.30.128 master_port:6379 master_link_status:up master_last_io_seconds_ago:1 master_sync_in_progress:0 slave_repl_offset:196 slave_priority:100 slave_read_only:1 connected_slaves:0 master_replid:fb4941e02d5032ad74c6e2383211fc58963dbe90 master_replid2:0000000000000000000000000000000000000000 master_repl_offset:196 second_repl_offset:-1 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:1 repl_backlog_histlen:196数据演示
192.168.30.128:6379> keys *(empty list or set)192.168.30.128:6379> set key1 100OK192.168.30.128:6379> set key2 lzxOK192.168.30.128:6379> keys *1) "key1"2) "key2"123456789101112【Redis集群做法的难点,百万并发客户端「实战」】