Redis4.0.1 installation and master-slave Replication
0. What is Redis?
Redis is a key-value storage system. Similar to Memcached, Memcached supports more storage value types, including string, list, set, and zset ). These data types support push/pop, add/remove, Intersection Set and difference set, and more abundant operations, and these operations are atomic. On this basis, Redis supports sorting in different ways. Like memcached, data is cached in the memory to ensure efficiency. The difference is that Redis periodically writes the updated data to the disk or writes the modification operation to the append record file, and on this basis implements master-slave (master-slave) synchronization. Redis is a high-performance key-value database. The emergence of Redis largely compensates for the shortage of keyvalue storage such as memcached, and can play a good complementary role in relational databases in some cases.
1. Environment Description before Redis installation 1.1
CentOS 7 Linux is used,
The master ip address is 10.211.55.3.
The slave ip address is 10.211.55.4.
The Virtual Machine Tool uses Parallels Desktop
1.2 download Redis
You can download Redis from the official website: https://redis.io/download. now, the latest stable version has reached 4.0.
Redis-4.0.1.tar.gz is used here.
1.3 Installation Steps
$ wget http://download.redis.io/releases/redis-4.0.1.tar.gz$ tar xzf redis-4.0.1.tar.gz -C /usr/local/$ cd /usr/local/redis-4.0.1$ make & make test
make
Possible exceptions
make[1]: Leaving directory `/usr/local/redis-4.0.1/src'make[1]: Entering directory `/usr/local/redis-4.0.1/src'You need tcl 8.5 or newer in order to run the Redis testmake[1]: *** [test] Error 1make[1]: Leaving directory `/usr/local/redis-4.0.1/src'make: *** [test] Error 2
Solution
yum install -y tcl
2. Simple Redis Configuration
All configuration modifications are made in this configuration file
/usr/local/redis-4.0.1/redis.conf
2.1 run as a daemon
Redis does not run as a daemon by default. You can modify this configuration item and use yes to enable the daemon.
# Daemonize no # change to yes daemonize yes
2.2 host address bound
Bind and add the Host ip address.Master-slave Replication
From Redis, you need to connect through an IP address.
bind 127.0.0.1 10.211.55.3
2.3 set the Redis Password
Set the password herejaven
# requirepass foobaredrequirepass javen
2.4 set the Redis port number
The default port is6379
port 6379
3. Test Redis
# Default configuration file/usr/local/redis-4.0.1/redis. confsrc/redis-server # or specify the configuration file src/redis-server redis. conf
Backend startup
src/redis-server &
Src/redis-cli # if there is a password, src/redis-cli-a Javen
# Default configuration file/usr/local/redis-4.0.1/redis. conf port src/redis-cli shutdown # specify the port src/redis-cli-p 6666 shutdown
4. Redis master-slave replication Configuration
Redis's master-slave replication function is very powerful. One master can have multiple slave instances, and one slave can have multiple slave instances. In this way, a powerful multi-level server cluster architecture is formed. The following is a simple configuration.
Modify the slave redis configuration file
- Set the redis configuration file of the master
bind
You can.
Modify the slave redis configuration file
Slaveof 10.211.55.3 6379 (mapped to the master server,6379
Is the port number)
You can also set it dynamically:
Connect to the slave node server through redis-cli and execute the following command.
Slaveof 10.211.55.3 6379
If a verification password is set for the master, you also need to configure masterauth. I set the verification password to javen for the master here, So configure masterauth javen.
After the configuration is complete, start the slave Redis service, OK, Master/slave configuration is complete (isn't it easy ).
The following is a test:
Run the info command on the master and slave respectively. The result is as follows:
Slave:
info" data-snippet-id="ext.a48eb390a343ced46aae6ab453a5354f" data-snippet-saved="false" data-codota-status="done">[root@centos-linux-2 redis-4.0.1]# src/redis-cli127.0.0.1:6379> info
If you connect from Redis to the mastermaster_link_status:up
Otherwisedown
. Ifdown
Please stick to the master Redis or notbind
The Host IP address and whether the password is set. Because the remote connection from Redis is requiredbind
If the Redis of the master node has a Server Load balancer password, it must be set.masterauth
Master:
Then execute set age 18 on the master.
Run get age on slave to check if the value is 18. If yes, the configuration is successful.
Next, we will post the modified slave parameters:
daemonize yesbind 127.0.0.1 10.211.55.4 requirepass javenport 6379slaveof 10.211.55.3 6379masterauth javen
5. Redis remote connection
Usage: redis-cli [OPTIONS] [cmd [arg [arg…]
-H <Host ip address>. The default value is 127.0.0.1.
-P <port>. The default value is 6379.
-A <password>: If redis is locked, the password must be passed.
-Help: displays help information.
redis-cli -h 10.211.55.4 -p 6379 -a javen
Recommended reading:
Detailed description of installation and master-slave synchronization configuration based on CentOS Mysql 5.7.19
Build Git Service Based on CentOS
Build FTP File Service Based on CentOS
Build your own ngork server in 10 minutes to achieve Intranet penetration
Build a JDK development environment and configure Environment Variables
Rapid Development