java中的接口是类吗
451
2022-10-28
Redis的多种启动方式比较!
有感:
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 ~]#
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~