groupadd -g 1862 redis
useradd -u 1862 -g 1862 -d /redis redis
chmod -R 750 /redis
echo abcd1234 | passwd --stdin redis
chown -R redis:redis /redis
su - redis
cp -r /etc/skel/. ./
source .bash_profile
exit
usermod -a -G redis patrol
sed -i ‘/vm.overcommit_memory/d’ /etc/sysctl.conf
echo “vm.overcommit_memory = 1” >> /etc/sysctl.conf
sysctl -p
echo never > /sys/kernel/mm/transparent_hugepage/enabled
vi /etc/rc.local
echo never > /sys/kernel/mm/transparent_hugepage/enabled
vi /etc/security/limits.conf
soft core unlimited
hard core unlimited
soft nofile 65536
hard nofile 65536
soft nproc 65536
hard nproc 65536
vi /etc/security/limits.d/20-nproc.conf
vi /etc/rc.local
sh /home/AppAutoStart_Redis.sh
touch /home/AppAutoStart_Redis.sh
chown redis:redis /home/AppAutoStart_Redis.sh
chmod 744 /home/AppAutoStart_Redis.sh
vi /etc/hosts
mkdir -p /redis/install
chown redis. -R /redis
su - redis
cd /redis/install/ && tar zxf redis-4.0.12.tar.gz
cd /redis/install/redis-4.0.12
REDIS_HOME=/redis/redis-4.0.12
cd deps && make hiredis lua jemalloc linenoise
cd /redis/install/redis-4.0.12 && make
make PREFIX=${REDIS_HOME} install
ls ${REDIS_HOME}/bin
export REDIS_HOME=/redis/redis-4.0.12
export PATH=PATH
mkdir -p ${REDIS_HOME}/conf/
mkdir -p ${REDIS_HOME}/tools/
cp /redis/install/redis-4.0.12/redis.conf ${REDIS_HOME}/conf/
cd ${REDIS_HOME}/conf/
sed -i “s/daemonize no/daemonize yes/g” redis.conf
sed -i “s/pidfile /var/run/redis_6379.pid/pidfile /redis/R_instance_name/redis.pid/g” redis.conf
sed -i “s/logfile “”/logfile /redis/R_instance_name/log/redis.log/g” redis.conf
sed -i “s/dir .//dir /redis/R_instance_name/snapshot/g” redis.conf
sed -i “s/# maxmemory
sed -i “s/bind 127.0.0.1/bind R_IP/g” redis.conf
sed -i “s/port 6379/port R_PORT/g” redis.conf
vi ${REDIS_HOME}/tools/env.instance
export instance_name=gdlf
export REDIS_HOME=/redis/redis-4.0.12
vi ${REDIS_HOME}/tools/instance.start.sh
. /redis/R_instance_name/env.R_instance_name
REDIS_BASE_DIR=/redis/R_instance_name
redis-server ${REDIS_BASE_DIR}/conf/redis.conf
vi ${REDIS_HOME}/tools/instance.stop.sh
. /redis/R_instance_name/env.R_instance_name
REDIS_BASE_DIR=/redis/R_instance_name
PW=cat $REDIS_BASE_DIR/conf/redis.conf | grep ^requirepass | awk -F "requirepass " '{print $2}' | sed "s/\"//g"
B_IP=cat $REDIS_BASE_DIR/conf/redis.conf | grep ^bind | awk -F "bind " '{print $2}'
PORT=cat $REDIS_BASE_DIR/conf/redis.conf | grep ^port | awk -F "port " '{print $2}'
redis-cli -h ${B_IP} -p {PW}" shutdown
vi ${REDIS_HOME}/tools/instance.cli.sh
. /redis/R_instance_name/env.R_instance_name
REDIS_BASE_DIR=/redis/R_instance_name
PW=cat $REDIS_BASE_DIR/conf/redis.conf | grep ^requirepass | awk -F "requirepass " '{print $2}' | sed "s/\"//g"
B_IP=cat $REDIS_BASE_DIR/conf/redis.conf | grep ^bind | awk -F "bind " '{print $2}'
PORT=cat $REDIS_BASE_DIR/conf/redis.conf | grep ^port | awk -F "port " '{print $2}'
redis-cli -h ${B_IP} -p {PW}"
instance_name=gdlf
mkdir -p /redis/${instance_name}/{conf,log,snapshot}
cp {instance_name}/conf/
R_PORT=7379
R_instance_name=${instance_name}
R_maxmemory=1073741824
R_IP=10.240.37.231
cd /redis/{R_IP}/g" redis.conf
sed -i “s/R_PORT/{R_instance_name}/g” redis.conf
sed -i "s/R_maxmemory/{instance_name}/conf/redis.conf | grep -e “^daemonize” -e “^pidfile” -e “^logfile” -e “^dir” -e “^maxmemory” -e “^bind” -e “^port”
cd /redis/${instance_name}/
cp {instance_name}
cp ${REDIS_HOME}/tools/instance.start.sh start.sh
cp ${REDIS_HOME}/tools/instance.stop.sh stop.sh
cp ${REDIS_HOME}/tools/instance.cli.sh cli.sh
cd /redis/{instance_name}/g" env.{instance_name}/g" start.sh
sed -i “s/R_instance_name/{instance_name}/g” cli.sh
chmod +x /redis/{instance_name}/stop.sh
chmod +x /redis/{instance_name}/start.sh"
EOF
/redis/${instance_name}/start.sh
/redis/${instance_name}/cli.sh
集群:
cd /redis/{instance_name}/conf/ sed -i "s/\# cluster-config-file nodes-6379.conf/cluster-config-file ..\/conf\/nodes-{instance_name}.conf/g" redis.conf
sed -i “s/# cluster-enabled yes/cluster-enabled yes/g” redis.conf
sed -i “s/# cluster-node-timeout 15000/cluster-node-timeout 5000/g” redis.conf
sed -i “s/# cluster-require-full-coverage yes/cluster-require-full-coverage yes/g” redis.conf
cd /redis/${instance_name}/conf/
cat redis.conf | grep -e “^cluster-config-file” -e “^cluster-enabled” -e “^cluster-node-timeout” -e “^cluster-require-full-coverage”
/redis/${instance_name}/start.sh
root:
cd /redis/install
umask 022
yum -y install ruby
cd /redis/install
gem install -l redis-3.3.5.gem
cp /redis/install/redis-4.0.12/src/redis-trib.rb ${REDIS_HOME}/bin
redis-trib.rb create 10.240.37.226:7379 10.240.37.245:7379 10.240.37.231:7379
redis-trib.rb add-node --slave 10.240.37.231:7380 10.240.37.231:7379
redis-trib.rb check 10.240.37.245:7380
config set masterauth okcenno
config set requirepass okcenno
auth okcenno
config rewrite
处一节点
cd /usr/local/share/gems/gems/redis-3.3.5/lib/redis/
PW=okcenno
sed -i “s/:password => nil,/:password => “${PW}”,/g” client.rb
redis-trib.rb check 10.240.37.231:7380
哨兵:
sentinel_name=sentinel
instance_name=gdlf
mkdir -p /redis/${sentinel_name}/{conf,log,snapshot}
cp {sentinel_name}/conf/sentinel.conf
B_IP=10.240.54.190
MASTER_IP=10.240.54.190
L_PORT=27379
master_name=${instance_name}
master_port=7379
PW=okcenno
cd /redis/{B_IP}/g" sentinel.conf
sed -i “s/MASTER_IP/{L_PORT}/g” sentinel.conf
sed -i “s/R_sentinel/{master_name}/g” sentinel.conf
sed -i “s/master_port/{PW}/g” sentinel.conf
cat /redis/${sentinel_name}/conf/sentinel.conf
cd /redis/${sentinel_name}/
cp {sentinel_name}
cp ${REDIS_HOME}/tools/sentinel.start.sh start.sh
cp ${REDIS_HOME}/tools/sentinel.stop.sh stop.sh
cp ${REDIS_HOME}/tools/sentinel.cli.sh cli.sh
cd /redis/{sentinel_name}/g" env.{sentinel_name}/g" start.sh
sed -i “s/R_sentinel_name/{sentinel_name}/g” cli.sh
chmod +x /redis/{sentinel_name}/stop.sh
chmod +x /redis/{sentinel_name}/start.sh"
EOF