Environment: CentOS 6.6
Redis version: redis-3.0
Installation directory: /usr/local/redis User: root
Compile and install the required packages :
# yum install gcc tcl
Download Redis version 3.0 ( the latest version of redis-3.0.0-rc5.tar.gz, please choose the latest version when installing ) # cd /usr/local/src
# wget https://github.com/antirez/redis/archive/3.0.0-rc5.tar.gz
Create the installation directory:
# mkdir /usr/local/redis
Unzip :
# tar -zxvf 3.0.0-rc5.tar.gz # mv redis-3.0.0-rc5 redis3.0 # cd redis3.0
Installation (use PREFIX to specify the installation directory ):
# make PREFIX=/usr/local/redis install
After the installation is complete, you can see that there is a bin directory in the /usr/local/redis directory, and the bin directory is the command script of redis: redis -benchmark redis-check-aof redis-check-dump redis-cli redis-server
Configure Redis as a service :
According to the above steps, the startup script of Redis is: /usr/local/src/redis3.0/utils/redis_init_script Copy the startup script to the /etc/rc.d/init.d/ directory and name it redis :
# cp /usr/local/src/redis3.0/utils/redis_init_script /etc/rc.d/init.d/redis Edit /etc/rc.d/init.d/redis, modify the corresponding configuration so that it can be registered Become a service:
# vi /etc/rc.d/init.d/redis
View the above redis service script, pay attention to the properties marked in orange, and prepare for the following modifications:
(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/bin/redis-server
(4) CLIEXEC=/usr/local/bin/redis-cli改为CLIEXEC=/usr/local/redis/bin/redis-cli
(5) Profile settings:
Create the redis configuration file directory
# mkdir /usr/local/redis/conf
Copy the redis configuration file /usr/local/src/redis3.0/redis.conf to the /usr/local/redis/conf directory and rename it to 6379.conf by port number
# cp /usr/local/src/redis3.0/redis.conf /usr/local/redis/conf/6379.conf After making the above preparations, adjust the CONF properties as follows:
CONF="/etc/redis/${REDISPORT}.conf" 改为 CONF="/usr/local/redis/conf/${REDISPORT}.conf"
(6) Change the command opened by redis and execute it in the background :
$EXEC $CONF & #"&" function is to transfer the service to the back to run
The content of the modified /etc/rc.d/init.d/redis service script is:
After the above configuration operations are completed, Redis can be registered as a service: # chkconfig --add redis
Open the corresponding port in the firewall
# vi /etc/sysconfig/iptables add:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 6379 -j ACCEPT Restart the firewall:
# service iptables restart
Modify the redis configuration file settings:
# vi /usr/local/redis/conf/6379.conf Modify the following configuration
daemonize no to > daemonize yes
pidfile /var/run/redis.pid changed to > pidfile /var/run/redis_6379.pid
Start the Redis service
# service redis start
Add Redis to environment variables: # vi /etc/profile
Add the following at the end: ## Redis env
export PATH=$PATH:/usr/local/redis/bin to make the configuration take effect:
# source /etc/profile
Now you can use redis commands such as redis-cli directly:
Shut down the Redis service
# service redis stop
By default, Redis enables security authentication. You can specify an authentication password through requirepass in /usr/local/redis/conf/6379.conf .