{"id":599,"date":"2021-04-01T17:43:32","date_gmt":"2021-04-01T09:43:32","guid":{"rendered":"https:\/\/qtvz.com\/?p=599"},"modified":"2021-04-01T17:43:32","modified_gmt":"2021-04-01T09:43:32","slug":"shell%e8%84%9a%e6%9c%ac%ef%bc%9a%e4%b8%80%e9%94%ae%e5%ae%89%e8%a3%85nginx%e6%9c%8d%e5%8a%a1%ef%bc%8c%e7%94%a8%e6%88%b7%e5%8f%af%e8%87%aa%e5%ae%9a%e4%b9%89nginx%e7%89%88%e6%9c%ac","status":"publish","type":"post","link":"https:\/\/qtvz.com\/599.html","title":{"rendered":"Shell\u811a\u672c\uff1a\u4e00\u952e\u5b89\u88c5Nginx\u670d\u52a1\uff0c\u7528\u6237\u53ef\u81ea\u5b9a\u4e49Nginx\u7248\u672c"},"content":{"rendered":"<!--wp-compress-html--><!--wp-compress-html no compression--><h6>\u7f51\u4e0a\u770b\u5230\u7684\u6587\u7ae0\u8bb0\u5f55\u4e00\u4e0b\u4ee5\u9632\u4e22\u5931 <a href=\"https:\/\/qtvz.com\/redirect\/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQyNTI3MjY5L2FydGljbGUvZGV0YWlscy8xMTUzMjQ0MzY=\" target=\"_blank\">\u539f\u6587<\/a><\/h6>\n<pre><code>#!\/bin\/bash\n\n#Nginx\u7248\u672c\nver=nginx-1.$2.$3\n\n# \u5b89\u88c5\u76ee\u5f55\nin_dir=&quot;\/app\/$ver&quot;\n\n#\u8f6f\u4ef6\u5b58\u653e\u76ee\u5f55\ndl_dir=&quot;\/server&quot;\n\n#\u6700\u7ec8\u8fd0\u884c\u76ee\u5f55\nrun_dir=\/app\/nginx\n\nif [ ! -d $in_dir ];then\n    mkdir -p $in_dir\nfi\nif [ ! -d $dl_dir ];then\n    mkdir $dl_dir\nfi\n\n##\u5b89\u88c5nginx\nfunction nginx_install (){\nyum -y install gcc gcc-c++ pcre-devel zlib-devel openssl-devel \nif [ $? -eq 0 ]\nthen\n    curl  &quot;http:\/\/nginx.org\/download\/$ver.tar.gz&quot; -o $dl_dir\/$ver.tar.gz &amp;&amp;  \n    useradd -M -s \/sbinlogin nginx  &amp;&amp; \n    tar xf $dl_dir\/$ver.tar.gz -C $dl_dir  &amp;&amp; \n    cd $dl_dir\/$ver\n    .\/configure  --prefix=$in_dir --user=nginx --group=nginx  &amp;&amp;  \n    make  &amp;&amp; make install \nfi\n\n}\nfunction nginx_init (){\n  ln -s $in_dir $run_dir\n}\n\nfunction nginx_start (){\n\n  ps -ef |grep nginx |grep master\n\n  if [ $? = 0  ];then\n        echo &quot;Nginx is Running.&quot;\n  else\n        if [ ! -e $run_dir\/sbin\/nginx ];then\n        nginx_init\n        fi\n    $run_dir\/sbin\/nginx\n        sleep 5\n        ps -ef |grep nginx |grep master\n        if [ $? = 0  ];then\n        echo &quot;Nginx Start successfully.&quot;\n        else\n        echo &quot;Nginx Failed to Start.&quot;\n    fi\n  fi\n\n}\n\nfunction nginx_stop (){\n    $run_dir\/sbin\/nginx -s quit \n        sleep 5\n        ps -ef |grep nginx |grep master\n        if [ $? != 0  ];then\n        echo &quot;Nginx Stop successfully.&quot;\n        else\n            echo &quot;Nginx Failed to Stop.&quot;\n    fi\n}\n\nfunction nginx_reload (){\n    $run_dir\/sbin\/nginx -s reload \n}\n\nmain(){\n  nginx_install\n  nginx_start\n}\n\ncase $1 in \ninstall)\n    nginx_install\n    nginx_init\n    nginx_start\n    ;;\nstart)\n    nginx_start\n    ;;\nstop)\n    nginx_stop\n    ;;\nrestart)\n    nginx_stop\n    nginx_start\n    ;;\nreload)\n    nginx_reload\n    ;;\n*)\n    echo &quot;\u4f7f\u7528\u65b9\u6cd5&quot;\n    echo &quot;$0 start|stop|restart|reload&quot;   \n    echo &quot;\u5b89\u88c5\u65b9\u6cd5&quot;\n    echo &quot;$0 install &lt;\u7248\u672c\u53f7&gt; &lt;\u5c0f\u7248\u672c\u53f7&gt;  \u4f8b\u5982\uff1a$0 install 19 3 \u4e0b\u8f7d\u7684\u5c31\u662f1.19.3\u7248\u672c &quot;\n    ;;\nesac\n\n#if [ $# = 0 ];then\n#   echo  &quot;\u4f7f\u7528 $0 \u540e\u9762\u52a0\u4e0a\u5c0f\u7248\u672c\u53f7\u8fdb\u884c\u90e8\u7f72\uff1a\u4f8b\u5982 $0 19 3 \u4e0b\u8f7d\u7684\u5c31\u662f1.19.3\u7248\u672c&quot;\n#else\n#   echo &quot;\u4e0b\u8f7d\u7248\u672c\uff1a1.$2.$3&quot;\n#   echo &quot;\u5b89\u88c5\u76ee\u5f55\uff1a$in_dir&quot;\n#   echo &quot;\u4e0b\u8f7d\u76ee\u5f55\uff1a$dl_dir&quot;\n#   echo &quot;Nginx installation...&quot; \n#        nginx_install\n#        if [ $? != 0 ];then\n##  echo &quot;Ngins installation Failed.&quot;\n#   else \n#        nginx_init\n#        nginx_start\n#        fi \n#fi<\/code><\/pre>\n<ul>\n<li>\u8fd9\u4e2a\u811a\u672c\u53ef\u4ee5\u5b9e\u73b0\u7528\u6237\u81ea\u5df1\u9009\u62e9\u60f3\u8981\u5b89\u88c5\u7684Nginx\u7248\u672c<\/li>\n<li>\u6bd4\u5982\u6211\u60f3\u88c5\u4e00\u4e2anginx-1.16.1\u7248\u672c\uff0c\u53ef\u4ee5\u8fd9\u6837\u505a\n<pre><code>sh install_nginx.sh install 16 1<\/code><\/pre>\n<\/li>\n<li>\u5f53\u7136\uff0c\u5982\u679c\u4f60\u5f00\u59cb\u5e76\u4e0d\u77e5\u9053\u4f7f\u7528\u65b9\u6cd5\uff0c\u76f4\u63a5\u6267\u884c\u4e86\u811a\u672c\uff0c\u6ca1\u5173\u7cfb\uff0c\u6709\u63d0\u793a\uff1a\n<pre><code>[root@localhost ~]# sh install_nginx.sh\n\u4f7f\u7528\u65b9\u6cd5\ninstall_nginx.sh start|stop|restart|reload\n\u5b89\u88c5\u65b9\u6cd5\ninstall_nginx.sh install &lt;\u7248\u672c\u53f7&gt; &lt;\u5c0f\u7248\u672c\u53f7&gt;  \u4f8b\u5982\uff1ainstall_nginx.sh install 19 3 \u4e0b\u8f7d\u7684\u5c31\u662f1.19.3\u7248\u672c <\/code><\/pre>\n<\/li>\n<li>\u77a7\uff0c\u4e0d\u5149\u544a\u8bc9\u4e86\u4f60\u600e\u4e48\u4f7f\u7528\u5b83\u5b89\u88c5\u670d\u52a1\uff0c\u8fd8\u53ef\u4ee5\u76f4\u63a5\u8fd0\u884c\u811a\u672c\u8fdb\u884c\u7ba1\u7406<\/li>\n<li>\u5f53\u4f60\u521a\u5b89\u88c5\u5b8c\u6210\u7684\u65f6\u5019\u9ed8\u8ba4\u662f\u542f\u52a8\u7684\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u811a\u672c\u8fdb\u884c\u5173\u95ed\u6216\u91cd\u542f\uff1a\n<pre><code>[root@localhost ~]# sh install_nginx.sh stop\nNginx Stop successfully.\n[root@localhost ~]# sh install_nginx.sh reload<\/code><\/pre>\n<\/li>\n<li>\u7136\u540e\u4f60\u53ef\u4ee5\u4fee\u6539\u914d\u7f6e\u540e\u8fdb\u884c\u5f00\u542f\uff1a\n<pre><code>[root@localhost ~]# sh install_nginx.sh start\nroot       4236      1  0 14:23 ?        00:00:00 nginx: master process \/app\/nginx\/sbin\/nginx\nNginx Start successfully.<\/code><\/pre>\n<\/li>\n<li>\u67e5\u770b\u5b83\u7684\u72b6\u6001\uff0c\u770b\u5b83\u662f\u5426\u5728\u8fd0\u884c\uff1a\n<pre><code>[root@localhost ~]# ss -utpln | grep nginx\ntcp    LISTEN     0      128       *:80                    *:*                   users:((&quot;nginx&quot;,pid=4238,fd=6),(&quot;nginx&quot;,pid=4236,fd=6))<\/code><\/pre>\n<\/li>\n<\/ul>\n<!--wp-compress-html no compression--><!--wp-compress-html-->","protected":false},"excerpt":{"rendered":"\u7f51\u4e0a\u770b\u5230\u7684\u6587\u7ae0\u8bb0\u5f55\u4e00\u4e0b\u4ee5\u9632\u4e22\u5931 \u539f\u6587 #!\/bin\/bash #Nginx\u7248\u672c ver=nginx-1.$2.$3 # \u5b89\u88c5\u76ee\u5f55 in_dir=&quot;\/app\/$ver&quot; #\u8f6f\u4ef6\u5b58\u653e\u76ee \u00b7\u00b7\u00b7","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[43],"tags":[],"views":2672,"_links":{"self":[{"href":"https:\/\/qtvz.com\/api\/wp\/v2\/posts\/599"}],"collection":[{"href":"https:\/\/qtvz.com\/api\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qtvz.com\/api\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qtvz.com\/api\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qtvz.com\/api\/wp\/v2\/comments?post=599"}],"version-history":[{"count":1,"href":"https:\/\/qtvz.com\/api\/wp\/v2\/posts\/599\/revisions"}],"predecessor-version":[{"id":600,"href":"https:\/\/qtvz.com\/api\/wp\/v2\/posts\/599\/revisions\/600"}],"wp:attachment":[{"href":"https:\/\/qtvz.com\/api\/wp\/v2\/media?parent=599"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qtvz.com\/api\/wp\/v2\/categories?post=599"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qtvz.com\/api\/wp\/v2\/tags?post=599"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}