nginx编译装--脚本

nginx手动编译安装

1安装环境包
yum -y install gcc gcc-c++ pcre pcre-devel zlib-devel

上传nginx压缩包到/opt目录下

2 解压nginx压缩包
[root@localhost opt]# tar  -zxvf nginx-1.12.2.tar.gz
3 创建运行用户
[root@localhost opt]# useradd -M -s /sbin/nologin nginx
4 编译安装
[root@localhost opt]# mkdir LNMP
[root@localhost nginx-1.12.2]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module

[root@localhost opt]# make && makeinstall
5优化路径
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin
6检查配置文件 /usr/local/nginx/conf/nginx.conf
[root@localhost sbin]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost sbin]# nginx
[root@localhost sbin]# netstat -napt |grep 80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      70403/nginx: master 


7 编译安装启动脚本

cd /etc/init.d/

vim /etc/init.d/nginx

#!/bin/bash
#chkconfig: - 99 20
#description: Nginx Service Control Script 
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case "$1" in
    start)
       $PROG
        ;;
    stop)
        kill -s QUIT $(cat $PIDF)
        ;;
    restart)
      $0 stop
      $o start
        ;;
    reload)
      kill -s HUP $(cat $PIDF)
        ;;
    *)
            echo "Usage: $0 {start|stop|restart|reload}"
            exit 1
esac
exit 0
8 验证编译脚本格式
 nginx -t
9 添加启动脚本
chkconfig --add nginx
10检查service 命令能否正常启动关闭
[root@localhost init.d]# netstat -napt |grep 80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      71485/nginx: master 
[root@localhost init.d]# service nginx stop
env: /etc/init.d/nginx: 权限不够
[root@localhost init.d]# chmod +x nginx
[root@localhost init.d]# service nginx stop
[root@localhost init.d]# netstat -napt |grep 80
[root@localhost init.d]# service nginx start
[root@localhost init.d]# netstat -napt |grep 80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      71705/nginx: maste
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值