启停脚本(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. JUC.Condition学习笔记

    目录 Condition的概念 大体实现流程 I.初始化状态 II.await()*作 III.signal()*作 3个主要方法 Condition的数据结构 线程何时阻塞和释放 await()方法 ...

  2. 二、FreeRTOS学习笔记-移植

    FreeRTOS移植 首先准备一个基础工程,stm32标准库或者HAL库,本实验使用HAL库版本的内存管理实验进行移植 移植步骤: 1 第一步:添加FreeRTOS源码(添加FreeRTOS源码的目的 ...

  3. golang之操作kafka

    安装第三方包: go get github.com/IBM/sarama 生产者实例: package main import ( "fmt" "github.com/I ...

  4. openEuler欧拉安装Gitlab

    1. 安装GitLab wget https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh sud ...

  5. 【单片机】I/O口实验

    要求:拨动开关,让所亮小灯位置左移或者右移 #include <STC8.H> #include <intrins.h> void delay(){ int i,j; for( ...

  6. 黑苹果(Hackintosh) - 问题,修改CPU数量和内存数量后,系统重启失败

    1. 问题复现 安装完黑苹果后,内存默认的 1个处理器2个核心.2G内存,发现不够用. 于是,修改了 VMware 对此系统的 硬件配置 内存: 2G -> 8G 处理器:1个处理器 -> ...

  7. Linux查找某个大小范围内的文件

    查找大小在某个范围内的文件使用-size参数,-size +n表示大于n单位的范围,-size –n表示小于n单位的范围.例如,查找大于100k且小于400k的文件: find . -type f - ...

  8. Python+Selenium自动搜索基金业协会指定企业名单,爬虫抓取指定信息并保存到数据库

    Python+Selenium自动搜索基金业协会指定企业名单,抓取指定信息并保存到数据库.网址https://gs.amac.org.cn/amac-infodisc/res/pof/manager/ ...

  9. Qt/C++开发经验小技巧301-305

    从Qt5.2版本开始,QLineEdit文本框控件提供了setClearButtonEnabled函数用于是否开启右侧的关闭按钮,这种控件非常常见,比如还可以增加个搜索按钮,怎么添加呢,在5.2版本以 ...

  10. Windows10 64环境下用Qt5.12.12自带的mingw730_64构建编译OpenCV4.1.0时cmake-3.20.6中的参数配置

    一.环境条件说明: 操作系统:Windows10 64环境 编译工具:用Qt5.12.12自带的mingw730_64构建 构建对象:编译OpenCV4.1.0的Release 64位和Debug 6 ...