首页 / NGINX / Shell编译安装nginx
Shell编译安装nginx
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Shell编译安装nginx,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3855字,纯文字阅读大概需要6分钟。
内容图文
![Shell编译安装nginx](/upload/InfoBanner/zyjiaocheng/1130/d390bcfcad944e97b1e9f31b14da1dab.jpg)
环境及规划
[root@nginx-node01 ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
ID | 主机名 | ip | 系统配置 | 软件版本 | 操作系统 |
---|---|---|---|---|---|
01 | nginx-node01 | 192.168.56.104 | 1C 1G | 1.16.0稳定版 | CentOS 7.6.1810 |
编译依赖检查
-
gcc编译环境
-
pcre & pcre-dev
-
zlib & zlib-dev
-
openssl & openssl-dev
[root@nginx-node01 nginx]# cat checkinstall.sh
#!/bin/bash
#auto install packages nginx required
function checkInstall(){
echo "Checking $1 installed or not"
#rpm -q $1 >/dev/null 2>&1
rpm -q $1
if [ $? -eq 0 ]; then
echo "$1 installed "
else
echo "$1 not installed, will install $1 "
yum -y install $1
if [ $? -ne 0 ];then
echo "Install $1" /bin/false
exit 1
fi
fi
}
##环境及依赖检查
#gcc
checkInstall gcc-c++
#pcre & pcre-devel
checkInstall pcre && checkInstall pcre-devel
#zlib & zlib-devel
checkInstall zlib && checkInstall zlib-devel
#openssl & openssl-devel
checkInstall openssl && checkInstall openssl-devel
安装步骤
-
检查并添加nginx用户和组
-
解压软件包、创建相关目录
-
执行预编译配置
-
执行编译、执行安装
[root@nginx-node01 ~]# useradd -g nginx nginx
[root@nginx-node01 ~]# id nginx
uid=1000(nginx) gid=1000(nginx) groups=1000(nginx)
cat nginx_install.sh
#!/bin/bash
#auto install nginx
#set -n
#set -v
#用户及组
NX_GROUP=‘nginx‘
NX_USER=‘nginx‘
#源码包位置
NX_TMP_DIR=‘/tmp/nginx/‘
#源码版本
NX_VER=1.16.0
NX_FILE="nginx-$NX_VER.tar.gz"
NX_FILE_ABS=$NX_TMP_DIR$NX_FILE
#解压后源码位置
NX_DIR=`echo $NX_FILE |sed ‘s/\.tar.*//g‘`
NX_SRC_ABS=${NX_TMP_DIR}${NX_DIR}
#Nginx home 目录
NX_HOME=‘/home/nginx‘
NX_LOG=$NX_HOME/log
NX_TARGET=${NX_HOME}/${NX_VER}
#解压源码
if [ -d $NX_SRC_ABS ];then
echo "$NX_SRC_ABS already exists"
else
tar -xvzf $NX_FILE
fi
##配置目录、预编译
cd $NX_SRC_ABS
##设置安装目录
#添加log目录
if [ ! -d $NX_LOG ]; then
mkdir -p $NX_LOG
fi
#Nginx 安装目录
if [ ! -d ${NX_TARGET} ]; then
mkdir -p ${NX_TARGET}
fi
#预编译配置
./configure --user=$NX_USER --group=$NX_GROUP --prefix=${NX_TARGET} --sbin-path=${NX_TARGET}/nginx --conf-path=${NX_TARGET}/nginx.conf --pid-path=${NX_LOG}/nginx.pid --error-log-path=${NX_LOG}/error.log --http-log-path=${NX_LOG}/access.log --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module
#编译 && 安装
make && make install
安装验证
[root@nginx-node01 ~]# /home/nginx/1.16.0/nginx -V
nginx version: nginx/1.16.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --user=nginx --group=nginx --prefix=/home/nginx/1.16.0 --sbin-path=/home/nginx/1.16.0/nginx --conf-path=/home/nginx/1.16.0/nginx.conf --pid-path=/home/nginx/log/nginx.pid --error-log-path=/home/nginx/log/error.log --http-log-path=/home/nginx/log/access.log --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module
启动验证
[root@nginx-node01 ~]# netstat -ntlp |grep -aiw 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 21949/nginx: master
[root@nginx-node01 ~]# ps -ef |grep nginx
root 21949 1 0 11:58 ? 00:00:00 nginx: master process ./nginx
nginx 21950 21949 0 11:58 ? 00:00:00 nginx: worker process
服务验证
[root@nginx-node01 ~]# curl localhost:80
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
对外服务验证
#关闭防火墙
systemctl stop firewalld.service
原文:https://www.cnblogs.com/elfcafe/p/13127252.html
内容总结
以上是互联网集市为您收集整理的Shell编译安装nginx全部内容,希望文章能够帮你解决Shell编译安装nginx所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。