Redis Master-slave + sentinel installation
1. Machine preparation 5 sets
1 master node, 1 slave node
The other three install one sentinel
2. Installation package preparation, version 3.2.9
3. Installation environment
Check by command gcc-v that the following command was not executed to install GCC
yum install gcc
4. Prepare gcc environment-related packages if you do not support the installation of the yum command
After placing the package in the same folder, execute the following commands for installation
rpm -Uvh *.rpm --nodeps –force
Check GCC version gcc-v
1. Unzip redis installation package
cd /opt tar -zxf redis-3.2.9.tar.gz
Compile and install
cd /opt/redis make && make install
If the above problem occurs, the command make MALLOC=libc needs to be executed
Then enter the directory cd/src to execute the following commands
make install
3. Modify the configuration file redis.conf after the two machines are installed in accordance with the above steps
cd /opt/redis/
vi redis.conf
The master redis_6379.conf configuration file needs to be modified as follows:
#bind 127.0.0.1 port 6379 #port requirepass "myredis" #Password daemonize yes #Daemon process logfile "logs/redis_6379.log" #Log Path dbfilename "dump.rdb" #rdb file dir "/opt/redis file name" #working directory masterauth "myredis" pidfile "/var/run/redis_6379.pid" appendonly yes
The slave-1 redis_6379.conf configuration file needs to be modified as follows:
port 6379 #port bind 0.0.0.0 #local ip requirepass "myredis" #Password daemonize yes #Daemon process logfile "logs/redis_6379.log" #Log Path dbfilename "dump_6379.rdb" #rdb file dir "/opt/redis file name" #working directory masterauth "myredis" #After the master node configures the password, the slave node must be matched pidfile "/var/run/redis_6379.pid" slaveof masterIP port #Slave node configuration appendonly yes
The slave-2 redis_6380.conf configuration file needs to be modified as follows:
port 6380 #port bind 0.0.0.0 #local ip requirepass "myredis" #Password daemonize yes #Daemon process logfile "logs/redis_6380.log" #Log Path dbfilename "dump_6380.rdb" #rdb file dir "/opt/redis file name" #working directory masterauth "myredis" #After the master node configures the password, the slave node must be matched pidfile "/var/run/redis_6380.pid" slaveof masterIP port #Slave node configuration appendonly yes
After configuring, you need to create a logs file mkdir logs or start it up with an error
Start redis
/opt/redis/src/redis-server redis_6379.conf /opt/redis/src/redis-server redis_6379.conf /opt/redis/src/redis-server redis_6380.conf
Link redis
/opt/redis/src/redis-cli -p 6379 -a myredis
Setting Values
set name zhangsan get name
if value is zhangsan true or false
1. Perform the above redis installation steps on three machines
The directory where sentinel installs redis is / opt/server/redis
2. Configure sentinel configuration file after three machines have installed redis separately
cd /opt/redis
vi sentinel
port 63791 #port daemonize yes #Daemon process logfile "/var/log/sentinel_63791.log" #log file protected-mode no dir "/opt/redis-4.0.11" #working directory sentinel monitor mymaster masterIP 2 #If the redis data master node is authenticated, the following configuration is required sentinel auth-pass mymaster Password #Password authentication sentinel down-after-milliseconds mymaster 30000 sentinel failover-timeout mymaster 180000
Except for inconsistent port numbers, the three sentinel.conf configuration files are 63791, 63792 and 63793, all of which are the same.
3. Start three sentinel s by executing the following commands
/opt/server/redis/src/redis-sentinel sentinel.conf
Sentinel verification
/opt/server/redis/src/redis-cli –p 63791
info sentinel view sentinel status
So far, redis is built from three sentinel s.