Main redis:192.168.1.155:6379
From redis:192.168.1.155:6380
sentinel:192168.1.155:26379
Copy the/usr/local/redis directory as shown
650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M00/84/94/wKioL1eVl66jNtdDAAArzZwfyQU225.jpg "title=" 1.jpg " alt= "Wkiol1evl66jntddaaarzzwfyqu225.jpg"/> Modify the inside configuration file, data file directory, etc.
Master Redis port:6379
From Redis port:6380
sentinel:26379
will be modified here from the Redis configuration file:
#slaveof Masterip Masterport
slaveof 192.168.1.155 6379: Specify the IP and port of the master Redis from the configuration file
Of course you need encryption. You can also define an encrypted login
#masterauth master_passwd:master need to verify password login
Masterauth Mypass (Requires a-a mypass parameter for password verification when master is logged on with Redis-cli-p 6379)
Sign in to master Redis
Redis-server/usr/local/redis/etc/redis.conf
NETSTAT-TUNLP: See if the port is up
Redis-cli-p 6379: Sign in to Redis
>info Replication (Info command to view redis information)
# Replication
Role:master
connected_slaves:0: Since there is no online
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
Similarly, access to the slave Redis service as follows
Redis-server/usr/local/redis-slave/etc/redis-slave.conf
Redis-cli-p 6380
650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M02/84/94/wKiom1eVm4Cw-XnKAABu1KjROjw011.jpg "title=" 2.jpg " alt= "Wkiom1evm4cw-xnkaabu1kjrojw011.jpg"/>
It can be seen from Redis has also been up, login slave redis view replication status
# Replication
Role:slave
Master_host:::1
master_port:6379
Master_link_status:up
Master_last_io_seconds_ago:2
master_sync_in_progress:0
slave_repl_offset:169
slave_priority:100
Slave_read_only:1
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
Check the info replication information in master Redis again
# Replication
Role:master
Connected_slaves:1
Slave0:ip=::1,port=6380,state=online,offset=309,lag=0
master_repl_offset:309
Repl_backlog_active:1
repl_backlog_size:1048576
Repl_backlog_first_byte_offset:2
repl_backlog_histlen:308
It is clear from the above information that master and slave have completed
Next Configure Sentinel Sentinel mode
Redis-sentinel has been prepared by the above, the port has been changed, so
Copy Sentinel configuration file sentinel.conf to/usr/local/redis-sentinel/etc/sentinel.conf
# Sentinel Monitor <master-name> <ip> <redis-port> <quorum>
Sentinel Monitor MyMaster 192.168.1.155 6379 1 (quorum: Legal votes to determine failover)
Then launch Sentinel.
redis-server/usr/local/redis-sentinel/etc/sentinel.conf--sentinel (add model later)
Login Sentinel:
Redis-cli-p 26379
>info use the info command to view master and slave information
The port scripts are as follows:
redis_6379
#!/bin/bash
#
Redis_cmd= "/usr/local/redis/bin"
Prog=redis
Lockfile= "/var/lock/subsys/redis"
redis_conf= "/usr/local/redis/etc/redis.conf"
redis_port=6379
. /etc/init.d/functions
Start () {
$redis _cmd/redis-server $redis _conf
[$?-eq 0] && {
Action "Starting $prog"/bin/true
Touch $lockfile
}
}
Stop () {
$redis-cli-p $redis _port shutdown
[$?-eq 0] && {
Action "Stopping $prog"/bin/true
Rm-f $lockfile
}
}
Case "$" in
Start
Start
;;
Stop
Stop
;;
Restart
Stop
Start
;;
*)
echo "Usage: $ {Start|stop|restart}"
;;
Esac
redis_6380
#!/bin/bash
#
redis_port=6380
Redis_home= "/usr/local/redis/bin"
Prog= "redis_6380"
redis_conf= "/usr/local/redis-slave/etc/redis-slave.conf"
Lockfile= "/var/lock/subsys/redis_6380"
. /etc/init.d/functions
Start () {
$redis _home/redis-server $redis _conf
[$?-eq 0] && {
Action "Starting $prog"/bin/true
Touch $lockfile
}
}
Stop () {
$redis _home/redis-cli-p $redis _port
[$?-eq 0] && {
Action "Stopping $porg"/bin/true
Rm-f $lockfile
}
}
Case "$" in
Start
Start
;;
Stop
Stop
;;
Restart
Stop
Start
;;
*)
echo "Usage: $ {Start|stop|restart}"
;;
Esac
Sentinel Sentinel Startup script:
#!/bin/bash
#
Redis_cmd= "/usr/local/redis/bin"
Prog= "Redis_sentinel"
Lockfile= "/var/lock/subsys/redis_sentinel"
redis_conf= "/usr/local/redis-sentinel/etc/sentinel.conf"
redis_port=26379
. /etc/init.d/functions
Start () {
$redis _cmd/redis-server $redis _conf--sentinel (be sure to bring the Sentinel mode)
[$?-eq 0] && {
Action "Starting $prog"/bin/true
Touch $lockfile
}
}
Stop () {
$redis _cmd/redis-cli-p $redis _port
[$?-eq 0] && {
Action "Stopping $prog"/bin/true
Rm-f $lockfile
}
}
Case "$" in
Start
Start
;;
Stop
Stop
;;
Restart
Stop
Start
;;
*)
echo "Usage: $ {Start|stop|restart}"
;;
Esac
Reference article: http://blog.csdn.net/lifetragedy/article/details/50660310
Redis's master-slave and Sentinel creation