CenterOS 中安装Redis及开机启动设置详解
程序员文章站
2023-02-14 16:42:04
centeros 中安装redis及开机启动设置详解
从官方下载最新redis进行安装,官网地址:http://redis.io/download
$ wget...
centeros 中安装redis及开机启动设置详解
从官方下载最新redis进行安装,官网地址:http://redis.io/download
$ wget http://download.redis.io/releases/redis-3.2.3.tar.gz $ tar xzf redis-3.2.3.tar.gz $ cd redis-3.2.3 $ make $ make install
redis启动
redisserver /path/to/redis.conf
redis关闭(默认port为6379)
rediscli -p port -a password shutdown
查看reids进程
ps -ef|grep redis
设置redis开机启动
1:配置init脚本,把代码存为reids,放到/etc/init.d/
########################### # chkconfig: 2345 90 10 # description: redis is a persistent key-value database path=/usr/local/bin redisport=6379 exec=/usr/local/bin/redis-server redis_cli=/usr/local/bin/redis-cli #redis密码 password=yourpassword pidfile=/var/run/redis.pid conf="/usr/local/reids/conf/redis.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 if [ "$?"="0" ] then echo "redis is running..." fi ;; stop) if [ ! -f $pidfile ] then echo "$pidfile does not exist, process is not running" else pid=$(cat $pidfile) echo "stopping ..." $redis_cli -p $redisport -a $password shutdown while [ -x ${pidfile} ] do echo "waiting for redis to shutdown ..." sleep 1 done echo "redis stopped" fi ;; restart|force-reload) ${0} stop ${0} start ;; *) echo "usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2 exit 1 esac ##############################
注意事项:
1) 最上面的注释的意思是,redis服务必须在运行级2,3,4,5下被启动或关闭,启动的优先级是90,关闭的优先级是10。
2) 如果执行命令出现$'/r':command not found,这个问题是在windows下换行和linux下换行不同,可以通过nodepad++进行转换。
2:设置脚本权限
chmod +x /etc/init.d/redis
3:设置开机启动
sudo chkconfig redis on
4:使用方法
service redis start #或者 /etc/init.d/redis start service redis stop #或者 /etc/init.d/redis stop
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
上一篇: 在减脂怎么吃最合适
下一篇: CentOS下MySQL安装详细步骤