Home > Database > Redis > body text

How to configure redis installation and master-slave replication in CentoS environment

王林
Release: 2023-05-26 19:07:16
forward
1113 people have browsed it

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
Copy after login

Running the compilation test make test requires tcl-8.5 and above

#yum install -y tcl
#make test
Copy after login

2. Start redis

#cd src
#./redis-server
Copy after login

3. Access redis

#cd ./redis-cli
Copy after login

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
Copy after login

4 .Master-slave replication

Deploy two redis services on one machine

#cd /usr/local
Copy after login

4.1. Create redis (master) with service port 6379

#mv redis redis-6379
#mkdir redis-6380
Copy after login

4.2. The service port is redis (slave) 6380

#cp -r redis-6379 redis-6380
#cd redis-6380
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!