1、在学习ngnix的时候,免不了需要进行安装,安装其实很简单,一个shell脚本就可以搞定可以参考如下
使用root用户执行nginx-install.sh脚本即可,脚本如下:
#!/bin/bash
set -o nounset
basedir=$(cd "$(dirname "$")"; pwd) # 设置用户名和密码
sys_user=hadoop
sys_user_passwd=hadoop # nginx 的版本信息
nginx_version=1.8. # nginx安装目录
nginx_install_dir=/usr/local/nginx #检查gcc环境是否安装
which gcc &> /dev/null || (echo -e "\033[31mgcc uninstall !!\033[0m"; exit )
test $? -eq && exit #
which make &>/dev/null || ( echo -e "\033[31mmake uninstall!\033[0m" ;exit )
test $? -eq && exit # check openssl
openssl=$(rpm -qa | grep openssl)
if [[ $openssl = "" ]]
then
echo -e "\033[31mopenssl is uninstall\033[0m"
exit
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
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
fi test -f nginx-$nginx_version.tar.gz || (echo "nginx-$nginx_version.tar.gz file not found" ; exit )
test $? -eq && exit tar -zxf nginx-$nginx_version.tar.gz
cd nginx-$nginx_version ./configure --prefix=$nginx_install_dir && make && make install || (echo "nginx install fail"; exit )
test $? -ge && exit function succ_msg {
awk 'BEGIN{printf "%-50s \033[32m%-30s\033[0m\n","'$'", "'$'"}'
} function fail_msg {
awk 'BEGIN{printf "%-50s \033[31m\033[05m%-30s\033[0m\n","'$'", "'$'"}'
} 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,不需要加端口,出现如下说明安装部署成功