redis哨兵之一机实现(懒人操作)

ls /redis_sentry &>/dev/null
if [ $? -ne 0 ];then
        mkdir /redis_sentry
        mkdir /redis_sentry/data
        mkdir /redis_sentry/logs
else
        rm -rf /redis_sentry
        mkdir /redis_sentry
        mkdir /redis_sentry/data
        mkdir /redis_sentry/logs
fi
#ls /etc/redis_sentry  &>/dev/null
#if [ $? -ne  0 ];then
#       mkdir /etc/redis_sentry
#else
#       rm -rf /etc/redis_sentry
#       mkdir /etc/redis_sentry
#fi
ls /var/run_sentry  &>/dev/null
if [ $? -ne 0 ];then
        mkdir /var/run_sentry
else
        rm -rf /var/run_sentry
        mkdir /var/run_sentry
fi
ls /etc/redis1_sentry  &>/dev/null
if [ $? -ne 0 ];then
        mkdir /etc/redis1_sentry
else
        rm -rf /etc/redis1_sentry
        mkdir /etc/redis1_sentry
fi

#主服务器
#主服务器
echo -e 'port 6380\nprotected-mode no\ndaemonize yes\npidfile "/var/run_sentry/redis-6380.pid"\nlogfile "/redis_sentry/logs/redis-6380.log"\ndir "/redis_sentry/data"\n' >> /etc/redis/master-6380.conf
#从服务器1
echo -e 'port 6381\nprotected-mode no\ndaemonize yes\npidfile "/var/run_sentry/redis-6381.pid"\nlogfile "/redis_sentry/logs/redis-6381.log"\ndir "/redis_sentry/data"\nslaveof 127.0.0.1 6380\n'>>/etc/redis/slave-6381.conf
#从服务器2
echo -e 'port 6382\nprotected-mode no\ndaemonize yes\npidfile "/var/run_sentry/redis-6382.pid"\nlogfile "/redis_sentry/logs/redis-6382.log"\ndir "/redis_sentry/data"\nslaveof 127.0.0.1 6380\n'>>/etc/redis/slave-6382.conf
#哨兵1
echo -e 'port 27000\ndir "/redis_sentry/data"\ndaemonize yes\nlogfile "27000.log"\nsentinel monitor mymaster 127.0.0.1 6380 2\nsentinel down-after-milliseconds mymaster 3000\nsentinel failover-timeout mymaster 5000\nsentinel parallel-syncs mymaster 1\nprotected-mode yes\n'>>/etc/redis/sentinel-27000.conf
#哨兵2
echo -e 'port 27001\ndir "/redis_sentry/data"\ndaemonize yes\nlogfile "27001.log"\nsentinel monitor mymaster 127.0.0.1 6380 2\nsentinel down-after-milliseconds mymaster 3000\nsentinel failover-timeout mymaster 5000\nsentinel parallel-syncs mymaster 1\nprotected-mode yes\n'>>/etc/redis/sentinel-27001.conf
ls /etc/redis1  &>/dev/null
if [ $? -ne 0 ];then
        mkdir /etc/redis1
else
        rm -rf /etc/redis1
        mkdir /etc/redis1
fi
#哨兵3
echo -e 'port 27002\ndir "/redis_sentry/data"\ndaemonize yes\nlogfile "27002.log"\nsentinel monitor mymaster 127.0.0.1 6380 2\nsentinel down-after-milliseconds mymaster 3000\nsentinel failover-timeout mymaster 5000\nsentinel parallel-syncs mymaster 1\nprotected-mode yes\n'>>/etc/redis/sentinel-27002.conf
#备份原文档
cp /etc/redis/* /etc/redis1/
#停止
#redis-cli -p 6380 shutdown &>/dev/null
#redis-cli -p 6381 shutdown &>/dev/null
#redis-cli -p 6382 shutdown &>dev/null
#redis-cli -p 27000 shutdown &>dev/null
#redis-cli -p 27001 shutdown &>dev/null
#redis-cli -p 27002 shutdown &>dev/null
#启动
redis-server  /etc/redis/master-6380.conf
redis-server /etc/redis/slave-6381.conf
redis-server /etc/redis/slave-6382.conf
redis-sentinel /etc/redis/sentinel-27000.conf
redis-sentinel /etc/redis/sentinel-27001.conf
redis-sentinel /etc/redis/sentinel-27002.conf

你可能感兴趣的:(redis哨兵之一机实现(懒人操作))