In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to use Shell script to install Nginx service with one click". In daily operation, I believe many people have doubts about how to use Shell script to install Nginx service with one click. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubt of "how to use Shell script to install Nginx service with one click". Next, please follow the editor to study!
Not much, the content is as follows:
#! / bin/bash#Nginx version ver=nginx-1.$2.$3# installation directory in_dir= "/ app/$ver" # Software storage directory dl_dir= "/ server" # final run directory run_dir=/app/nginxif [!-d $in_dir]; then mkdir-p $in_dirfiif [!-d $dl_dir] Then mkdir $dl_dirfi## install nginxfunction nginx_install () {yum-y install gcc gcc-c++ pcre-devel zlib-devel openssl-devel if [$?-eq 0] then curl "http://nginx.org/download/$ver.tar.gz"-o $dl_dir/$ver.tar.gz & &\ useradd-M-s / sbinlogin nginx & &\ tar xf $dl_dir/$ver.tar.gz-C $dl_dir & &\ Cd $dl_dir/$ver. / configure-- prefix=$in_dir-- user=nginx-- group=nginx & &\ make & & make install fi} function nginx_init () {ln-s $in_dir $run_dir} function nginx_start () {ps-ef | grep nginx | grep master if [$? = 0] Then echo "Nginx is Running." Else if [!-e $run_dir/sbin/nginx]; then nginx_init fi $run_dir/sbin/nginx sleep 5 ps-ef | grep nginx | grep master if [$? = 0]; then echo "Nginx Start successfully." Else echo "Nginx Failed to Start." Fi fi} function nginx_stop () {$run_dir/sbin/nginx-s quit sleep 5 ps-ef | grep nginx | grep master if [$?! = 0]; then echo "Nginx Stop successfully." Else echo "Nginx Failed to Stop." Fi} function nginx_reload () {$run_dir/sbin/nginx-s reload} main () {nginx_install nginx_start} case $1 in install) nginx_install nginx_init nginx_start;; start) nginx_start;; stop) nginx_stop;; restart) nginx_stop nginx_start;; reload) nginx_reload *) echo "usage" echo "$0 start | stop | restart | reload" echo "installation method" echo "$0 install for example: $0 install 19 3 download is version 1.19.3"; esac#if [$# = 0] Then# echo "is deployed with a small version number followed by $0: for example, what is downloaded for $0193 is version 1.19.3" # else# echo "download version: 1." 2.room3" # echo "installation directory: $in_dir" # echo "download directory: $dl_dir" # echo "Nginx installation..." # nginx_install# if [$?! = 0] Then## echo "Ngins installation Failed." # else # nginx_init# nginx_start# fi # fi
This script can implement the Nginx version that the user chooses to install.
For example, if I want to install a nginx-1.16.1 version, I can do this:
Sh install_nginx.sh install 16 1
Of course, if you don't know how to use it at first and execute the script directly, it doesn't matter, there are hints:
[root@localhost ~] # sh install_nginx.sh usage install_nginx.sh start | stop | restart | reload installation method install_nginx.sh install for example: install_nginx.sh install 19 3 downloads version 1.19.3
Look, it not only tells you how to use it to install the service, but also runs the script directly to manage it. When you first install it, it is started by default, and you can use the script to shut down or restart:
[root@localhost ~] # sh install_nginx.sh stopNginx Stop successfully. [root@localhost ~] # sh install_nginx.sh reload
Then you can change the configuration and enable it:
[root@localhost ~] # sh install_nginx.sh startroot 4236 10 14:23? 00:00:00 nginx: master process / app/nginx/sbin/nginxNginx Start successfully.
Check its status to see if it is running:
[root@localhost ~] # ss-utpln | grep nginxtcp LISTEN 0 128 *: 80 *: * users: ("nginx", pid=4238,fd=6), ("nginx", pid=4236,fd=6))
Let's visit it with a browser.
At this point, the study on "how to use Shell scripts to install Nginx services with one click" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.