Redis的多种启动方式比较!
有感:
创新互联公司网站建设提供从项目策划、软件开发,软件安全维护、网站优化(SEO)、网站分析、效果评估等整套的建站服务,主营业务为成都网站制作、网站建设、外贸网站建设,app软件定制开发以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。创新互联公司深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!
redis玩了许久时间,真心感觉启动方式还是自己定义的方便!
1)直接启动和关闭:(配置文件默认)
开启:redis-server &(&后台运行)
#daemonize yes(也可配置文件修改此参数)
关闭:redis-cli shutdown or killall -9 redis-server
2)指定配置文件启动:
redis-server /etc/redis.conf(配置文件可自己定义)
如果更改了redis默认端口:
redis-cli shutdown (-p端口)
redis-cli shutdown (-p 端口) (-a 认证密码)
3)自己定义启动文件并配置(推荐)
[root@redis1 ~]# cpredis-2.8.24/utils/redis_init_script /etc/init.d/redis
注册为系统服务:
[root@redis1 ~]# sed -i '2i #chkconfig:2345 80 90' /etc/init.d/redis
[root@redis1 ~]# chkconfig --add redis
修改配置文件(因为路径自己定义,sed也可以)
REDISPORT=7000 #注意slave端口自己定义即可
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"
脚本如下(自己配置的,大家也可在此基础上进行修改)
#!/bin/sh #chkconfig: 2345 80 90 # Simple Redis init.d script conceivedto work on Linux systems # as it does use of the /procfilesystem. REDISPORT=7000 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 "$1" in start) if [ -f $PIDFILE ] then echo -e "\033[31m $PIDFILEexists, process is already running or crashed \033[0m" else echo -e "\033[32m Waitingfor Redis to start...\033[0m" $EXEC $CONF if [ $? -eq 0 ] then echo -e "\033[32m Redis isalready started successfully! \033[0m" else echo -e "\033[31m Redisstart fail \033[0m" fi fi ;; stop) if [ ! -f $PIDFILE ] then echo -e "\033[31m $PIDFILEdoes not exist, process is not running \033[0m" else PID=$(cat $PIDFILE) echo -e "\033[32m Waitingfor Redis to stop ... \033[0m" $CLIEXEC -p $REDISPORT shutdown while [ -x /proc/${PID} ] do echo -e "\033[32mWaiting for Redis to shutdown ... \033[0m" sleep 1 done echo -e "\033[32m Redis isalready stopped successfully! \033[0m" fi ;; status) ps aux|grep redis-server|grep-v grep &>/dev/null if [ $? -eq 0 ] then echo -e "\033[32m Redisis running... \033[0m" else echo -e "\033[31m Redisis already stopped \033[0m" fi ;; restart) $CLIEXEC -p $REDISPORT shutdown if [ $? -eq 0 ] then echo -e "\033[32m Redis isalready stopped successfully! \033[0m" else echo -e "\033[31m Redisstop fail \033[0m" fi $EXEC $CONF if [ $? -eq 0 ] then echo -e "\033[32m Redis isalready started successfully! \033[0m" else echo -e "\033[31m Redisstart fail \033[0m" fi ;; *) echo "the usage is service redis start|stop|status|restart" esac
查看redis状态,启动,关闭,重启
[root@redis1 ~]# /etc/init.d/redis status Redis is running... [root@redis1 ~]# /etc/init.d/redis stop Waiting for Redis to stop ... Waiting for Redis to shutdown ... Redis is already stopped successfully! [root@redis1 ~]# /etc/init.d/redis start Waiting for Redis to start... Redis is already started successfully! [root@redis1 ~]# /etc/init.d/redis restart Redis is already stopped successfully! Redis is already started successfully! [root@redis1 ~]# [root@redis1 ~]# ps aux|grep redis-server|grep -v grep root 2881 0.1 0.1 128296 1692 ? Ssl 12:45 0:01 /usr/local/redis/bin/redis-server *:7000 [root@redis1 ~]#
新闻标题:Redis的多种启动方式比较!
新闻来源:http://azwzsj.com/article/gihoco.html