Redis3.X compilation and installation

1. Download the latest redis compressed package through wget or upload the existing package to the linux server. Storage directory: /usr/local/src      

2. Unzip the installation package and rename the unzipped directory name

-- Enter the directory where the compressed package is located

cd /usr/local/src

--unzip

tar -zxvf redis-3.2.8.tar.gz

--rename (directory name redis3)

mv redis-3.2.8 redis3

-- Enter the redis3 directory

cd redis3

3. Compile and install redis

--install dependencies (optional)

yum -y install gcc tcl gcc-c++

--Clear the files generated by the previous compilation and installation (optional)

make distclean

--create installation directory

mkdir /usr/local/redis_master

--Compile and install (install to the specified directory, the parameter PREFIX must be uppercase)

make PREFIX=/usr/local/redis_master install

--View the directory structure after installation 


Note, the installation fails, please check whether the dependencies are installed: yum install gcc tcl

4. Redis service startup

--copy startup script

cp /usr/local/src/redis3/utils/redis_init_script /etc/rc.d/redis

or

cp /usr/local/src/redis3/utils/redis_init_script /etc/rc.d/init.d/redis

Depends on your system!

--Edit the startup script and modify the following items

(1) Add a line after the first line of the script as follows:

 #chkconfig: 2345 80 90

(If the above content is not added, it will prompt when registering the service: service redis does not support chkconfig)

(2) The REDISPORT port remains unchanged at 6379; (note that the port name will be related to the configuration file name below)

(3)EXEC=/usr/local/bin/redis-server改为EXEC=/usr/local/redis_master/bin/redis-server

(4)CLIEXEC=/usr/local/bin/redis-cli改为CLIEXEC=/usr/local/redis_master/bin/redis-cli

(5)CONF="/etc/redis/${REDISPORT}.conf"改为CONF="/usr/local/redis_master/conf/${REDISPORT}.conf"

(6) $EXEC $CONF is changed to  $EXEC $CONF &, that is, the background running process

The complete configuration is as follows: 


 

5. Redis startup configuration file

--Create a directory to store configuration files
 mkdir /usr/local/redis _master /conf

 --Copy and rename the config file

cp /usr/local/src/redis3/redis.conf /usr/local/redis_master/conf/6379.conf

-- modify the configuration file

vi /usr/local/redis_master/conf/6379.conf

(1) Change daemonize no to >daemonize yes, run the program in the background, and do not display the startup interface

(2) Make sure that the pidfile /var/run/redis_6379.pid is the same as the full path of the pid file in the startup script

(3) logfile "/usr/local/redis_master/logs/redis.log", the absolute path of the log file

(4) maxmemory 3GB, configure the maximum memory, the recommended maximum is half of the physical memory

6. Other matters

--Add new services, and start automatically at boot

chkconfig --add redis

chkconfig redis on

--Enable firewall whitelist

vi /etc/sysconfig/iptables

Add configuration: -A INPUT -m state --state NEW -m tcp -p tcp --dport 6379 -j ACCEPT

-- restart firewall

service iptables restart

-- Append redis related commands to environment variables

vi /etc/profile

Add the following at the end:

##Redis_ENV

export PATH=$PATH:/usr/local/redis_master/bin

To make the configuration take effect:

# source /etc/profile

7. Execute scripts using commands to enable or disable services

service redis start|stop

8. Notes on redis configuration files

(1), 6379.conf configure the bind option, you need to configure the specific IP of the server, otherwise the application may be refused connection

        bind 10.0.0.100 127.0.0.1 ::1

        If the test environment wants to allow all IP access, it can be configured as: bind 0.0.0.0

(2), configure the authentication authority

        requirepass 123456

        The stop command that needs to modify the startup script is: $CLIEXEC -p $REDISPORT -a 123456 shutdown

(3), the difference between the startup script [ $EXEC $CONF & ] and the configuration file [ daemonize yes ]

   a. & in the script means background running process

   b. The configuration file yes means that the startup interface is not displayed. If the value is yes, it does not matter whether the & The service will not stop, otherwise the service will stop

 

 

Guess you like

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