I. Installation of Redis
Redis installation is actually quite simple, the recommended way is to download the Redis source code, and after the installation of the machine compiled.
First access to the home folder download directory, the implementation of wget download source code
[zhxilin@localhost ~]$ cd download
[zhxilin@localhost download]$ wget http://download.redis.io/redis-stable.tar.gz
Next unpack, move to the/usr/redis directory
[ZHXILIN@LOCALHOST download]$ tar-zxvf redis-stable.tar.gz
[zhxilin@localhost download]$ su mv Redis-stable/usr/redis
Then enter the Redis directory, execute make command, compile Redis source
[ROOT@LOCALHOST download]# cd/usr/redis/
[root@localhost redis]# make
After compiling, there are 2 important programs generated in the SRC directory, one is redis-server
, the other is, redis-cli
then enter the src directory, execute make install
, then copy these executable programs to the /usr/local/bin
directory, because /usr/local/bin
it is defined in the system's environment variable $path, So the terminal can be executed in any redis-server
position redis-cli
.
[root@localhost redis]# cd src/
[root@localhost src]# make install
The work on installing Redis is complete.
Let's take a look at some of the compiled programs:
redis-server
: As the name suggests, Redis service
redis-cli
: Redis client, to provide a Redis clients to connect to Redis services, to carry out screening and other operations
redis-sentinel
: redis instance monitoring management, notification and instance fail-Aid services
redis-benchmark
: Redis's performance testing tool
redis-check-aof
: If the log is generated in a aof manner, it is used for quick fixes when the accident occurs
redis-check-rdb
: If the log is generated in a rdb manner, it is used for quick fixes when the accident occurs
After the installation is complete, start and redis-server
run the redis-cli
test
[Zhxilin@localhost ~]$ Redis-server
[Zhxilin@localhost ~]$ redis-cli
127.0.0.1:6379> PING
PONG
This indicates that the Redis service is working properly and that the runtime redis-cli
will report an error if the Redis service is not started Could not connect to Redis at 127.0.0.1:6379: Connection refused
.
Two. Configure Self-startup
In order for Redis-server to run automatically when the system is started, the Redis service needs to be run as a daemon (daemon), and we go back to /usr/redis/
the directory to find a redis.conf
file that is the configuration that the Redis service loads at runtime. Let's look at the contents first.
The contents of this file are very long, but most of them are annotations, and we focus on several of these settings daemonize
and pidfile
:
Where the daemonize
default value is False and the pidfile
default value ispidfile /var/run/redis_6379.pid
The first one says whether it is daemon, obviously we have to change it daemonize yes
;
The second means that when the service is running as a daemon, Redis writes the PID to the file by default, the /var/run/redis_6379.pid
file exists in the service run, and the service is automatically deleted when the file is stopped, so it can be used to determine if the Redis is running.
Exit after saving.
With the basic configuration, Redis also needs to have a script that manages startup, shutdown, and restart. Redis source code In fact has provided an initialization script, located in /usr/redis/utils/redis_init_script
.
Let's take a look at what this script does:
#!/bin/sh# redisport=6379 Exec=/usr/local/bin/redis-server REDIS-CLI pidfile=/var/run/redis_${redisport}.pid conf= "/etc/redis/${redisport}.conf" case "in Start" if [-f $PI Dfile] then echo "$PIDFILE exists, process is already running or crashed" else echo "starting Redis server ...
."
$EXEC $CONF fi;; STOP) if [! f $PIDFILE] then echo "$PIDFILE does not exist, the process is not running" else pid=$ (cat $PIDFI LE) echo "Stopping ..." $CLIEXEC-p $REDISPORT shutdown while [-x/proc/${pid}] do echo waiting fo
R Redis to shutdown ... "Sleep 1 do echo" Redis stopped "FI;;
*) echo "Please use start or stop as the" "argument";; Esac
The script specifies the port, the server path, the CLI path, the Pidfile path, and the Conf path, all of which need to be properly configured, and if executed at installation time, make install
the script here does not require much change because make install
Copy the server and CLI to the /usr/local/bin
bottom.
In addition to see the path here conf, we need to Redis directory of redis.conf files to copy to/etc/redis/6379.conf
[Root@localhost utils]# cd/etc
[root@localhost etc]# mkdir
Then redis_init_script
copy the script to the/etc/init.d/redisd
The scripts under/ETC/INIT.D are services that can be started automatically at system startup, and there is now a system startup configuration:
[Root@localhost zhxilin]# chkconfig REDISD on
Then you'll find a mistake: Does the service REDISD not support Chkconfig?
This is because we need to redis_init_script
add a small change to the beginning:
#!/bin/sh
# chkconfig:2345 Description:redis is
a persistent key-value database
After the copy is saved /etc/init.d/redisd
, the operation chkconfig
is complete.
When you are ready, you can perform the following command to verify that the service is set up successfully:
[root@localhost zhxilin]# service REDISD start
[root@localhost zhxilin]# service REDISD stop
Equivalent to
[Root@localhost zhxilin]#/ETC/INIT.D/REDISD start
[root@localhost zhxilin]#/ETC/INIT.D/REDISD Stop
Summarize
Finally restart the system, after entering the system directly run REDIS-CLI Test Redis service has been automatically run. The above is the entire content of this article, I hope the content of this article for everyone's study or work can bring certain help, if you have questions you can message exchange.