Basic Single-node Configuration
Copy redis_init_script from redis utils to /etc/init.d/ and change it to redis_ port number
cp redis_init_script /etc/init.d/redis_6379
mkdir /etc/redis # Save redis configuration file
mkdir /var/redis/6379 Store redis persistent filesCopy the redis.conf file to /etc/redis/6379.conf# Change the configuration environment in redis.conf to production
daemonize yes Let Redis start in the background
pidfile /var/run/redis_6379.pid Set the pid file location of redis
port 6379 Set redis listening port number
dir /var/redis/6379 # set the location of the persistence file
Redis_cli can be used in any directory
sudo cp src/redis-cli /usr/local/bin/
sudo cp src/redis-server /usr/local/bin/
# start redis
cd /etc/init.d/
chmod 777 6379.conf
./redis_6379.conf start
Add the following two lines to the top of redis_6379 to make redis start automatically
#chkconifg:2345 90 10
#description:Redis is a persistent key-value database
# -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
# Execute the following command in the current directory
chkconfig redis_6379 on
Check whether Redis is started
ps -ef |grep redis
Copy the code
Primary/secondary replication configuration
master
In the redis configuration file, that is, /etc/redis/6379.conf
bindYour OWN IP address Requirepass key (optional)Copy the code
slave
bindMaster replicaof masterauth master replicaof Masterauth master replicaof Masterauth Master replicaof MasterCopy the code
Start the redis
Note: Start master first and then slave/etc/init.d/
./redis.6379 start
The server with RequirePass is required to enter the key, while the server without requirePass is not required. In other words, the master needs to enter the key, while the slave does not need to enter the keyRedisl -cli -h IP address of the current server -a Key configuredYou can view the master/slave configuration information in the server
info replication
Copy the code
master info replication
slave info replication
The problem
Ping succeeded, but Telnet failed. Procedure
- Telent master IP address redis set port number (default: 6379)
- If the Telnet command is not found, run the yum install -y Telnet command
- If there is a problem with yum, modify the source file of yum, vim /etc/yum.repos. D/epel.repo
Comment metalink and uncomment Baseurl as shown below4. After Telnet is installed, the slave can ping the master, but Telnet fails. In this case, the firewall of the server is faulty
# Turn off the firewall
systemctl disable firewalld.service
Check the firewall status
firewall-cmd --state
# temporarily disable the firewall
systemctl stop firewalld.service
Copy the code