有感:
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)自己定义启动文件并配置(推荐)
[[email protected] ~]# cpredis-2.8.24/utils/redis_init_script /etc/init.d/redis
注册为系统服务:
[[email protected] ~]# sed -i ‘2i #chkconfig:2345 80 90‘ /etc/init.d/redis
[[email protected] ~]# 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状态,启动,关闭,重启
[[email protected] ~]# /etc/init.d/redis status Redis is running... [[email protected] ~]# /etc/init.d/redis stop Waiting for Redis to stop ... Waiting for Redis to shutdown ... Redis is already stopped successfully! [[email protected] ~]# /etc/init.d/redis start Waiting for Redis to start... Redis is already started successfully! [[email protected] ~]# /etc/init.d/redis restart Redis is already stopped successfully! Redis is already started successfully! [[email protected] ~]# [[email protected] ~]# 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 [[email protected] ~]#
时间: 2024-12-18 22:28:52