• nginx的编译安装以及启动脚本编写


    Nginx的编译安装和启动脚本的编写

    Nginxd的功能强大,可以实现代理、负载均衡等企业常用的功能。下面介绍一下nginx的编译安装方法:

    1. 下载

      官方下载地址:http://nginx.org/en/download.html;下面以nginx-1.8.0版本为例:

    # cd /usr/local/src/
    # wget http://nginx.org/download/nginx-1.8.0.tar.gz
    # tar zxvf nginx-1.8.0.tar.gz
    

    2. 配置

    # cd nginx-1.8.0
    # ./configure 
    --prefix=/usr/local/nginx 
    --with-http_realip_module 
    --with-http_sub_module 
    --with-http_gzip_static_module 
    --with-http_stub_status_module 
    --with-pcre
    

      若出现以下错误:

    ./configure: error: the HTTP rewrite module requires the PCRE library.
    # yum -y install pcre-devel
    

    3. 编译、安装

    # make && make install
    

     4. 启动Nginx

    # /usr/local/nginx/sbin/nginx   //启动nginx
    # ps aux |grep nginx   //查看是否启动成功
    

     5. 启动脚本编写

      编写的启动脚本,可实现功能如【start|stop|reload|restart|configtest】即【启动|关闭|重新加载|重启|配置排错】

    # vim /etc/init.d/nginx    //写入以下内容

    #!/bin/bash # chkconfig: - 30 21 # description: http service. # Source Function Library . /etc/init.d/functions # Nginx Settings NGINX_SBIN="/usr/local/nginx/sbin/nginx" NGINX_CONF="/usr/local/nginx/conf/nginx.conf" NGINX_PID="/usr/local/nginx/logs/nginx.pid" RETVAL=0 prog="Nginx" start() { echo -n $"Starting $prog: " mkdir -p /dev/shm/nginx_temp daemon $NGINX_SBIN -c $NGINX_CONF RETVAL=$? echo return $RETVAL } stop() { echo -n $"Stopping $prog: " killproc -p $NGINX_PID $NGINX_SBIN -TERM rm -rf /dev/shm/nginx_temp RETVAL=$? echo return $RETVAL } reload(){ echo -n $"Reloading $prog: " killproc -p $NGINX_PID $NGINX_SBIN -HUP RETVAL=$? echo return $RETVAL } restart(){ stop start } configtest(){ $NGINX_SBIN -c $NGINX_CONF -t return 0 } case "$1" in start) start ;; stop) stop ;; reload) reload ;; restart) restart ;; configtest) configtest ;; *) echo $"Usage: $0 {start|stop|reload|restart|configtest}" RETVAL=1 esac exit $RETVAL

       保存后,修改权限,因为必须要有执行权限:

    # chmod 755 /etc/init.d/nginx
    # chkconfig --add nginx  //加入开机启动列表
    # chkconfig nginx on     //启动开机启动
    

       开机启动选项,可以根据自己的需求来添加和开启。

  • 相关阅读:
    选择排序与冒泡排序
    判断是否为偶数
    mysql基础之mysql双主(主主)架构
    mysql基础之mysql主从架构半同步复制
    mysql基础之mysql主从架构
    mysql基础之数据库备份和恢复实操
    mysql基础之数据库备份和恢复的基础知识
    mysql基础之日志管理(查询日志、慢查询日志、错误日志、二进制日志、中继日志、事务日志)
    mysql基础之查询缓存、存储引擎
    mysql基础之数据库变量(参数)管理
  • 原文地址:https://www.cnblogs.com/llius/p/5105240.html
Copyright © 2020-2023  润新知