一、CentOS 7.0系統下的設置方法
假設Redis已經安裝,版本3.2.4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
#cd redis-3.2.4 #mkdir /etc/redis #cp redis.conf /etc/redis/6379.conf #cp utils/redis_init_script /etc/init.d/redis #chmod a+x /etc/init.d/redis #cp src/redis-server /usr/local/bin/ #cp src/redis-cli /usr/local/bin/ #vim /etc/init.d/redis |
在腳本文件添加 #chkconfig: 2345 80 90
否則會出現 “redis服務不支持chkconfig”的錯誤提示
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#!/bin/sh #chkconfig: 2345 80 90 # Simple Redis init.d script conceived to work on Linux systems # as it does use of the /proc filesystem. REDISPORT=6379 EXEC= /usr/local/bin/redis-server CLIEXEC= /usr/local/bin/redis-cli PIDFILE= /var/run/redis_ ${REDISPORT}.pid CONF= "/etc/redis/${REDISPORT}.conf" case "$1" 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 is 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
|
#chkconfig redis on |
啟動服務
1
|
#service redis start |
查看服務是否啟動
1
|
#lsof -i:6379 |
二、Debian 8.0設置方法
步驟與上面類似,不過Debian 用update-rc.d
(或insserv)代替chkconfig
腳本文件描述也不一樣。
假設Redis已經安裝,版本3.2.4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
#cd redis-3.2.4 #mkdir /etc/redis #cp redis.conf /etc/redis/6379.conf #cp utils/redis_init_script /etc/init.d/redis #chmod a+x /etc/init.d/redis #cp src/redis-server /usr/local/bin/ #cp src/redis-cli /usr/local/bin/ #vim /etc/init.d/redis |
在腳本文件添加
1
2
3
4
5
6
7
8
9
|
### BEGIN INIT INFO # Provides: redis6379 # Required-Start: $local_fs $network # Required-Stop: $local_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: redis6379 # Description: penavico redis 6379 ### END INIT INFO |
否則會出現 “ insserv: warning: script ‘redis6379′ missing LSB tags and overrides”
的錯誤提示
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
#!/bin/sh # # Simple Redis init.d script conceived to work on Linux systems # as it does use of the /proc filesystem. ### BEGIN INIT INFO # Provides: redis6379 # Required-Start: $local_fs $network # Required-Stop: $local_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: redis6379 # Description: penavico redis 6379 ### END INIT INFO REDISPORT=6379 EXEC= /usr/local/bin/redis-server CLIEXEC= /usr/local/bin/redis-cli PIDFILE= /var/run/redis_ ${REDISPORT}.pid CONF= "/etc/redis/${REDISPORT}.conf" case "$1" 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 is 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
|
#update-rc.d redisd defaults |
啟動服務
1
|
#service redis start |
查看服務是否啟動
1
|
#lsof -i:6379 |
開機啟動以后,默認的配置文件位置:/etc/redis/6379.conf
總結
以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對服務器之家的支持。