Linux下Nginx、PHP、MySQL、Redis开机自启动设置

一、Nginx开机启动设置

1、在/etc/init.d/目录下创建脚本

vi  /etc/init.d/nginx

2、更改脚本权限

chmod 775 /etc/init.d/nginx

3、编写脚本内容

#! /bin/sh
set -e
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
SCRIPTNAME=/etc/init.d/$NAME
PIDFILE=/var/run/$NAME.pid

# If the daemon file is not found, terminate the script.
test -x $DAEMON || exit 0

d_start() {
$DAEMON || echo -n " already running"
}

d_stop() {
kill -QUIT `cat $PIDFILE` || echo -n " not running"
}

d_reload() {
kill -HUP `cat $PIDFILE` || echo -n " could not reload"
}

case "$1" in
start)
echo -n "Starting $DESC: $NAME"
d_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
d_stop
echo "."
;;
reload)
echo -n "Reloading $DESC configuration..."
d_reload
echo "reloaded."
;;
restart)
echo -n "Restarting $DESC: $NAME"
d_stop
# Sleep for two seconds before starting again, this should give the
# Nginx daemon some time to perform a graceful stop.
sleep 2
d_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2
exit 3
;;
esac
exit 0

4、设置开机启动

  这里说明,Ubuntu 中系统没有了RH系统中的 chkconfig 命令 !

  可用一些小工具来管理 Ubuntu 的启动选项,rcconf:

  #sudo apt-get rcconf

  #sudo apt-get install rcconf

  root 下运行: #sudo rcconf

  功能更全的工具:sysv-rc-conf

  #sudo apt-get update

  #sudo apt-get install sysv-rc-conf

  运行:#sudo sysv-rc-conf

  也可以直接加入启动程序,例如把 /etc/init.d/red5 加入到系统自动启动列表中:

  #sudo sysv-rc-conf red5 on

  其他使用方法见: google::Ubuntu::sysv-rc-conf 命令用法

二、PHP开机启动设置

1、在/etc/init.d/目录下创建脚本

vi  /etc/init.d/php-fpm

2、更改脚本权限

chmod 775 /etc/init.d/php-fpm

3、编写脚本内容

#!/bin/sh
#
# php-fpm - this script starts and stops the php-fpm daemin
#
# chkconfig: - 85 15
# processname: php-fpm
# config:      /usr/local/php/etc/php-fpm.conf

set -e

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="php-fpm daemon"
NAME=php-fpm
DAEMON=/usr/local/php5.6/sbin/$NAME
CONFIGFILE=/usr/local/php5.6/etc/$NAME.conf
PIDFILE=/var/run/php-fpm5.pid
SCRIPTNAME=/etc/init.d/php-fpm5

# If the daemon file is not found, terminate the script.
test -x $DAEMON || exit 0

d_start(){
        $DAEMON -y $CONFIGFILE || echo -n " already running"
}

d_stop(){
        kill -QUIT `cat $PIDFILE` || echo -n " no running"
}

d_reload(){
        kill -HUP `cat $PIDFILE` || echo -n " could not reload"
}

case "$1" in
start)
echo -n "Starting $DESC: $NAME"
d_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
d_stop
echo "."
;;
reload)
echo -n "Reloading $DESC configuration..."
d_reload
echo "Reloaded."
;;
restart)
echo -n "Restarting $DESC: $NAME"
d_stop
# Sleep for two seconds before starting again, this should give the nginx daemon some time to perform a graceful stop
sleep 2
d_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload)" >&2
exit 3
;;
esac
exit 0

4、通过上面的自启动方法来设置。

三、MySQL开机启动设置

1、复制相关文件

  cp -a ./support-files/my-default.cnf  /etc/my.cnf

  cp -a ./support-files/mysql.server  /etc/init.d/mysqld

2、设置如上

四、Redis开机启动设置

1、在/etc/init.d/目录下创建脚本

vi  /etc/init.d/redis

2、更改脚本权限

chmod 775 /etc/init.d/redis

3、编写脚本内容

#!/bin/sh

# chkconfig: 2345 10 90
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli

PIDFILE=/var/run/redis.pid
CONF="/etc/redis.conf"

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 -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

4、通过上面的自启动方法来设置。

时间: 2024-10-28 07:13:57

