nginx部署与安装

1、在学习ngnix的时候,免不了需要进行安装,安装其实很简单,一个shell脚本就可以搞定可以参考如下

使用root用户执行nginx-install.sh脚本即可,脚本如下:

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

# 设置用户名和密码
sys_user=hadoop
sys_user_passwd=hadoop

# nginx 的版本信息
nginx_version=1.8.0

# nginx安装目录
nginx_install_dir=/usr/local/nginx

#检查gcc环境是否安装
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安装" "成功"

2、最终会提示安装成功,这个时候可以启动和检查nginx是否成功

  启动nginx

/usr/local/nginx/sbin/nginx

nginx默认端口是80,查看服务是否重启成功
ps -ef | grep nginx

 关闭nginx

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

  重新热启动命令

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

  访问该服务器的ip,不需要加端口,出现如下说明安装部署成功

  

posted on 2018-09-18 19:07  海之浪子  阅读(220)  评论(0编辑  收藏  举报

导航