installation of redis
Because Redis is developed in c language. Redis requires a compilation environment for the C language. If no gcc needs to be installed online. yum install gcc-c++
installation steps:
Step 1: Upload the source package of redis to the linux system.
Step 2: Unzip redis.
Step 3: Compile. Enter the redis source directory. make
the fourth step: installation. Specify the installation directory make install PREFIX=/usr/local/redis
The PREFIX parameter specifies the installation directory of redis. General software is installed in the /usr/local directory
start up:
It is recommended to use the configuration file to start:
Copy the redis.conf in the source directory to /bin in the installation directory and modify the configuration file deamonize yes
connect:
[root @localhost bin]# ./redis-cli
connects to the redis service running on port 6379 on localhost by default.
[root @localhost bin]# ./redis-cli -h IP address -p 6379
-h: The address of the connected server
-p: The port number of the service
Shut down redis: [root @localhost bin]# ./redis-cli shutdown
Building a Redis cluster
There should be at least three nodes in a Redis cluster. In order to ensure the high availability of the cluster, each node has a backup machine.
So a Redis cluster requires at least 6 servers.
Build pseudo-distribution. A single virtual machine can be used to run 6 redis instances. Need to modify the port number of redis 7001-7006
1. Use ruby script to build a cluster. Requires a ruby runtime environment.
Install ruby:
yum install ruby
yum install rubygems
2. Install the package used by the ruby script to run:
wget https://rubygems.global.ssl.fastly.net/gems/redis-3.2.1.gem
gem install -l ./redis -3.2.1.gem
Construction steps
6 redis servers are required. Build pseudo-distribution.
6 redis instances are required.
Need to run on different ports 7001-7006
Step 1: Create 6 redis instances, each instance runs on a different port, so you need to modify the port number of each instance in the redis.conf configuration file. And remove the comment before cluster-enabled yes
Step 2: Start each redis instance.
Step 3: Use ruby script to build a cluster.
Unzip the directory
src./redis-trib.rb create --replicas 1 IP address: 7001 IP address: 7002 IP address: 7003 IP address: 7004 IP address: 7005 IP address: 7006
Replicas means that each redis has a backup machine Can I set the above configuration? (type 'yes' to accept): yes
when the script is executed
Finally, ALL 16384 slots coverd appears, indicating that the cluster is successfully built
Connect to redis cluster
Redis-cli connects to the cluster.
[root @localhost redis-cluster]# redis01/redis-cli -p 7001 -c
-c: represents the connection to the redis cluster