Linux下Nginx、PHP、MySQL、Redis开机自启动设置的相关文章

linux下数据库实例监听开机自启动设置

linux下数据库实例监听开机自启动设置 2016/5/16 zhanky 脚本介绍 在开始之前,我们先介绍一下几个会用到的脚本. oratab oratab文件是在创建数据库实例时建立的,在安装时使用root用户执行root.sh脚本后得到.(如果忘记也可以直接手动创建.) 在$ORACLE_HOME/bin目录下的$ORACLE_HOME/bin/dbstart和$ORACLE_HOME/bin/dbshut需要调用/etc/oratab文件,如果不存在,dbstart和dbshut将失败,

Linux下Tomcat的搭建以及开机自启动设置

首先进行下JDK的配置: 1.查看下系统信息,确认是32位还是64位:uname -a 2.下载相应位数的jdk压缩包,传到Linux系统,这里提供一个32位和64位的下载链接:http://pan.baidu.com/s/1i5HXQex 密码:y0on 3.进入放置JDK压缩包的目录下,ls 查看文件 4.解压到/opt下:tar -zxvf 压缩包名 -C /opt/ 5.配置环境变量,修改etc下的profile文件:vim /etc/profile 定位到文档末尾:G 加上如下几行:

linux下nginx+php+mysql 自助环境搭建

++++++++++++++++++++++++++++++++++++++++++++++linux下nginx+php+mysql环境搭建++++++++++++++++++++++++++++++++++++++++++++++操作系统 : [CentOS6.0]服务器 : [nginx-1.1.8]PHP : [php-5.2.6]数据库 : [mysql-5.1.59]++++++++++++++++++++++++++++++++++++++++++++++准备安装软件(downlo

linux下nginx+php+mysql环境搭建

linux下nginx+php+mysql环境搭建 ++++++++++++++++++++++++++++++++++++++++++++++ 操作系统 : [CentOS6.0] 服务器 : [nginx-1.1.8] PHP : [php-5.2.6] 数据库 : [mysql-5.1.59] ++++++++++++++++++++++++++++++++++++++++++++++ 准备安装软件(download)  1>[nginx-1.1.8]       http://nginx

centos7系统下nginx安装并配置开机自启动操作

准备工作 我的centos7系统是最小化安装的, 缺很多库, 首先安装必须的运行库 ? 1 2 3 4 5 6 7 8 9 10 11 yum install wget gcc gcc-c++ pcre-devel zlib-devel ##创建工作目录并进入工作目录 mkdir -p /z/nginx && cd /z/nginx ##获取nginx最新的安装包 wget http://nginx.org/download/nginx-1.11.10.tar.gz ##解压缩 tar z

Linux下Nginx+PHP+Mysql环境搭建过程(图文)

一.使用yum命令,安装所需的程序库        1.命令内容                yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses

总结linux下 nginx,MySQL,PHP的安装过程

nginx的安装过程 1.先找到nginx的官网进去复制最新版本的下载地址在虚拟机上进行下载 wget http://nginx.org/download/nginx-1.16.0.tar.gz 2.把nginx压缩包解压到/usr/local/nginx/ tar -zxcf nginx-1.16.0.tar.gz -C /usr/local/nginx/ 3.下载他所需要的包 yum -y install gcc gcc-c++ autoconf automake make openssl

Linux下 C语言 Mysql操作和字符集设置

一.C语言 Mysql操作 首先安转libmysql库. # sudo apt-get install libmysql++-dev 把MySQL的库拷贝到公共库中. # sudo cp -ri /usr/lib/mysql/* /usr/lib/ 配置MySQL库. # mysql_config --cflags --libs 二.创建数据库和表 启动终端,输入以下命令,进入mysql. # mysql -u username -p 创建一个数据库. mysql > create databa

Ubuntu16设置Redis开机自启动

Ubuntu16设置Redis开机自启动 设置条件: -Ubuntu16.04 -Redis-4.0.11 在redis目录下找到  utils/redis_init_script  复制到 /etc/init.d/redis  打开文件进行修改 步骤:(主要Linux命令) whereis redis # 查找redis目录 sudo cp redis_init_script /etc/init.d/redis # 复制文件 cd /etc/init.d/ # 进入文件目录 sudo vim