shell腳本多實例部署nginx的詳細教程
發(fā)布日期:2022-01-28 15:47 | 文章來源:源碼之家
1. 創(chuàng)建一個目錄,用來存放腳本和安裝包
[root@localhost nginx]# tree . ├── install.sh └── packages └── nginx-1.20.1.tar.gz 1 directory, 2 files [root@localhost nginx]#
2. 下載好對應的安裝包
[root@localhost packages]# wget https://nginx.org/download/nginx-1.20.1.tar.gz [root@localhost packages]# ls nginx-1.20.1.tar.gz [root@localhost packages]#
3. 編寫腳本
[root@localhost nginx]# cat install.sh #!/bin/bash log_dir=/var/log install_dir=/usr/local id nginx &>/dev/null if [ $? -ne 0 ];then useradd -r -M -s /sbin/nologin nginx fi yum -y install pcre-devel pcre gcc gcc-c++ openssl-devel zlib zlib-devel make vim wget openssl openssl-devel gd-devel if [ ! -d $log_dir/nginx ];then mkdir -p $log_dir/nginx chown -R nginx.nginx $log_dir/nginx fi if [ ! -d $install_dir/nginx-1.20.1 ];then tar xf packages/nginx-1.20.1.tar.gz -C $install_dir fi cd $install_dir/nginx-1.20.1 if [ ! -d $install_dir/nginx ];then ./configure --prefix=$install_dir/nginx \ --user=nginx \ --group=nginx \ --with-debug \ --with-http_ssl_module \ --with-http_realip_module \ --with-http_image_filter_module \ --with-http_gunzip_module \ --with-http_gzip_static_module \ --with-http_stub_status_module \ --http-log-path=/var/log/nginx/access.log \ --error-log-path=/var/log/nginx/error.log make && make install fi echo "export PATH=$install_dir/nginx/sbin:$PATH" > /etc/profile.d/nginx.sh cat > /usr/lib/systemd/system/nginx.service <<EOF [Unit] Description=Nginx server daemon After=network.target [Service] Type=forking ExecStart=/usr/local/nginx/sbin/nginx ExecStop=/usr/local/nginx/sbin/nginx -s quit ExecReload=/bin/kill -HUP \$MAINPID [Install] WantedBy=multi-user.target EOF systemctl daemon-reload systemctl enable --now nginx.service [root@localhost nginx]#
4. 驗證效果
[root@localhost nginx]# bash -x install.sh + log_dir=/var/log + install_dir=/usr/local + id nginx + '[' 0 -ne 0 ']' + yum -y install pcre-devel pcre gcc gcc-c++ openssl-devel zlib zlib-devel make vim wget openssl openssl-devel gd-devel Updating Subscription Management repositories. Unable to read consumer identity This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. 上次元數(shù)據(jù)過期檢查:1:03:20 前,執(zhí)行于 2021年10月24日 星期日 20時57分26秒。 軟件包 pcre-devel-8.42-4.el8.x86_64 已安裝。 軟件包 pcre-8.42-4.el8.x86_64 已安裝。 軟件包 gcc-8.4.1-1.el8.x86_64 已安裝。 軟件包 gcc-c++-8.4.1-1.el8.x86_64 已安裝。 軟件包 openssl-devel-1:1.1.1g-15.el8_3.x86_64 已安裝。 軟件包 zlib-1.2.11-17.el8.x86_64 已安裝。 軟件包 zlib-devel-1.2.11-17.el8.x86_64 已安裝。 軟件包 make-1:4.2.1-10.el8.x86_64 已安裝。 軟件包 vim-enhanced-2:8.0.1763-15.el8.x86_64 已安裝。 軟件包 wget-1.19.5-10.el8.x86_64 已安裝。 軟件包 openssl-1:1.1.1g-15.el8_3.x86_64 已安裝。 軟件包 gd-devel-2.2.5-7.el8.x86_64 已安裝。 依賴關系解決。 無需任何處理。 完畢! + '[' '!' -d /var/log/nginx ']' + '[' '!' -d /usr/local/nginx-1.20.1 ']' + cd /usr/local/nginx-1.20.1 + '[' '!' -d /usr/local/nginx ']' + echo 'export PATH=/usr/local/nginx/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin' + cat + systemctl daemon-reload + systemctl enable --now nginx.service [root@localhost nginx]# [root@localhost nginx]# ss -antl StateRecv-Q Send-QLocal Address:Port Peer Address:Port LISTEN 0 128 0.0.0.0:80 0.0.0.0:* LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 128 [::]:22 [::]:* [root@localhost nginx]#
到此這篇關于shell腳本多實例部署nginx的詳細教程的文章就介紹到這了,更多相關shell腳本部署nginx內(nèi)容請搜索本站以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持本站!
版權聲明:本站文章來源標注為YINGSOO的內(nèi)容版權均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務器上建立鏡像,否則將依法追究法律責任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學習參考,不代表本站立場,如有內(nèi)容涉嫌侵權,請聯(lián)系alex-e#qq.com處理。
相關文章