Linux中设置Redis开机启动的方法
程序员文章站
2022-06-24 18:33:29
一、centos 7.0系统下的设置方法
假设redis已经安装,版本3.2.4
#cd redis-3.2.4
#mkdir /etc/redis...
一、centos 7.0系统下的设置方法
假设redis已经安装,版本3.2.4
#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”的错误提示
#!/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
注册事件,开机启动
#chkconfig redis on
启动服务
#service redis start
查看服务是否启动
#lsof -i:6379
二、debian 8.0设置方法
步骤与上面类似,不过debian 用update-rc.d
(或insserv)代替chkconfig
脚本文件描述也不一样。
假设redis已经安装,版本3.2.4
#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
在脚本文件添加
### 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”
的错误提示
#!/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
注册事件,开机启动
#update-rc.d redisd defaults
启动服务
#service redis start
查看服务是否启动
#lsof -i:6379
开机启动以后,默认的配置文件位置:/etc/redis/6379.conf
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对的支持。
上一篇: Mac端安装.apk文件到安卓手机
下一篇: Android_OnClick点击事件