Overview
First report the version of my system:
Java code
- [Root@firefish init.d]# cat/etc/issue
The system version information is as follows:
Reference
CentOS Release 6.4 (Final)
Kernel \ r on an \m
Installing Redis
You want to install Redis under this directory:
Reference/usr/local/redis
Refer to the Http://redis.io/download installation instructions to make adjustments:
Reference
$ mkdir/usr/local/redis
$ cd/usr/local/src
$ wget http://redis.googlecode.com/files/redis-2.6.14.tar.gz
$ tar xzf redis-2.6.14.tar.gz
$ ln-s redis-2.6.14 Redis #建立一个链接
$ CD Redis
$ make Prefix=/usr/local/redis Install #安装到指定目录中
Note the last line above, we specified the installed directory through prefix. If make fails, it is common that GCC is not installed in your system and can be installed by Yum:
Java code
- Yum Install GCC
After the installation is complete, make is executed.
After you have successfully installed Redis, you will be able to see a bin directory in/usr/local/redis that includes the following files:
Java code
- Redis-benchmark redis-check-aof redis-check-dump redis-cli redis-server
Make Redis a service
1. Copy the script to the/ETC/RC.D/INIT.D directory
When you install Redis as per the above steps, its service script is located at:
Java code
- /usr/local/src/redis/utils/redis_init_script
It must be copied to the/ETC/RC.D/INIT.D directory:
Java code
- Cp/usr/local/src/redis/utils/redis_init_script/etc/rc.d/init.d/redis
The following copies the Redis_init_script to/etc/rc.d/init.d/and is easily named Redis.
If this is the case, we directly register the service:
Java code
- Chkconfig--add Redis
The following error will be reported:
Reference Redis service does not support Chkconfig
For some, we need to change the Redis script, see the next section for instructions.
2. Change the service script for Redis
Java code
- Vim/etc/rc.d/init.d/redis
See the following file contents:
Java code
- #!/bin/bash
- #chkconfig: 2345
- # simple Redis INIT.D script conceived to work on Linux systems
- # as it does use of the/proc filesystem.
- redisport=6379
- Exec=/usr/local/redis/bin/redis-server
- Cliexec=/usr/local/redis/bin/redis-cli
- Pidfile=/var/run/redis_${redisport}.pid
- conf="/etc/redis/${redisport}.conf"
- Case "$" in
- Start
- if [-F $PIDFILE]
- 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, process was not running"
- Else
- pid=$ (Cat $PIDFILE)
- echo "Stopping ..."
- $CLIEXEC-P $REDISPORT shutdown
- While [-x/proc/${pid}]
- Do
- echo "Waiting for Redis to shutdown ..."
- Sleep 1
- Done
- echo "Redis stopped"
- Fi
- ;;
- *)
- echo "Please use Start or stop as first argument"
- ;;
- Esac
1) Troubleshoot issues that cannot be registered:
The original file does not have the contents of line 2nd below,
Reference #chkconfig:2345 80 90
If the registration will be an error, to add re-registration is OK.
2) Change the exec, cliexec parameter, set the corresponding value, as shown above is consistent with our previous installation.
3) Change the Redis Open command to run in the background:
Java code
- $EXEC $CONF &
Notice that the "&" in the back is the meaning of moving the service to the back, or when the service is started, the Redis service will
Occupy the front desk, occupying the main user interface, resulting in other commands not being executed.
4) Copy the Redis configuration file to/etc/redis/${redisport}.conf
Java code
- Mkdir/etc/redis
- cp/usr/local/src/redis/redis.conf/etc/redis/6379.conf
In this way, the conf specified by the Redis service script exists. By default, Redis does not have authentication enabled, and you can specify a verification password by turning on the requirepass of 6379.conf.
Once the above operation is complete, you can register the service:
Java code
- Chkconfig--add Redis
3. Start the Redis service
Java code
- $ service Redis Start
Add the directory of the Redis command to the system parameter path
To modify a profile:
#vi/etc/profile
In the last line add:
Java code
- Export path="$PATH:/usr/local/redis/bin"
Then apply this file immediately:
Java code
- . /etc/profile
This makes it possible to invoke the REDIS-CLI command directly, as follows:
Java code
- $ redis-cli
- Redis 127.0. 0.1:6379> auth Superman
- Ok
- Redis 127.0. 0.1:6379> ping
- PONG
- Redis 127.0. 0.1:6379>
Because I turned on the security authentication feature above, the password is Superman, so I need to auth to interact with the server.
< finish >
Installing the Redis complete process