Dependent environment
centos 6.5
gcc-4.4.7: Compile redis original file
tcl-8.5.7: Run compilation detection
1. Compile redis
#cd /usr/local #tar -zxvf redis-4.0.1.tar.gz #mv redis-4.0.1 redis #cd redis #make
Running the compilation test make test requires tcl-8.5 and above
#yum install -y tcl #make test
2. Start redis
#cd src #./redis-server
3. Access redis
#cd ./redis-cli
It is recommended to install the latest version. When accessing on the Linux side, there are code format prompts for easy practice
>set name "redis" >get name
4 .Master-slave replication
Deploy two redis services on one machine
#cd /usr/local
4.1. Create redis (master) with service port 6379
#mv redis redis-6379 #mkdir redis-6380
4.2. The service port is redis (slave) 6380
#cp -r redis-6379 redis-6380 #cd redis-6380
4.3. Change the port and set the ip and port of the main redis
#vi redis.conf port=6380 slaveof 127.0.0.1 6379
4.4. Start the master redis first and then start the slave redis
# cd /usr/local/redis-6379/src #./redis-server ../redis.conf #cd /usr/local/redis-6380/src #./redis-server ../redis.conf
4.5. Test the master-slave redis
#./redis-cli -p 6379 >set name "redis" >get name redis >quit #./redis-cli -p 6380 >get name redis
tip : If you test redis master-slave replication between different servers, you need to note that the IP bound to redis needs to be changed to an open-access IP (127.0.0.1—>192.168.2.134), and the port also needs to be open in the firewall
The above is the detailed content of How to configure redis installation and master-slave replication in CentoS environment. For more information, please follow other related articles on the PHP Chinese website!