Centos Redis 安装配置和启动脚本
Redis管理脚本在Centos上使用之前,需要先配置下面的内核参数,否则Redis脚本在重启或停止redis时,将会报错,并且不能自动在停止服务前同步数据到磁盘上。
redis 源码: https://github.com/antirez/redis
redis 官方: https://redis.io
redis 最新: redis-4.0.10.tar.gz (2018.6.13)
redis 安装配置:
tar zxvf redis-4.0.10.tar.gz
cd redis-4.0.10
make && make install
1. 配置内核参数
# vi /etc/sysctl.conf
vm.overcommit_memory = 1
然后应用生效:
# sysctl -p
2. 添加Redis启动脚本
vim /etc/init.d/redis
#!/bin/bash # # Init file for redis # # chkconfig: - 80 12 # description: redis daemon # author: www.mimvp.com # # vim /etc/init.d/redis # # processname: redis # BIN="/usr/local/bin" # CONFIG: /etc/redis.conf # PIDFILE: /var/run/redis.pid source /etc/init.d/functions BIN="/usr/local/bin" CONFIG="/etc/redis.conf" PIDFILE="/var/run/redis.pid" ### Read configuration [ -r "$SYSCONFIG" ] && source "$SYSCONFIG" RETVAL=0 prog="redis-server" desc="Redis Server" start() { if [ -e $PIDFILE ];then echo "$desc already running...." exit 1 fi echo -n $"Starting $desc: " daemon $BIN/$prog $CONFIG RETVAL=$? echo [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog return $RETVAL } stop() { echo -n $"Stop $desc: " killproc $prog RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog $PIDFILE return $RETVAL } restart() { stop start } case "$1" in start) start ;; stop) stop ;; restart) restart ;; condrestart) [ -e /var/lock/subsys/$prog ] && restart RETVAL=$? ;; status) status $prog RETVAL=$? ;; *) echo $"Usage: $0 {start|stop|restart|condrestart|status}" RETVAL=1 esac exit $RETVAL
添加可执行权限:
chmod +x /etc/init.d/redis
3. 增加开机自启动:
# chmod 755 /etc/init.d/redis
# chkconfig --add redis
# chkconfig --level 345 redis on
# chkconfig --list redis
[root@mimvp-hz ~]# chkconfig --list redis
redis 0:off 1:off 2:on 3:on 4:on 5:on 6:off
参考推荐:
版权所有: 本文系米扑博客原创、转载、摘录,或修订后发表,最后更新于 2018-07-23 15:59:36
侵权处理: 本个人博客,不盈利,若侵犯了您的作品权,请联系博主删除,莫恶意,索钱财,感谢!