安裝教程:https://my.oschina.net/u/2331760/blog/2239815html
mkdir /usr/local/redis-msredis
cd /usr/local/redis-ms/vim
mkdir 6381app
mkdir 6382測試
mkdir 6382spa
2)複製redis.conf到主從目錄.net
cp /usr/local/redis/redis.conf ./6381/rest
cp /usr/local/redis/redis.conf ./6382/日誌
cp /usr/local/redis/redis.conf ./6383/server
3)修改主./6381/redis.conf
vim ./6381/redis.conf
#修改以下key的值
bind 0.0.0.0#任意ip均可以鏈接
protected-mode no#關閉保護,容許非本地鏈接
port 6381#端口號
daemonize yes#後臺運行
pidfile /var/run/redis_6381.pid#進程守護文件,就是存放該進程號相關信息的地方
dir /usr/local/redis-ms/6381/#db等相關目錄位置
appendonly yes#開啓日誌形式
4)修改從./6382/redis.conf
vim ./6382/redis.conf
#修改以下key的值
bind 0.0.0.0#任意ip均可以鏈接
protected-mode no#關閉保護,容許非本地鏈接
port 6382#端口號
daemonize yes#後臺運行
pidfile /var/run/redis_6382.pid#進程守護文件,就是存放該進程號相關信息的地方
dir /usr/local/redis-ms/6382/#db等相關目錄位置
slaveof 192.168.194.131 6381#主信息
appendonly yes#開啓日誌形式
5)修改從./6383/redis.conf
vim ./6383/redis.conf
#修改以下key的值
bind 0.0.0.0#任意ip均可以鏈接
protected-mode no#關閉保護,容許非本地鏈接
port 6383#端口號
daemonize yes#後臺運行
pidfile /var/run/redis_6383.pid#進程守護文件,就是存放該進程號相關信息的地方
dir /usr/local/redis-ms/6383/#db等相關目錄位置
slaveof 192.168.194.131 6381#主信息
appendonly yes#開啓日誌形式
cd /usr/local/redis-ms/
/usr/local/redis/src/redis-server ./6381/redis.conf
/usr/local/redis/src/redis-server ./6382/redis.conf
/usr/local/redis/src/redis-server ./6383/redis.conf
ps -ef|grep redis
#查看主從是否搭建成功
/usr/local/redis/src/redis-cli -p 6381
info
如圖:
/usr/local/redis/src/redis-cli -p 6381 --raw
set name '丁潔'
get name
/usr/local/redis/src/redis-cli -p 6382 --raw
get name
/usr/local/redis/src/redis-cli -p 6382 --raw
get name
注:
--raw 中文顯示
主6381設置name值,能夠在從638二、6383取到,可是從不能設置值。
mkdir /usr/local/redis-ms/script
cd /usr/local/redis-ms/script/
vim ./start.sh
#!/bin/sh /usr/local/redis/src/redis-server /usr/local/redis-ms/6381/redis.conf /usr/local/redis/src/redis-server /usr/local/redis-ms/6382/redis.conf /usr/local/redis/src/redis-server /usr/local/redis-ms/6383/redis.conf
vim ./stop.sh
#!/bin/sh /usr/local/redis/src/redis-cli -p 6381 shutdown /usr/local/redis/src/redis-cli -p 6382 shutdown /usr/local/redis/src/redis-cli -p 6383 shutdown
vim ./restart.sh
#!/bin/sh systemctl stop redis-ms systemctl start redis-ms
chmod 777 ./*
cd /usr/lib/systemd/system/
vim redis-ms.service
[Unit] Description=redis-ms After=network.target remote-fs.target nss-lookup.target [Service] Type=forking ExecStart=/usr/local/redis-ms/script/start.sh ExecStop=/usr/local/redis-ms/script/stop.sh ExecReload=/usr/local/redis-ms/script/restart.sh [Install] WantedBy=multi-user.target
改變權限
chmod 777 redis-ms.service
進程服務重加載
systemctl daemon-reload
開機啓動主從
systemctl enable redis-ms.service
啓動主從
systemctl start redis-ms.service
關閉主從
systemctl stop redis-ms.service
重啓主從
systemctl restart redis-ms.service