010 Installation and configuration of redis4.0.8 under Linux (CentOS 6.8)

Installation:
1. Obtain redis resources (http://redis.io/download)
wget http://download.redis.io/releases/redis-4.0.8.tar.gz


2. Extract
tar xzvf redis-4.0.8 .tar.gz


3. Install
cd redis-4.0.8
make
cd src
make install PREFIX=/usr/local/redis


Note: If the make compilation fails, because the gcc service is not installed
rpm -qa |grep gcc to see if the installation is successful
yum install gcc


4. Move the configuration file to the installation directory
cd ../
mkdir /usr/local/redis/etc
cp redis.conf /usr/local/redis/etc


5. Configure redis to start
vi /usr/local/redis/ in the background etc/redis.conf //Change daemonize no to daemonize yes


6. Add redis to boot
vi /etc/rc.local //Add content inside:
/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf (meaning to call this command to start redis at boot)


7. Several files in the /usr/local/redis/bin directory A key file
redis-benchmark: redis performance test tool
redis-check-aof: tool for checking aof logs
redis-check-dump: tool for checking rdb logs
redis-cli: client for connection
redis-server: redis service process


settings The environment variable is that the above command does not need the absolute path
vi /etc/profile.d/redis.sh Add this file and add the following content:
export REDIS_HOME=/usr/local/redis
export PATH=$PATH:$REDIS_HOME/bin
execute the change The file takes effect immediately:
source /etc/profile.d/redis.sh 8. redis


use
start redis
redis-server /usr/local/redis/etc/redis.conf 
stop redis
redis-cli shutdown (./redis-cli -h 127.0.0.1 -p 6379 shutdown)
pkill redis-server
client
redis-cli (./redis-cli -h 127.0.0.1 -p 6379)
view
ps -ef | grep redis
netstat -ntlp | grep redis


9. Configure kernel parameters
Configure the overcommit_memory parameter
, otherwise, when the Redis script restarts or stops redis, it will An error will be reported, and the data cannot be automatically synchronized to the disk before the service is stopped.
It is a memory allocation strategy
. Optional values: 0, 1, 2.
0, means that the kernel will check whether there is enough available memory for the application process; if there is enough available memory, the memory application is allowed; otherwise, the memory application fails and an error is returned to the application process.
1, Indicates that the kernel allows all physical memory to be allocated, regardless of the current memory state.
2. Indicates that the kernel allows the allocation of memory that exceeds the sum of all physical memory and swap space.
Set vm.overcommit_memory to 1:
There are three ways to modify kernel parameters, but you must have root privileges:
(1) Edit /etc/sysctl.conf, change vm .overcommit_memory=1, then sysctl -p makes the configuration file take effect
(2) sysctl vm.overcommit_memory=1
(3) echo 1 > /proc/sys/vm/overcommit_memory


configure the somaxconn parameter to
define the largest listening queue for each port in the system The length, this is a global parameter, the default value is 128
echo 1000 >/proc/sys/net/core/somaxconn


10.conf Configuration item introduction
daemonize: if you need to run in the background, change the value of this item to yes
pdifile: put the pid file in /var/run/redis.pid , can be configured to other addresses
bind: specify that redis only receives requests from this IP, if not set, then all requests will be processed, it is best to set this
port in the production link: listening port, the default is 6379
timeout: set the client The timeout time when connecting, in seconds.
loglevel: The level is divided into 4 levels, debug, revbose, notice and warning. In the production environment, notice
logfile is generally enabled: configure the address of the log file, and the standard output is used by default, that is, it is printed on the port of the command line terminal
database: set the number of databases, the default database is 0
save: set the frequency of database mirroring by redis
rdbcompression: Whether to compress when performing mirror backup
dbfilename: The file name of the mirror backup file
dir: The path where the database mirror backup file is placed
slaveof: Set the database as the slave database of other databases
masterauth: When the master database connection requires password authentication, Set here
requirepass: Set the password that needs to be used after the client connects before making any other assignments
maxclients: Limit the number of clients connected at the same time
maxmemory: Set the maximum memory that redis can use
appendonly: After enabling appendonly mode, redis will append each received write operation to the appendonly.aof file. When redis restarts, it will restore the previous file from the file. Status
appendfsync: set the frequency of synchronization of appendonly.aof file vm_enabled :
whether to enable virtual memory support vm_page_size: Set the size of virtual memory pages vm_pages: Set the total page number of swap files vm_max_thrrads: Set the number of threads used by vm IO at the same time 11. Uninstall redis: rm -rf /usr/local/redis //Delete the installation directory rm -rf /usr/bin/redis-* //Delete all redis related command scripts Additional : Redis cluster setup Open 6 Redis instances on one node, and each of these 6 Redis has its own port. In this case, it is equivalent to simulating 6 machines. Then build a Redis cluster with these 6 instances 1. Obtain redis resources (http://redis.io/download) wget http://download.redis.io/releases/redis-4.0.8.tar.gz





























2. After decompressing
tar xzvf redis-4.0.8.tar.gz
, the directory is redis-4.0.8


3. Install
cd redis-4.0.8
make
cd src
make install PREFIX=/usr/local/redis-cluster


Note: If the make compilation fails, because the gcc service is not installed
rpm -qa |grep gcc to see if the installation is successful
yum install gcc


4. Move the configuration file to the installation directory The port number of the Redis node in the
planned cluster is 7001-7006, and the port number is under the cluster each instance folder. The data is stored in the port number/data folder.
mkdir -p /usr/local/redis-cluster/etc
mkdir -p /usr/local/redis-cluster/700{1,2,3,4,5,6}/data
cp redis-4.0.8/redis. conf /usr/local/redis-cluster/etc
cp redis-4.0.8/redis.conf /usr/local/redis-cluster/7001
cp redis-4.0.8/redis.conf /usr/local/redis-cluster/ 7002
cp redis-4.0.8/redis.conf /usr/local/redis-cluster/7003
cp redis-4.0.8/redis.conf /usr/local/redis-cluster/7004
cp redis-4.0.8/redis.conf /usr/local/redis-cluster/7005
cp redis-4.0.8/redis.conf /usr/local/redis-cluster/7006


5.配置redis.conf
清空7001-7006目录下的redis.conf配置,重新添加如下配置:
include /usr/local/redis-cluster/etc/redis.conf
port 7001
daemonize yes
bind 192.168.3.243
dir /usr/local/redis-cluster/7001/data/
logfile "/usr/local/redis-cluster/logs/7001.log"
pidfile /var/run/redis_7001.pid
cluster-enabled yes
cluster-config-file nodes-7001.conf
cluster-node-timeout 15000
dbfilename dump-7001.rdb
appendonly yes


注:
cluster-enabled yes
If cluster-config-file nodes-7001.conf
cluster-node-timeout 15000
is commented out, it is only that 6 redis ports are opened on one server, that is, the cluster is not opened.


6. Start and stop redis
:
/usr/local/redis-cluster/bin/redis-server /usr/local/redis-cluster/7001/redis.conf
/usr/local/redis-cluster/bin/redis-server / usr/local/redis-cluster/7002/redis.conf
/usr/local/redis-cluster/bin/redis-server /usr/local/redis-cluster/7003/redis.conf
/usr/local/redis-cluster/ bin/redis-server /usr/local/redis-cluster/7004/redis.conf
/usr/local/redis-cluster/bin/redis-server /usr/local/redis-cluster/7005/redis.conf
/usr/ local/redis-cluster/bin/redis-server /usr/local/redis-cluster/7006/redis.conf
stopped:
/usr/local/redis-cluster/bin/redis-cli -h 192.168.3.243 -p 7001 shutdown
pkill redis-server  
client connection:
/usr/local/redis-cluster/bin/redis-cli -h 192.168.3.243 -p 7001
View:
ps -ef | grep redis
netstat -ntlp | grep redis
The result is as follows:
#netstat -ntlp | grep redis
tcp 0 0 192.168.3.243:17001 0.0.0.0:* LISTEN 13950/redis-server  
tcp 0 0 192.168 .3.243:17002 0.0.0.0:* LISTEN 13967/redis-server  
tcp 0 0 192.168.3.243:17003 0.0.0.0:* LISTEN 13972/redis-server  
tcp        0      0 192.168.3.243:17004         0.0.0.0:*                   LISTEN      13974/redis-server  
tcp        0      0 192.168.3.243:17005         0.0.0.0:*                   LISTEN      13979/redis-server  
tcp        0      0 192.168.3.243:17006         0.0.0.0:*                   LISTEN      13987/redis-server  
tcp        0      0 192.168.3.243:7001          0.0.0.0:*                   LISTEN      13950/redis-server  
tcp        0      0 192.168.3.243:7002          0.0.0.0:*                   LISTEN      13967/redis-server  
tcp        0      0 192.168.3.243:7003          0.0.0.0:*                   LISTEN      13972/redis-server
tcp        0      0 192.168.3.243:7004          0.0.0.0:*                   LISTEN      13974/redis-server  
tcp 0 0 192.168.3.243:7005 0.0.0.0:* LISTEN 13979/redis-server  
tcp 0 0 192.168.3.243:7006 0.0.0.0:* LISTEN 13987/redis-server 


7. Create a cluster
redis officially provides redis-trib. The rb tool is located in the src directory of the decompression directory
cp redis-4.0.8/src/redis-trib.rb /usr/local/redis-cluster/bin


Since the Redis cluster needs to use the ruby ​​command, we need to install ruby ​​and related interfaces.
yum -y install ruby ​​ruby-devel rubygems rpm-build
gem install redis (installing the interface between redis and ruby)
This error may occur here: ERROR: Error installing redis: redis requires Ruby version >= 2.2.2, see the documentation for the handling method The final problem is dealt with,


this is the real cluster creation
/usr/local/redis-cluster/bin/redis-trib.rb create --replicas 1 192.168.3.243:7001 192.168.3.243:7002 192.168.3.243:7003 192.168.3.243:7004 192.168.3.243:7005 192.168.3.243:7006


[WARNING] Some slaves are in the same host as their master
M: 8493eeca008f83c9a6e2d3a24509f18b0b8c6851 192.168.3.243:7001
   slots:0-5460 (5461 slots) master
M: 4a54c721e2b38ee51cdd74f1a896d652c8f23981 192.168.3.243:7002
   slots:5461-10922 (5462 slots) master
M: 5bcdfff3911c8991342c8edc36a384f231a102c3 192.168.3.243:7003
   slots:10923-16383 (5461 slots) master
S: e743fd8969a2a7f5db687fa51f0e420c8a5c4e7d 192.168.3.243:7004
   replicates 5bcdfff3911c8991342c8edc36a384f231a102c3
S: bbea0be24de5230b5f27cb3bf282813c4c2c9177 192.168.3.243:7005
   Replicates 8493eeca008f83c9a6e2d3a24509f18b0b8c6851
S: f9b69590139b1509a4b76a76a1603581309d9142 192.168.3.243:7006
   Replicates 4a54c721e2b38ee51cdd74f1a896d652c8f23981
of Can the I the SET at The above the Configuration (of the type 'yes' to the Accept):? Yes


briefly explain this command: Call ruby commands to create a cluster , --replicas 1 indicates that the master-slave replication ratio is 1:1, that is, one master node corresponds to one slave node; then, each master node and corresponding slave node services are assigned to us by default,
as well as the size of solt, because in Redis There are only 16383 solts in the cluster. By default, they will be evenly distributed to us. Of course, you can specify, and subsequent additions and deletions of nodes can also be redistributed.
M: 5bcdfff3911c8991342c8edc36a384f231a102c3 primary node Id
S: e743fd8969a2a7f5db687fa51f0e420c8a5c4e7d 192.168.3.243:7004
   Replicates 5bcdfff3911c8991342c8edc36a384f231a102c3 Id corresponding to the master node from the node




to test:
It is still connected through the client command, and the status and node information are viewed through the cluster command.
/usr/local/redis-cluster/bin/redis-cli -c -h 192.168.3.243 -p 7001
cluster info
cluster nodes
shows the following:
# /usr/local/redis-cluster/bin/redis-cli -c -h 7001 -p 192.168.3.243
192.168.3.243:7001> Cluster info
cluster_state: OK
cluster_slots_assigned: 16384
cluster_slots_ok: 16384
cluster_slots_pfail: 0
cluster_slots_fail: 0
cluster_known_nodes:. 6
CLUSTER_SIZE:. 3
cluster_current_epoch:. 6
cluster_my_epoch:. 1
cluster_stats_messages_ping_sent: 423
cluster_stats_messages_pong_sent: 451
cluster_stats_messages_sent: 874
cluster_stats_messages_ping_received:446
cluster_stats_messages_pong_received:423
cluster_stats_messages_meet_received:5
cluster_stats_messages_received:874
192.168.3.243:7001> cluster nodes
4a54c721e2b38ee51cdd74f1a896d652c8f23981 192.168.3.243:7002@17002 master - 0 1521701466000 2 connected 5461-10922
e743fd8969a2a7f5db687fa51f0e420c8a5c4e7d 192.168.3.243:7004@17004 slave 5bcdfff3911c8991342c8edc36a384f231a102c3 0 1521701467962 4 connected
f9b69590139b1509a4b76a76a1603581309d9142 192.168.3.243:7006@17006 slave 4a54c721e2b38ee51cdd74f1a896d652c8f23981 0 1521701466000 6 connected
bbea0be24de5230b5f27cb3bf282813c4c2c9177 192.168.3.243:7005@17005 slave 8493eeca008f83c9a6e2d3a24509f18b0b8c6851 0 1521701467000 5 connected
Master 192.168.3.243:7003@17003 5bcdfff3911c8991342c8edc36a384f231a102c3 - 0 1521701466961 3 Connected 10923-16383
8493eeca008f83c9a6e2d3a24509f18b0b8c6851 192.168.3.243:7001@17001 myself, Master - 1 0 1,521,701,465,000 Connected 0-5460
192.168.3.243:7001>
We have really put Redis Cluster Setup The deployment is successful! The




problem is solved
when the gem install redis command is executed:
redis requires Ruby version >= 2.2.2 error, Centos supports ruby ​​to 2.0.0 by default, but gem install redis requires at least 2.2.2


1. Install RVM :
gpg2 --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3
curl -L get.rvm.io | bash -s stable
find / -name rvm -print
source /usr/local/rvm/scripts/ The rvm
result is as follows:
/usr/local/rvm 
/usr/local/rvm/src/rvm 
/usr/local/rvm/src/rvm/bin/rvm 
/usr/local/rvm/src/rvm/lib/rvm 
/usr/local/rvm/src/rvm/scripts/rvm 
/usr/local/rvm/bin/rvm 
/usr/local/rvm/lib/rvm 
/usr /local/rvm/scripts/rvm


2. Check the known ruby ​​versions in the rvm library
rvm list known
results are as follows:
MRI Rubies 
[ruby-]1.8.6[-p420] 
[ruby-]1.8.7[-head] # security released on head 
[ruby-]1.9.1[-p431] 
[ruby-]1.9.2[-p330] 
[ruby-]1.9.3[-p551] 
[ruby-]2.0.0[-p648] 
[ruby -]2.1[.10] 
[ruby-]2.2[.6] 
[ruby-]2.3[.3] 
[ruby-]2.4[.0] 
ruby-head 


3. Install a ruby ​​version
rvm use 2.3.3
4. use a ruby ​​version
rvm use 2.3.3
5. set default version
rvm use 2.3.3 --default
6. Uninstall a known version
rvm remove 2.0.0
7. Check ruby ​​version:
ruby ​​--version
8. Install redis:
gem install redis

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324952160&siteId=291194637