安装后redis,默认系统不会自启动,如果关机或重启redis不会自行启动,linux下/etc/init.d/目录下基本上存放所有系统的大多数的启动脚本,放在这个目录下的脚本可以实现自启动操作。

在 /etc/init.d/目录下创建redis的shell文件

#!/bin/bash
#config:/usr/local/src/redis.conf
#pidfile:/var/run/redis.pid
source /etc/init.d/functions
BIN="/usr/local/bin"
REDIS_CONFIG="/usr/local/src/redis.conf"
PIDFILE="/var/run/redis.pid"
###Read configuration
[ -r "$SYSCONFIG" ] && source "$SYSCONFIG"
RETVAL=
prog="redis-server"
desc="Redis Server" start(){ if [ -e $PIDFILE ];then
echo "$desc already running...."
exit
fi echo -n $"starting $desc:" daemon $BIN/$prog $REDIS_CONFIG & RETVAL=$? echo [ $RETVAL -eq ] && touch /var/lock/subsys/$prog
return $RETVAL } stop(){
echo -n $"Stop $desc" killproc $prog
RETVAL=$?
echo [ $RETVAL -eq ] && rm -f /var/lock/subsys/$prog $PIDFILE return $RETVAL } restart(){
stop
start } case "$1" in start) start ;; stop) stop ;; restart) restart ;; status) status $prog RETVAL=$? ;; *) echo $"Usage:$0{start|stop|restart|condrestart|status}" RETVAL= esac
exit $RETVAL
service redis start

service redis stop

service redis restart

service redis status

都正常

将redis加入自启动计划

cd /etc/init.d/

chmod -R 775 redis

chkconfig --list|grep redis

添加启动计划到系统

[root@dongzi init.d]# chkconfig --add redis
service redis does not support chkconfi

再在脚本里面加入两行注释

# chkconfig: - 20 80
# description: Starts and stops the redis daemon.

运行正常

[root@dongzi init.d]# chkconfig --add redis
You have new mail in /var/spool/mail/root
[root@dongzi init.d]# chkconfig --list|grep redis
redis :off :off :off :off :off :off :off
You have new mail in /var/spool/mail/root
[root@dongzi init.d]# chkconfig --level redis on
[root@dongzi init.d]# chkconfig --list|grep redis
redis :off :off :on :on :on :on :off

shell编写redis启动脚本的更多相关文章

  1. Linux shell编写端口扫描脚本

    Linux shell编写端口扫描脚本 需求: 扫描特定主机 扫描特定主机的特定端口 扫描特定网段 扫描特定网段中哪些主机开放了特定的端口 源码如下: #/bin/bash #该脚本用于对特定目标主机 ...

  2. centos LNMP第一部分环境搭建 LAMP LNMP安装先后顺序 php安装 安装nginx 编写nginx启动脚本 懒汉模式 mv /usr/php/{p.conf.default,p.conf} php运行方式SAPI介绍 第二十三节课

    centos  LNMP第一部分环境搭建 LAMP安装先后顺序  LNMP安装先后顺序 php安装 安装nginx  编写nginx启动脚本   懒汉模式  mv   /usr/local/php/{ ...

  3. shell编写一个判断脚本

                                                              shell编写一个判断脚本 4.1问题 本例要求在虚拟机server0上创建/roo ...

  4. linux shell 之尝试编写 企业级 启动脚本

    企业Shell面试题10:开发企业级MySQL启动脚本 说明: MySQL启动命令为: 1 /bin/sh mysqld_safe --pid-file=$mysqld_pid_file_path 2 ...

  5. 自己编写服务启动脚本(一):functions文件详细分析和说明

    本文目录: 1.几个显示函数2.action函数3.is_true和is_false函数4.confirm函数5.pid检测相关函数 5.1 checkpid.__pids_var_run和__pid ...

  6. Ubuntu编写开机启动脚本

    1 概述 服务器一般不可能百分之百不会挂,于是一般采用主备或者分布式来达到高可用. 挂掉的机器有很多处理策略,常用的就是重新启动,但是为了保证重启之后服务器能够恢复可用状态,需要配置开机启动脚本. 2 ...

  7. redis启动脚本

    #!/bin/sh # # Simple Redis init.d script conceived to work on Linux systems # as it does use of the ...

  8. CentOS下的Redis启动脚本

    这是一个Shell脚本,用于管理Redis进程(启动,停止,重启),如果你在使用Redis,这个脚本可供参考. #!/bin/sh # # redis - this script starts and ...

  9. 026_编写 nginx 启动脚本

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

随机推荐

  1. 20145118 《Java程序设计》第5周学习总结 教材学习内容总结

    20145118 <Java程序设计>第5周学习总结 教材学习内容总结 1.Java中所有错误都会被打包成对象,可以通过try.catch语法对错误对象作处理,先执行try,如果出错则跳出 ...

  2. Android下拉刷新控件--PullToRefresh的简单使用

    Android中很多时候都会用到上下拉刷新,这是一个很常用的功能,Android的v4包中也为我们提供了一种原生的下拉刷新控件--SwipeRefreshLayout,可以用它实现一个简洁的刷新效果, ...

  3. codeforces 256 div2 C. Painting Fence 分治

    C. Painting Fence time limit per test 1 second memory limit per test 512 megabytes input standard in ...

  4. shell 使用ping测试网络

    能ping通返回1,不能返回0 ping -c 192.168.1.1 | grep '0 received' | wc -l

  5. PHP自定义XML类实现数组到XML文件的转换

    这两天在公司写和各应用商店应用内搜索的接口,大致就像百度应用内搜索这样的东西,具体可以点下面的链接查看. 百度应用内搜索 有的应用商店需要JSON格式的数据,所以我只需要用下面的语句就可以返回对方服务 ...

  6. Appium 自动化测试(7) -- Appium 服务器初始化参数设置

    Desired Capabilities Desired capabilities 是一些发送给 Appium 服务器的键值对集合 (比如 map 或 hash),告诉服务器我们想要启动什么类型的自动 ...

  7. UVA-11613 Acme Corporation (最大费用最大流+拆点)

    题目大意:有一种商品X,其每每单位存放一个月的代价I固定.并且已知其每月的最大生产量.生产每单位的的代价.最大销售量和销售单价,还已知每个月生产的X能最多能存放的时间(以月为单位).问只考虑前m个月, ...

  8. IOS-网络(文件压缩和解压缩)

    // // ViewController.m // IOS_0206_文件上传 // // Created by ma c on 16/2/6. // Copyright © 2016年 博文科技. ...

  9. 038——VUE中组件之WEB开发中组件使用场景与定义组件的方式

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. vue2 过渡动画

    <body> <div id="app"> <transition name="move"> // transition里面 ...