nginx deployment and installation

Keywords: Java Nginx OpenSSL RPM Hadoop

1. When learning ngnix, there is no need to install it. In fact, the installation is very simple. A shell script can do it. Please refer to the following

Use the root user to execute the nginx-install.sh script, which is as follows:

#!/bin/bash
set -o nounset
basedir=$(cd "$(dirname "$0")"; pwd)

# Set user name and password
sys_user=hadoop
sys_user_passwd=hadoop

# Version information of nginx
nginx_version=1.8.0

# nginx installation directory
nginx_install_dir=/usr/local/nginx

#Check that the gcc environment is installed
which gcc &> /dev/null  || (echo -e "\033[31mgcc uninstall !!\033[0m"; exit 1)
test $? -eq 1 && exit 1

#
which make &>/dev/null || ( echo -e "\033[31mmake uninstall!\033[0m" ;exit 1)
test $? -eq 1 && exit 1

# check openssl 
openssl=$(rpm -qa | grep openssl)
if [[ $openssl = "" ]]
then
  echo -e "\033[31mopenssl is uninstall\033[0m"
  exit 1
fi

# check pcre-devel
pcre_devel=$(rpm -aq | grep pcre-devel)
if [[ $pcre_devel = "" ]]
then
  echo -e "\033[31mpcre-devel is uninstall\033[0m"
  exit 1
fi

# check zlib-devel
zlib_devel=$(rpm -aq | grep zlib-devel)
if [[ $zlib_devel = "" ]]
then 
  echo -e "\033[31mzlib-devel is uninstall\033[0m"
  exit 1
fi


test -f nginx-$nginx_version.tar.gz || (echo "nginx-$nginx_version.tar.gz file not found" ; exit 1)
test $? -eq 1 && exit 1

tar -zxf nginx-$nginx_version.tar.gz 
cd nginx-$nginx_version

./configure --prefix=$nginx_install_dir && make && make install || (echo "nginx install fail"; exit 1)
test $? -ge 1 && exit 1

function succ_msg {
  awk 'BEGIN{printf "%-50s \033[32m%-30s\033[0m\n","'$1'", "'$2'"}'
}

function fail_msg {
  awk 'BEGIN{printf "%-50s \033[31m\033[05m%-30s\033[0m\n","'$1'", "'$2'"}'
}

succ_msg "nginx install" "Success"

2. Finally, you will be prompted that the installation is successful. At this time, you can start and check whether nginx is successful

Start nginx

/usr/local/nginx/sbin/nginx

The default port of nginx is 80. Check whether the service is restarted successfully
ps -ef | grep nginx

Turn off nginx

/usr/local/nginx/sbin/nginx -s stop

Restart command

/usr/local/nginx/sbin/nginx -s reload

To access the ip address of the server, you do not need to add a port. The following shows that the installation and deployment are successful

  

Posted by bk6662 on Mon, 30 Dec 2019 12:26:23 -0800