启停脚本(redis-5.0.5)

一、编辑脚本

vim /u01/redis/redisServer.sh

#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem. ### BEGIN INIT INFO
# Provides: redis_6379
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Redis data structure server
# Description: Redis data structure server. See https://redis.io
### END INIT INFO REDISPORT=6379
EXEC=/u01/redis/src/redis-server
CLIEXEC=/u01/redis/src/redis-cli PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/u01/redis/redis.conf"
PWD=`cat $CONF | grep ^requirepass|awk '{print $2}'` 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
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -a $PWD -p $REDISPORT shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
*)
echo "Please use start or stop as first argument"
;;
esac

二、开机启动

[root@localhost redis]# cp /u01/redis/redis.sh /etc/init.d/redis
[root@localhost redis]# chkconfig --add redis
[root@localhost redis]# systemctl start redis


https://www.cnblogs.com/houchaoying/p/13031041.html

三、使用systemV启动方法

编写启动脚本

vim /lib/systemd/system/redis.service

[Unit]
Description=Redis
After=network.target
[Service]
Type=forking
PIDFile=/var/run/redis_6379.pid
ExecStart=/opt/redis6/bin/redis-server /opt/redis6/bin/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target

四、开机启动

使用systemctl命令
# 重载服务
systemctl daemon-reload
# 开机自启
systemctl enable redis
# 启动
systemctl start redis
# 重启
systemctl restart redis    
# 停止
systemctl stop redis
# 查看状态
systemctl status redis
# 关闭开机启动
systemctl disable redis

redis启停shell脚本的更多相关文章

  1. 编写Redis启停服务脚本

    脚本内容如下; fi   esac   exit$RETVAL 下载脚本:艺搜下载 将下载下来的脚本放在/etc/init.d/目录下 更改脚本权限 chmod 777 /etc/init.d/red ...

  2. nginx启停shell脚本

    #!/bin/bash # 编写 nginx 启动脚本 # 本脚本编写完成后,放置在/etc/init.d/目录下,就可以被 Linux 系统自动识别到该脚本 # 如果本脚本名为/etc/init.d ...

  3. Redis windows版本的启停bat脚本命令

    Reids windows版本安装 redis windows官网推荐:https://github.com/MicrosoftArchive/redis/releases 下载解压即可. 启停bat ...

  4. 获取redis主从复制链SHELL脚本

    获取redis主从复制链SHELL脚本 vi redisnode.sh #!/bin/sh master_host=$ master_port=$ auth=$ #判断输入密码是否为空,为空则转化为' ...

  5. shell启停服务脚本模板

    一. 启动脚本模板:符合幂等性 如果该服务已经启动,再次调用该脚本,不会报错,也就是说可以反复多次调用,另外启动成功返回 一个参数,提供给自动发布平台校验该服务是否启动 #!/bin/bash ins ...

  6. 编写Nginx启停服务脚本

    在/etc/init.d/目录下创建脚本 vim /etc/init.d/nginx 编写脚本内容:(其中下面2行需要根据情况自行修改) nginxd=/opt/nginx/sbin/nginx ng ...

  7. redis启停

    1 查看服务器上启动的redis服务 开了两个redis单机服务,监听在两个端口. 开了一个集群,监听在6个端口. [root@localhost bin]# ps aux | grep redis ...

  8. centos下的redis一键安装shell脚本

    #!/bin/bash yum install cpp binutils glibc-kernheaders glibc-common glibc-devel gcc make wget #安装依赖库 ...

  9. 数据库MySQL、redis主从切换shell脚本

    具体源码可找我领取

  10. 04. 启停redis服务

    启动 查看redis.conf文件,可以通过general中的说明,配置通过systemd来启停redis和查看redis状态(作者没有采用,而是使用service管理,service配置参考< ...

随机推荐

  1. Golang之常用方法[总结]

    1. 有一堆数字,如果除了一个数字以外,其他数字都出现了两次,那么如何找到出现一次的数字? nums := []int{1, 5, 1, 6, 5, 3, 6} i := 0 for _, v := ...

  2. API之接口服务

    聚合数据: https://www.juhe.cn/ 百度api市场: https://apis.baidu.com/

  3. 理解Flink之一编译Flink-1.11.1

    下载源码 git clone -b release-1.11.1 https://github.com/apache/flink.git --depth=1 flink-1.11.1 编译 mvn c ...

  4. 从零开始学java(第二天)

    ------------恢复内容开始------------ 今天是学习了一些基础的知识 1.注释 //行注释 /*多行注释*/ /**文档注释*/ 2.标识符和关键字 标识符就是名字,类名方法名变量 ...

  5. Java8 Lambda编程常用技巧

    遍历打印List List<Integer> list= Arrays.asList(1,5,6,8,9,32,5,8,7,4,5); list.forEach(System.out::p ...

  6. 生产环境BigDecimal用错了,已哭晕在厕所。。。

    大家好,我是苏三,又跟大家见面了. 前言 在日常开发中,很多小伙伴喜欢用 BigDecimal 来处理精确计算,比如钱.分数.比例啥的. 理论上,它比 double 或 float 更精确,但如果你用 ...

  7. 基于 .NET 的 Nuget 发版工具

    背景 由于 Natasha 及周边项目发版任务多,文件结构也不简单,之前一直使用基于 Github 管道脚本和 XUnit 来发版.这个方案对于发版环境与条件依赖性较强,且不够灵活,因此萌生出做一个本 ...

  8. StreamJsonRpc.ConnectionLostException 在请求完成之前, 与远程方的 JSON-RPC 连接已丢失

    今天电脑重启之后,发现 visual studio 2022 的智能提示与报错经常性不好用,不光不能在正常时候提示代码错误信息,甚至在编译过后也不提示错误.反复重启,刚开始正常,隔一会儿就会提示什么什 ...

  9. mysql:sql create database新建utf8mb4 数据库

    create database sina default character set utf8mb4 collate utf8mb4_unicode_ci;或者是create database con ...

  10. 龙哥量化:缠论的笔、线段、中枢以及MACD背离分析实现

    声明:看到研究非常细致深入的文章,转载到我的博客园,以便学习和研究. (转载自聚宽的大象咖啡) 本文参考了如下相关文贴: [量化缠论]之分型.笔.线段识别1.1. 在该帖的基础上将线段和调整后的k线绘 ...