安装后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. POJ 1797 Heavy Transportation(最短路&Dijkstra变体)题解

    题意:给你所有道路的载重,找出从1走到n的所有路径中载重最大的,即路径最小值的最大值. 思路:和之前的POJ3268很像.我们用Dijkstra,在每次查找时,我们把最大的先拿出来,因为最大的不影响最 ...

  2. The P4 Language Specification v1.0.2 Introduction部分

    Introduction P4 is a declarative language for expressing how packets are processed by the pipeline o ...

  3. Codeforces Round #278 (Div. 2) D. Strip 线段树优化dp

    D. Strip time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...

  4. nginx.conf 配置详解

    目录 pid user error_log worker_connections include http server nginx主配置文件中的内容 pid 主线程id的存储位置. # cat /u ...

  5. Java回顾之网络通信

    在这篇文章里,我们主要讨论如何使用Java实现网络通信,包括TCP通信.UDP通信.多播以及NIO. TCP连接 TCP的基础是Socket,在TCP连接中,我们会使用ServerSocket和Soc ...

  6. JavaScript Number() Vs new Number()

    最近在优化一个页面时候.IDEA 提示我错误的使用了包装类.当时感觉很诧异. 随后.我上Stack Overflow上面查了一下,终于发现了问题所在. new Number('123') 与 Numb ...

  7. express 调优的一个过程和心得,不错的文章

    Netflix的软件工程师Yunong Xiao最近在公司的技术博客上写了一篇文章,分析了他所在的团队在将Netflix网站UI转移到Node.js上时遇到的延迟问题.在文章中他描述了找到问题根本原因 ...

  8. 爱奇艺vip视频免费看

    代码: <html> <meta charset="utf-8" /> <head> <script> var num = 0; v ...

  9. 利用Pandoc将markdown文件转化为pdf

    利用Pandoc将markdown文件转化为pdf 准备工作 安装pandoc 安装MiKTeX 将markdown文件转换为pdf 准备工作 安装pandoc Windows下安装pandoc很容易 ...

  10. git 忽略不提交的文件3种情形

    1..gitignore文件 :从未提交过的文件,从来没有被 Git 记录过的文件 也就是添加之后从来没有提交(commit)过的文件,可以使用.gitignore忽略该文件.只能作用于未跟踪的文件( ...