Nginx 离线安装,基于centos7 --^_^-- Linux服务启动脚本范例

〇、下载离线软件包

离线包 下载 点这里

或者自己手动去下载:

  1. 下载nginx:  http://nginx.org/download/nginx-1.17.2.tar.gz
  2. 下载openssl:  https://www.openssl.org/source/openssl-fips-2.0.10.tar.gz
  3. 下载zlib:  http://zlib.net/zlib-1.2.11.tar.gz
  4. 下载pcre: http://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz

一、上传离线软件包

mkdir -p /usr/local/nginx/

将以上四个离线包上传到 此 

二、安装

1.安装openssl

cd /usr/local/nginx                
tar -zxvf openssl-fips-2.0.10.tar.gz                 
cd openssl-fips-2.0.10            
./config && make && make install                       

 2.安装pcre

cd /usr/local/nginx                 
tar -zxvf pcre-8.43.tar.gz                    
cd pcre-8.43                
./configure && make && make install                

3.安装zlib

cd /usr/local/nginx                 
tar -zxvf zlib-1.2.11.tar.gz            
cd zlib-1.2.11            
./configure && make && make install                    

4.安装nginx

cd /usr/local/nginx                         
tar zxvf nginx-1.17.2.tar.gz                
cd nginx-1.17.2        
./configure && make && make install            

三、Nginx设置成服务并开机自动启动

1、在/etc/init.d下创建文件nginx

vim /etc/init.d/nginx

其内容如下:

#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig:   - 85 15
# description:  NGINX is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /etc/nginx/nginx.conf
# config:      /etc/sysconfig/nginx
# pidfile:     /var/run/nginx.pid

path="/usr/local/nginx/sbin"
name=nginx:

start() {
        cd $path  &&  nohup ./nginx >/dev/null 2>&1 &
        sleep 1
        pid1=`ps -ef | grep $name| grep -v grep |awk '{print $2}'`
        if [[ -n $pid1 ]]; then
                echo nginx 服务启动成功 pid=$pid1
        fi

}

stop() {
        pids=`ps -ef | grep $name | grep -v grep |awk '{print $2}'`
        for pid in $pids
        do
                kill -9 $pid
                echo pid=$pid[$name]已经关闭
        done
}

restart()
{
        $0 stop
        sleep 1
        $0 start
}

status()
{
        ps -ef | grep $name | grep -v grep
}

case "$1" in
        start)
        start
        ;;
        stop)
        stop
        ;;
        status)
        status
        ;;
        restart)
        restart
        ;;
        *)
        echo $"命令行缺少: $0 {start|stop|restart|status}"
        RETVAL=1
esac
exit $RETVAL

可能调整的配置:

path="/usr/local/nginx/sbin"
name=nginx:

也可以参照官方文档方式编写:Red Hat NGINX Init Script | NGINX

2、保存后执行【加入服务配置,开机启动】

chmod a+x /etc/init.d/nginx        
chkconfig --add /etc/init.d/nginx            
chkconfig nginx on        

3、服务操作相关命令

service nginx start
service nginx stop
service nginx restart
service nginx status

完毕>>>

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

cy谭

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值