redis伪集群脚本
77 #!/bin/sh 78 # 79 # chkconfig: 2345 70 20 80 # description: Redis-cluster autostart 81 . /etc/init.d/functions 82 83 case "$1" in 84 start) 85 /bin/bash /data1/redis-cluster/all-start.sh 86 ;; 87 stop) 88 /bin/bash /data1/redis-cluster/all-stop.sh 89 ;; 90 *) 91 echo "Usage: $0 (start|stop)" 92 ;; 93 esac 94 EOF 95 96 #啟動redis 97 chmod 741 $workspace/*.sh 98 $workspace/all-start.sh 99 sleep 3 100 #安裝redis-trib所需的 ruby腳本 101 cp $workspace/redis-4.0.9/src/redis-trib.rb $workspace/redis-trib.rb 102 103 wget https://rubygems.org/downloads/redis-3.2.2.gem 104 yum install -y ruby rubygems 105 gem install redis-3.2.2.gem 106 107 yum install -y expect 108 #配置集群 109 expect -c " 110 cd $workspace; 111 spawn ./redis-trib.rb create --replicas 1 $ip:7001 $ip:7002 $ip:7003 $ip:7004 $ip:7005 $ip:7006; 112 expect "configuration" { send \"yes\r\"; } 113 expect eof 114 " 115 cp $workspace/redis-01/redis-cli /usr/bin/redis-cli 116 echo -e "\nredis-cluster is ok " 117 chkconfig redis on 118
?
?
啟動腳本
單實例設置自啟動腳本
1、復制redis啟動腳本
redis啟動腳本一般在redis根目錄的utils,如果不知道路徑,可以先查看路徑
[root@slj-redis data1]#? find / -name redis_init_script
/data1/redis-cluster/redis-4.0.9/utils/redis_init_script
?
復制啟動腳本到/etc/init.d/redis文件中
cp /data1/redis-cluster/redis-4.0.9/utils/redis_init_script /etc/init.d/redis-alone
?
2、更改redis-alone腳本
?
首先添加如下倆行
# chkconfig: 2345 90 10
# description: Redis is a persistent key-value database
?
其次更改EXEC?? CLIEXEC? CONF 為實際所安裝目錄即可
REDISPORT=6379
EXEC=/data1/redis-alone/bin/redis-server
CLIEXEC=/data1/redis-alone/bin/redis-cli
?
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/data1/redis-alone/redis.conf"
?
?
chkconfig redis-alone on
?
?
centos7
[Unit] Description=Redis After=network.target remote-fs.target nss-lookup.target[Service] Type=forkingExecStart=/usr/local/redis/src/redis-server /usr/local/redis/redis.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/usr/bin/redis-cli -h 127.0.0.1 -p 6379 shutdown[Install] WantedBy=multi-user.target?
?
集群設置自啟動
?
?
先寫好集群啟動腳本
[root@slj-redis redis-cluster]# cat all-start.sh
cd /data1/redis-cluster/redis-01 ./redis-server redis.conf cd /data1/redis-cluster/redis-02./redis-server redis.confcd /data1/redis-cluster/redis-03./redis-server redis.confcd /data1/redis-cluster/redis-04./redis-server redis.confcd /data1/redis-cluster/redis-05./redis-server redis.confcd /data1/redis-cluster/redis-06./redis-server redis.conf?
?
關閉腳本
[root@slj-redis redis-cluster]# vim all-stop.sh
?
redis-cli -h 10.253.0.1 -p 7001 shutdownredis-cli -h 10.253.0.1 -p 7002 shutdownredis-cli -h 10.253.0.1 -p 7003 shutdownredis-cli -h 10.253.0.1 -p 7004 shutdownredis-cli -h 10.253.0.1 -p 7005 shutdownredis-cli -h 10.253.0.1 -p 7006 shutdown?
?
?
[root@slj-redis init.d]# vim redis-cluster
#!/bin/sh## chkconfig: 2345 70 20# description: Redis-cluster autostart. /etc/init.d/functionscase "$1" instart)/bin/bash /data1/redis-cluster/all-start.sh;;stop)/bin/bash /data1/redis-cluster/all-stop.sh;;*)echo "Usage: $0 (start|stop)";;esacchkconfig redis-cluster on?
轉載于:https://www.cnblogs.com/abkn/p/10239323.html
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的redis伪集群脚本的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 张小龙:做 PC 版微信是一种破坏,本来
- 下一篇: Java多线程02(线程安全、线程同步、