1、搭建一个 redis 哨兵集群
一主二从三哨兵模式
master(10.0.0.105),slave1(10.0.0.106),slave2(10.0.0.107)
都执行以下脚本安装redis服务。
bash install_redis.sh #!/bin/bash . /etc/init.d/functions SRC_DIR=/usr/local/src REDIS='redis-5.0.9.tar.gz' VERSION=`echo $REDIS | sed -nr 's/^(.*).tar.*/1/p'` INSTALL_DIR=/apps/redis PASSWORD=123456 COLOR='echo -e E[01;31m' END='E[0m' ##检查 check(){ ##检查用户是否root if [ $UID -ne 0 ] ;then action "当前用户不是root,安装失败" false exit 1 fi cd $SRC_DIR ##检查nginx安装包是否存在 if [ ! -e $REDIS ] ;then $COLOR"缺少${REDIS}文件"$END $COLOR"请将相关文件放在${SRC_DIR}目录下"$END exit ##检查mysql是否已安装 elif [ -e ${INSTALL_DIR} ] ;then action "REDIS已存在,安装失败 " false exit else action "环境检测正常" return fi } ##安装redis install_redis(){ ##安装依赖包 yum install gcc jemalloc-devel -y > /dev/null [ $? -eq 0 ] && { action "依赖包安装" ;} || { action "依赖包安装" false ;exit ; } ##创建redis用户 id redis && action "创建Redis用户" || { useradd -r -s /sbin/nologin redis ; action "创建redis用户"; } ##创建apps文件夹 [ -d /apps ] || { mkdir /apps ; action "创建apps文件夹"; } cd $SRC_DIR tar xf $REDIS cd $VERSION make PREFIX=${INSTALL_DIR} install > /dev/null [ $? -eq 0 ] && action "make install " || { action "make install " false ; exit ;} mkdir ${INSTALL_DIR}/{etc,data,run,log} cp redis.conf ${INSTALL_DIR}/etc/ sed -ri 's/bind 127.0.0.1$/bind 0.0.0.0/' ${INSTALL_DIR}/etc/redis.conf sed -ri "/# requirepass .*/a requirepass ${PASSWORD}" ${INSTALL_DIR}/etc/redis.conf sed -ri "/^dir .*/c dir ${INSTALL_DIR}/data/" ${INSTALL_DIR}/etc/redis.conf sed -ri "/logfile .*/c logfile ${INSTALL_DIR}/log/redis_6379.log" ${INSTALL_DIR}/etc/redis.conf sed -ri "/daemonize .*/c daemonize yes" ${INSTALL_DIR}/etc/redis.conf sed -ri "/pidfile .*/c pidfile ${INSTALL_DIR}/run/redis_6379.pid" ${INSTALL_DIR}/etc/redis.conf echo "PATH=${INSTALL_DIR}/bin:$PATH" > /etc/profile.d/redis.sh . /etc/profile.d/redis.sh cat > /usr/lib/systemd/system/redis.service <<-EOF [Unit] Description=Redis persistent key-value database After=network.target [Service] ExecStart=${INSTALL_DIR}/bin/redis-server ${INSTALL_DIR}/etc/redis.conf --supervised systemd ExecStop=/bin/kill -s QUIT $MAINPID Type=notify User=redis Group=redis RuntimeDirectory=redis RuntimeDirectoryMode=0755 [Install] WantedBy=multi-user.target EOF cat >> /etc/sysctl.conf<<-EOF net.core.somaxconn = 1024 vm.overcommit_memory = 1 EOF sysctl -p echo 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' >> /etc/rc.d/rc.local chmod +x /etc/rc.d/rc.local /etc/rc.d/rc.local chown -R redis.redis ${INSTALL_DIR} systemctl daemon-reload systemctl enable redis.service systemctl start redis.service [ $? -eq 0 ] && action "Redis 启动" || { action "Redis 启动" false ;exit ;} [ $? -eq 0 ] && $COLOR"Redis安装成功"$END } check install_redis
安装完redis服务后修改配置文件,配置一主二从。 master(10.0.0.105)修改以下配置,重启服务 vim /apps/redis/etc/redis.conf masterauth 123456 systemctl restart redis.service slave1(10.0.0.106),slave2(10.0.0.107)修改以下配置,重启服务 vim /apps/redis/etc/redis.conf replicaof 10.0.0.105 6379 masterauth 123456 systemctl restart redis.service
主从配置成功 [root@centos7 ~]#redis-cli -a 123456 -h 10.0.0.105 info replication Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. # Replication role:master connected_slaves:2 slave0:ip=10.0.0.106,port=6379,state=online,offset=3356,lag=0 slave1:ip=10.0.0.107,port=6379,state=online,offset=3221,lag=1 master_replid:121e97e5aa570877d224e9a538c04e4c9a3302c7 master_replid2:0000000000000000000000000000000000000000 master_repl_offset:3356 second_repl_offset:-1 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:1 repl_backlog_histlen:3356 [root@centos7 ~]#redis-cli -a 123456 -h 10.0.0.106 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:10.0.0.105 master_port:6379 master_link_status:up master_last_io_seconds_ago:2 master_sync_in_progress:0 slave_repl_offset:30511 slave_priority:100 slave_read_only:1 connected_slaves:0 master_replid:121e97e5aa570877d224e9a538c04e4c9a3302c7 master_replid2:0000000000000000000000000000000000000000 master_repl_offset:30511 second_repl_offset:-1 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:1 repl_backlog_histlen:30511 [root@centos7 ~]#redis-cli -a 123456 -h 10.0.0.107 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:10.0.0.105 master_port:6379 master_link_status:up master_last_io_seconds_ago:1 master_sync_in_progress:0 slave_repl_offset:30781 slave_priority:100 slave_read_only:1 connected_slaves:0 master_replid:121e97e5aa570877d224e9a538c04e4c9a3302c7 master_replid2:0000000000000000000000000000000000000000 master_repl_offset:30781 second_repl_offset:-1 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:3064 repl_backlog_histlen:27718
部署哨兵集群
master(10.0.0.105),slave1(10.0.0.106),slave2(10.0.0.107) 都执行以下脚本命令 #!/bin/bash ##AUTO huangguangrui MASTER="10.0.0.105" PASSWD="123456" PORT="6379" install_sentinel(){ cp /usr/local/src/redis-*/sentinel.conf /apps/redis/etc/ sed -ri "/^pidfile.*/c pidfile /apps/redis/run/redis-sentinel.pid" /apps/redis/etc/sentinel.conf sed -ri "/^logfile.*/c logfile "/apps/redis/log/sentinel.log"" /apps/redis/etc/sentinel.conf sed -ri '/^dir.*/c dir "/apps/redis/data"' /apps/redis/etc/sentinel.conf sed -ri "/^sentinel monitor mymaster.*/c sentinel monitor mymaster $MASTER $PORT 2" /apps/redis/etc/sentinel.conf sed -ri "/^# sentinel auth-pass mymaster.*/c sentinel auth-pass mymaster $PASSWD" /apps/redis/etc/sentinel.conf sed -ri '/^sentinel down-after-milliseconds.*/c sentinel down-after-milliseconds mymaster 3000' /apps/redis/etc/sentinel.conf cat > /usr/lib/systemd/system/redis-sentinel.service <<-EOF [Unit] Description=Redis Sentinel After=network.target After=network-online.target Wants=network-online.target [Service] ExecStart=/apps/redis/bin/redis-sentinel /apps/redis/etc/sentinel.conf --supervised systemd #ExecStop=/usr/libexec/redis-shutdown redis-sentinel ExecStop=/bin/kill -s QUIT $MAINPID Type=notify User=redis Group=redis RuntimeDirectory=redis RuntimeDirectoryMode=0755 [Install] WantedBy=multi-user.target EOF chown -R redis.redis /apps/redis/ systemctl enable --now redis-sentinel.service } install_sentinel
查看日志
[root@centos7 ~]#tail -f /apps/redis/log/sentinel.log 5931:X 26 Oct 2020 18:46:14.377 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 5931:X 26 Oct 2020 18:46:14.377 # Redis version=5.0.9, bits=64, commit=00000000, modified=0, pid=5931, just started 5931:X 26 Oct 2020 18:46:14.377 # Configuration loaded 5931:X 26 Oct 2020 18:46:14.377 * supervised by systemd, will signal readiness 5931:X 26 Oct 2020 18:46:14.378 # You requested maxclients of 10000 requiring at least 10032 max file descriptors. 5931:X 26 Oct 2020 18:46:14.378 # Server can't set maximum open files to 10032 because of OS error: Operation not permitted. 5931:X 26 Oct 2020 18:46:14.378 # Current maximum open files is 4096. maxclients has been reduced to 4064 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'. 5931:X 26 Oct 2020 18:46:14.378 * Running mode=sentinel, port=26379. 5931:X 26 Oct 2020 18:46:14.379 # Sentinel ID is 8a34136c61f51740d8a201923a5e78648e2bbe1e 5931:X 26 Oct 2020 18:46:14.382 # +monitor master mymaster 10.0.0.105 6379 quorum 2 5931:X 26 Oct 2020 18:54:46.517 * +reboot master mymaster 10.0.0.105 6379 5931:X 26 Oct 2020 18:54:56.578 * +slave slave 10.0.0.106:6379 10.0.0.106 6379 @ mymaster 10.0.0.105 6379 5931:X 26 Oct 2020 18:55:36.747 * +slave slave 10.0.0.107:6379 10.0.0.107 6379 @ mymaster 10.0.0.105 6379
5931:X 26 Oct 2020 19:21:19.737 * +sentinel sentinel dd06d2d40766647aeaada6535c5e07ebd2dfea94 10.0.0.106 26379 @ mymaster 10.0.0.105 6379
5931:X 26 Oct 2020 19:21:44.872 * +sentinel sentinel b6163adab7a58d19aa5f2f14f36cb73db2eb46f8 10.0.0.107 26379 @ mymaster 10.0.0.105 6379
redis哨兵模式sentinel部署成功。
模拟故障:master(10.0.0.105)down机了。 master: [root@centos7 ~]#systemctl stop redis 几秒后启动 [root@centos7 ~]#systemctl start redis 查看日志:已自动转换slave2(10.0.0.107)为master,原master(10.0.0.105)自动转换为slave 6552:X 26 Oct 2020 19:23:19.472 # +sdown master mymaster 10.0.0.105 6379 6552:X 26 Oct 2020 19:23:19.550 # +odown master mymaster 10.0.0.105 6379 #quorum 2/2 6552:X 26 Oct 2020 19:23:19.551 # +new-epoch 1 6552:X 26 Oct 2020 19:23:19.551 # +try-failover master mymaster 10.0.0.105 6379 6552:X 26 Oct 2020 19:23:19.554 # +vote-for-leader dd06d2d40766647aeaada6535c5e07ebd2dfea94 1 6552:X 26 Oct 2020 19:23:19.578 # 8a34136c61f51740d8a201923a5e78648e2bbe1e voted for dd06d2d40766647aeaada6535c5e07ebd2dfea94 1 6552:X 26 Oct 2020 19:23:19.599 # b6163adab7a58d19aa5f2f14f36cb73db2eb46f8 voted for dd06d2d40766647aeaada6535c5e07ebd2dfea94 1 6552:X 26 Oct 2020 19:23:19.617 # +elected-leader master mymaster 10.0.0.105 6379 6552:X 26 Oct 2020 19:23:19.617 # +failover-state-select-slave master mymaster 10.0.0.105 6379 6552:X 26 Oct 2020 19:23:19.673 # +selected-slave slave 10.0.0.107:6379 10.0.0.107 6379 @ mymaster 10.0.0.105 6379 6552:X 26 Oct 2020 19:23:19.673 * +failover-state-send-slaveof-noone slave 10.0.0.107:6379 10.0.0.107 6379 @ mymaster 10.0.0.105 6379 6552:X 26 Oct 2020 19:23:19.729 * +failover-state-wait-promotion slave 10.0.0.107:6379 10.0.0.107 6379 @ mymaster 10.0.0.105 6379 6552:X 26 Oct 2020 19:23:20.586 # +promoted-slave slave 10.0.0.107:6379 10.0.0.107 6379 @ mymaster 10.0.0.105 6379 6552:X 26 Oct 2020 19:23:20.586 # +failover-state-reconf-slaves master mymaster 10.0.0.105 6379 6552:X 26 Oct 2020 19:23:20.635 * +slave-reconf-sent slave 10.0.0.106:6379 10.0.0.106 6379 @ mymaster 10.0.0.105 6379 6552:X 26 Oct 2020 19:23:21.636 * +slave-reconf-inprog slave 10.0.0.106:6379 10.0.0.106 6379 @ mymaster 10.0.0.105 6379 6552:X 26 Oct 2020 19:23:21.818 # -odown master mymaster 10.0.0.105 6379 6552:X 26 Oct 2020 19:23:22.659 * +slave-reconf-done slave 10.0.0.106:6379 10.0.0.106 6379 @ mymaster 10.0.0.105 6379 6552:X 26 Oct 2020 19:23:22.759 # +failover-end master mymaster 10.0.0.105 6379 6552:X 26 Oct 2020 19:23:22.760 # +switch-master mymaster 10.0.0.105 6379 10.0.0.107 6379 6552:X 26 Oct 2020 19:23:22.762 * +slave slave 10.0.0.106:6379 10.0.0.106 6379 @ mymaster 10.0.0.107 6379 6552:X 26 Oct 2020 19:23:22.763 * +slave slave 10.0.0.105:6379 10.0.0.105 6379 @ mymaster 10.0.0.107 6379 6552:X 26 Oct 2020 19:23:25.859 # +sdown slave 10.0.0.105:6379 10.0.0.105 6379 @ mymaster 10.0.0.107 6379 6552:X 26 Oct 2020 19:24:13.665 # -sdown slave 10.0.0.105:6379 10.0.0.105 6379 @ mymaster 10.0.0.107 6379 5906:X 26 Oct 2020 19:24:23.585 * +convert-to-slave slave 10.0.0.105:6379 10.0.0.105 6379 @ mymaster 10.0.0.107 6379
[root@centos7 ~]#redis-cli -a 123456 -h 10.0.0.107 info replication Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. # Replication role:master connected_slaves:2 slave0:ip=10.0.0.106,port=6379,state=online,offset=186051,lag=1 slave1:ip=10.0.0.105,port=6379,state=online,offset=186051,lag=1 master_replid:7cfd0019a61ee0c158a97ed0356d7abffcc1beef master_replid2:f083f61c7917ecf3d22b5fe24c6b01d9e1d049c5 master_repl_offset:186321 second_repl_offset:21643 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:1 repl_backlog_histlen:186321
2、实现 redis cluster 得部署
老规矩先部署redis服务(所有服务器都操作)
bash install_redis.sh
修改redis.conf文件启动cluster(所有服务器都操作) sed -i.bak -e '/^# masterauth.*/c masterauth 123456' -e '/# cluster-enabled yes/c cluster-enabled yes' -e '/# cluster-enable yes/a cluster-enable yes' -e '/# cluster-config-file nodes-6379.conf/a cluster-config-file nodes-6379.conf' -e '/cluster-require-full-coverage yes/c cluster-require-full-coverage no' /apps/redis/etc/redis.conf [root@centos7 ~]#systemctl restart redis [root@centos7 ~]#ss -ntl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 511 *:16379 *:* LISTEN 0 511 *:6379 *:* LISTEN 0 128 *:22 *:* LISTEN 0 100 [::1]:25 [::]:* LISTEN 0 128 [::]:22 [::]:*
创建cluster集群 [root@centos7 ~]#redis-cli -a 123456 --cluster create 10.0.0.7:6379 10.0.0.17:6379 10.0.0.27:6379 10.0.0.37:6379 10.0.0.47:6379 10.0.0.57:6379 --cluster-replicas 1 Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. >>> Performing hash slots allocation on 6 nodes... Master[0] -> Slots 0 - 5460 Master[1] -> Slots 5461 - 10922 Master[2] -> Slots 10923 - 16383 Adding replica 10.0.0.47:6379 to 10.0.0.7:6379 Adding replica 10.0.0.57:6379 to 10.0.0.17:6379 Adding replica 10.0.0.37:6379 to 10.0.0.27:6379 M: f1c86c487d1f77613b0d8b4bf179e5108ab17358 10.0.0.7:6379 slots:[0-5460] (5461 slots) master M: 786672e63751194924bb1abde8e71c2f947e5ddb 10.0.0.17:6379 slots:[5461-10922] (5462 slots) master M: 7c46b4182b3a14ccc5c7e29a08707e49a56b48b8 10.0.0.27:6379 slots:[10923-16383] (5461 slots) master S: 16855d434fe1b75f9f54add196e45a620fda6177 10.0.0.37:6379 replicates 7c46b4182b3a14ccc5c7e29a08707e49a56b48b8 S: e34561286f1e99b1aefdd8b94d8dd34fb074a868 10.0.0.47:6379 replicates f1c86c487d1f77613b0d8b4bf179e5108ab17358 S: 30a1c6ea3cf780bc1685256d82aeade5e725eae3 10.0.0.57:6379 replicates 786672e63751194924bb1abde8e71c2f947e5ddb Can I set the above configuration? (type 'yes' to accept): yes ##输入yes自动创建 >>> Nodes configuration updated >>> Assign a different config epoch to each node >>> Sending CLUSTER MEET messages to join the cluster Waiting for the cluster to join ...... >>> Performing Cluster Check (using node 10.0.0.7:6379) M: f1c86c487d1f77613b0d8b4bf179e5108ab17358 10.0.0.7:6379 slots:[0-5460] (5461 slots) master 1 additional replica(s) M: 7c46b4182b3a14ccc5c7e29a08707e49a56b48b8 10.0.0.27:6379 slots:[10923-16383] (5461 slots) master 1 additional replica(s) S: e34561286f1e99b1aefdd8b94d8dd34fb074a868 10.0.0.47:6379 slots: (0 slots) slave replicates f1c86c487d1f77613b0d8b4bf179e5108ab17358 S: 16855d434fe1b75f9f54add196e45a620fda6177 10.0.0.37:6379 slots: (0 slots) slave replicates 7c46b4182b3a14ccc5c7e29a08707e49a56b48b8 M: 786672e63751194924bb1abde8e71c2f947e5ddb 10.0.0.17:6379 slots:[5461-10922] (5462 slots) master 1 additional replica(s) S: 30a1c6ea3cf780bc1685256d82aeade5e725eae3 10.0.0.57:6379 slots: (0 slots) slave replicates 786672e63751194924bb1abde8e71c2f947e5ddb [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered. 查看主从信息 [root@centos7 ~]#redis-cli -a 123456 -h 10.0.0.7 -c info replication Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. # Replication role:master connected_slaves:1 slave0:ip=10.0.0.47,port=6379,state=online,offset=112,lag=0 master_replid:bd1e9603956dfeaeeeaae0c2f956dcf2959c5070 master_replid2:0000000000000000000000000000000000000000 master_repl_offset:112 second_repl_offset:-1 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:1 repl_backlog_histlen:112 [root@centos7 ~]#redis-cli -a 123456 -h 10.0.0.17 -c info replication Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. # Replication role:master connected_slaves:1 slave0:ip=10.0.0.57,port=6379,state=online,offset=126,lag=0 master_replid:26d9d8c942dea536271a7db0d35ce3d54c26e0f3 master_replid2:0000000000000000000000000000000000000000 master_repl_offset:126 second_repl_offset:-1 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:1 repl_backlog_histlen:126 [root@centos7 ~]#redis-cli -a 123456 -h 10.0.0.27 -c info replication Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. # Replication role:master connected_slaves:1 slave0:ip=10.0.0.37,port=6379,state=online,offset=126,lag=1 master_replid:99b64c8da3c279b4392147e909459a7efc6f3001 master_replid2:0000000000000000000000000000000000000000 master_repl_offset:126 second_repl_offset:-1 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:1 repl_backlog_histlen:126 验证cluster集群信息 [root@centos7 ~]#redis-cli -a 123456 cluster info Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. cluster_state:ok cluster_slots_assigned:16384 cluster_slots_ok:16384 cluster_slots_pfail:0 cluster_slots_fail:0 cluster_known_nodes:6 cluster_size:3 cluster_current_epoch:6 cluster_my_epoch:1 cluster_stats_messages_ping_sent:162 cluster_stats_messages_pong_sent:169 cluster_stats_messages_sent:331 cluster_stats_messages_ping_received:164 cluster_stats_messages_pong_received:162 cluster_stats_messages_meet_received:5 cluster_stats_messages_received:331
cluster部署完成。
模拟故障:
[root@centos7 ~]#redis-cli -a 123456 Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. 127.0.0.1:6379> SHUTDOWN not connected> exit [root@centos7 ~]#ss -ntl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 *:22 *:* LISTEN 0 100 [::1]:25 [::]:* LISTEN 0 128 [::]:80 [::]:* LISTEN 0 128 [::]:22 [::]:* [root@centos7 ~]#redis-cli -a 123456 --cluster info 10.0.0.17:6379 Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. Could not connect to Redis at 10.0.0.7:6379: Connection refused 10.0.0.17:6379 (786672e6...) -> 0 keys | 5462 slots | 1 slaves. 10.0.0.27:6379 (7c46b418...) -> 0 keys | 5461 slots | 1 slaves. 10.0.0.47:6379 (e3456128...) -> 0 keys | 5461 slots | 0 slaves. ##自动提47为master [OK] 0 keys in 3 masters. 0.00 keys per slot on average.
修复原master(7)后自动降为slave [root@centos7 ~]#systemctl restart redis [root@centos7 ~]#redis-cli -a 123456 --cluster info 10.0.0.7:6379 Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. 10.0.0.47:6379 (e3456128...) -> 0 keys | 5461 slots | 1 slaves. 10.0.0.17:6379 (786672e6...) -> 0 keys | 5462 slots | 1 slaves. 10.0.0.27:6379 (7c46b418...) -> 0 keys | 5461 slots | 1 slaves. [OK] 0 keys in 3 masters. 0.00 keys per slot on average. [root@centos7 ~]#redis-cli -a 123456 cluster nodes Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. f1c86c487d1f77613b0d8b4bf179e5108ab17358 10.0.0.7:6379@16379 slave e34561286f1e99b1aefdd8b94d8dd34fb074a868 0 1603717186966 7 connected 7c46b4182b3a14ccc5c7e29a08707e49a56b48b8 10.0.0.27:6379@16379 master - 0 1603717186000 3 connected 10923-16383 e34561286f1e99b1aefdd8b94d8dd34fb074a868 10.0.0.47:6379@16379 master - 0 1603717187970 7 connected 0-5460 16855d434fe1b75f9f54add196e45a620fda6177 10.0.0.37:6379@16379 slave 7c46b4182b3a14ccc5c7e29a08707e49a56b48b8 0 1603717187000 4 connected 30a1c6ea3cf780bc1685256d82aeade5e725eae3 10.0.0.57:6379@16379 slave 786672e63751194924bb1abde8e71c2f947e5ddb 0 1603717184000 6 connected 786672e63751194924bb1abde8e71c2f947e5ddb 10.0.0.17:6379@16379 myself,master - 0 1603717184000 2 connected 5461-10922
3、部署一个 tomcat 服务
#!/bin/bash #AUTO huangguangrui . /etc/init.d/functions SRC=/usr/local/src JDK="jdk-8u271-linux-x64.tar.gz" TOMCAT="apache-tomcat-8.5.59.tar.gz" JDK_DIR="/usr/local" TOMCAT_DIR="/usr/local" install_jdk(){ cd $SRC tar xf ${JDK} -C ${JDK_DIR} cd ${JDK_DIR} ln -s jdk1.8.* jdk cat > /etc/profile.d/jdk.sh <<-EOF export JAVA_HOME=${JDK_DIR}/jdk export PATH=$PATH:$JAVA_HOME/bin export JRE_HOME=$JAVA_HOME/jre export CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib/ EOF . /etc/profile.d/jdk.sh java -version && action "JDK 安装成功" || { action "JDK 安装失败" false ;exit ; } } install_tomcat(){ id tomcat &> /dev/null || useradd -r -s /sbin/nologin tomcat cd $SRC tar xf ${TOMCAT} -C ${TOMCAT_DIR} cd ${TOMCAT_DIR} ln -s apache-tomcat-* tomcat echo 'PATH=/usr/local/tomcat/bin:$PATH' > /etc/profile.d/tomcat.sh . /etc/profile.d/tomcat.sh cat > ${TOMCAT_DIR}/tomcat/conf/tomcat.conf <<-EOF JAVA_HOME=${JDK_DIR}/jdk EOF chown -R tomcat.tomcat ${TOMCAT_DIR}/tomcat/ cat > /lib/systemd/system/tomcat.service <<-EOF [Unit] Description=Apache Tomcat Web Application Container After=syslog.target network.target [Service] Type=forking EnvironmentFile=${TOMCAT_DIR}/tomcat/conf/tomcat.conf ExecStart=${TOMCAT_DIR}/tomcat/bin/startup.sh ExecStop=${TOMCAT_DIR}/tomcat/bin/shutdown.sh PrivateTmp=true User=tomcat Group=tomcat [Install] WantedBy=multi-user.target EOF systemctl daemon-reload systemctl enable --now tomcat.service systemctl is-active tomcat.service &> /dev/null && action "TOMCAT 安装完成" || { action "TOMCAT 安装失败" false ;exit ;} } install_jdk install_tomcat
cd /usr/local/src mv jpress-v3.3.0.war /usr/local/tomcat/webapps systemctl restart tomcat [root@centos7 /usr/local/tomcat/webapps]#ls docs examples host-manager jpress jpress-v3.3.0 jpress-v3.3.0.war manager ROOT