what is Redis
Redis is a key-value storage system. Similar to Memcached, it supports storing relatively many value types, including string, list, set, and zset.
These data types support push / pop, add / remove, and intersection and union and difference sets and richer operations, all of which are atomic.
On this basis, Redis supports a variety of different sorts. Like memcached, data is cached in memory for efficiency.
The difference is that Redis periodically writes updated data to disk or writes modifications to additional log files and implements master-slave synchronization based on this. Redis is a high-performance key-value database.
The emergence of Redis, a large extent, to compensate for such lack of keyvalue memcached storage, in some cases can play a good complement to the relational database.
1, Redis installation
1.1 Pre-installation environment description
Using a CentOS 7 version of Linux system with
master ip of 192.168.1.110
slave ip of 192.168.1.111 The
1.2 Download Redis
Redis can go to the official website to download: https://redis.io/download , now the latest stable version has reached 4.0.
Used here is redis-4.0.1.tar.gz .
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 test
make[1]: *** [test] Error 1
make[1]: Leaving directory `/usr/local/redis-4.0.1/src’
make: *** [test] Error 2
solution
yum install -y tcl
2, Redis simple configuration
All configuration changes are in this configuration file
/usr/local/redis-4.0.1/redis.conf
2.2 bound host address
Bind after the host to add ip,from behind Redis need to connect through the IP.
bind 127.0.0.1 192.168.1.110
2.3 Set Redis password
The password is set herejaven
# requirepass foobared
requirepass mohan
2.4 Set the Redis port number
The default port is6379
port 6379
3, test Redis
start up
/usr/local/redis-4.0.1/redis.conf
src/redis-server
src/redis-server redis.conf
Client connection
src/redis-cli
src/redis-cli -a mohan
/usr/local/redis-4.0.1/redis.conf
src/redis-cli shutdown
src/redis-cli -p 6666 shutdown
4, Redis master-slave replication configuration
Redis master-slave replication is very powerful, a master can have multiple slaves, and a slave can have multiple slaves, so go on, forming a powerful multi-level server cluster architecture. The following simple configuration.
Modify the slave’s redis configuration file
Master’s redis configuration file bindcan be set as long as
Slave redis modify the slave configuration file slaveof 10.211.55.3 6379 (mapped to the main server, 6379the port number)
can also be dynamically set:
Redis-cli connected to the slave node server, execute the following command.
slaveof 10.211.55.3 6379
If master sets the authentication password, you also need to configure masterauth. Here I set the master authentication password javen, so configure masterauth javen.
After configuring the slave start the Redis service, OK, master-slave configuration is completed (is not very simple).
The following test:
In the master and slave, respectively, the info command to view the results are as follows:
slave:
[root@centos-linux-2 redis-4.0.1]# src/redis-cli
127.0.0.1:6379> info
5, Redis remote connection
Usage: redis-cli [OPTIONS] [cmd [arg [arg …]]]
-h <host ip>, the default is 127.0.0.1
-p <port>, the default is 6379
-a <password>, redis lock, you need to pass the password
-help, Show help information
redis-cli -h 10.211.55.4 -p 6379 -a javen
Recent Comments