标签:启动脚本 pass start centos 7 wan chmod 前台 emd targe
安装环境L:Linux(centos 7.6)
R: Redis(5.0.7)http://download.redis.io/releases/
172.24.77.241(sr1.dj.com):运行Redis-Master&Slave
172.24.77.242(sr2.dj.com):运行Redis--Master&Slave
172.24.77.243(sr3.dj.com):运行Redis--Master&Slave
cd /usr/local/src/
tar xvf redis-5.0.7.tar.gz
cd redis-5.0.7
make PREFIX=/usr/local/redis install
ll /usr/local/redis/
mkdir /usr/local/redis/etc
cp redis.conf /usr/local/redis/etc/
vim /etc/sysctl.conf
net.core.somaxconn=512
vm.overcommit_memory = 1
sysctl -p
1:表示内核允许分配所有的物理内存,而不管当前的内存状态如何。
2:表示内核允许分配超过所有物理内存和交换空间总和的内存
vim /etc/rc.d/rc.local
echo never > /sys/kernel/mm/transparent_hugepage/enabled
chmod a+x /etc/rc.d/rc.local
init 6
/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
vim /usr/lib/systemd/system/redis.service
[Unit]
Description=Redis persistent key-value database
After=network.target
After=network-online.target
Wants=network-online.target
[Service]
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf --supervised systemd
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
Type=notify
User=root
Group=root
RuntimeDirectory=redis
RuntimeDirectoryMode=0755
[Install]
WantedBy=multi-user.target
groupadd -g 1000 redis && useradd -u 1000 -g 1000 redis -s /sbin/nologin
mkdir -pv /usr/local/redis/{etc,logs,data,run}
chown redis.redis /usr/local/redis/ -R
systemctl start redis
/usr/local/redis/bin/redis-cli
/usr/local/redis/bin/redis-cli -h 172.24.77.241 -p 6379 -a PASSWORD
ln -sv /usr/local/redis/bin/redis-* /usr/bin/
vim /usr/local/redis/etc/redis.conf
bind 0.0.0.0
daemonize yes
master 如果密码需要设置 293行
masterauth 123456
设置启用密码507行
requirepass 123456
cluster-enabled yes
systemctl start redis
/usr/local/redis/bin/redis-cli
get key*
info replication
systemctl stop redis
cp -r /usr/local/redis /usr/local/redis2
vim /usr/local/redis2/etc/redis.conf
port 6380
/usr/local/redis2/bin/redis-server /usr/local/redis2/etc/redis.conf
redis-cli -a 123456 --cluster create 172.24.77.241:6379 172.24.77.241:6380 172.24.77.242:6379 172.24.77.242:6380 172.24.77.243:6379 172.24.77.243:6380 --cluster-replicas 1
yes #输入 yes 自动创建集群
[OK] All nodes agree about slots configuration.
Check for open slots...#所有节点槽位分配完成
Check slots coverage...#检查打开的槽位
[OK] All 16384 slots covered.#检查插槽覆盖范围
redis-cli -h 172.24.77.241 -p 6380 -a 123456
CONFIG SET masterauth 123456
info replication
redis-cli -h 172.24.77.242 -p 6380 -a 123456
CONFIG SET masterauth 123456
redis-cli -h 172.24.77.243 -p 6380 -a 123456
CONFIG SET masterauth 123456
redis-cli -h 172.24.77.241 -p 6379 -a 123456
info replication
cluster info
cluster nodes
172.24.77.242:6379> set key1 test1
172.24.77.243:6380> keys *
redis-trib.rb check 172.24.77.241:6379 ##redis4版本
redis-cli -a 123456 --cluster check 172.24.77.241:6379 ##redis5版本
新节点244安装redis(略)
配置双redis
cp -r /usr/local/redis /usr/local/redis2
cd /usr/local/redis/etc/
在现在节点上执行
scp redis.conf root@172.24.77.244:/usr/local/redis/etc/
cd /usr/local/redis2/etc
scp redis.conf root@172.24.77.244:/usr/local/redis/etc/
systemctl daemon-reload
systemctl restart redis
/usr/local/redis/bin/redis-server /usr/local/redis2/etc/redis.conf
redis-cli -a 123456 --cluster add-node 172.24.77.244:6379 172.24.77.241:6379
要添加的新redis节点IP和端口添加到的集群中的 master IP:端口, 加到集群之后默认是 master 节点但是没有slots 数据,需要重新分配
redis-trib.rb check 172.24.77.241:6379
redis-cli -a 123456 --cluster reshard 172.24.77.244:6379
4096 #分配多少个槽位
新redis ID ##接收 slot 的服务器 ID, 手动输入172.24.77.244的 node ID
Source node all #1: all #将哪些源主机的槽位分配给 192.168.7.104:6379, all 是自动在所有的 redis node 选
择划分,如果是从 redis cluster 删除主机可以使用此方式将主机上的槽位全部移动到别的 redis 主机
yes #确认分配
redis-cli -a 123456 --cluster check 172.24.77.242:6379
redis-cli -a 123456 --cluster add-node 172.24.77.244:6380 172.24.77.244:6379
redis-cli -h 172.24.77.244 -p 6380 -a 123456
CLUSTER REPLICATE master id
cluster replicate 9d63a881bf0e7f8d8b29a786448e7c22de30ba6a
CLUSTER NODES #再次查看集群节点状态, 验证节点是否已经更改为指定 master 的 slave
redis-cli -a 123456 --cluster check 172.24.77.244:6379
标签:启动脚本 pass start centos 7 wan chmod 前台 emd targe
原文地址:https://blog.51cto.com/13688209/2509808