一、编译安装
安装插件
安装需要的组件
yum -y install gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
1、gcc是linux下的编译器在此不多做解释,感兴趣的小伙伴可以去查一下相关资料,它可以编译 C,C++,Ada,Object C和Java等语言
查看gcc版本
gcc -v
ldd --version
安装命令 gcc、gcc-c++
yum -y install gcc gcc-c++
2、pcre、pcre-devel安装
pcre是一个perl库,包括perl兼容的正则表达式库,nginx的http模块使用pcre来解析正则表达式,所以需要安装pcre库。
安装命令:
yum install -y pcre pcre-devel
3、zlib安装
zlib库提供了很多种压缩和解压缩方式nginx使用zlib对http包的内容进行gzip,所以需要安装
安装命令:
yum install -y zlib zlib-devel
4、安装openssl
yum install -y openssl openssl-devel
安装nginx
1、下载nginx安装包并解压
mkdir /software && cd /software
wget http://nginx.org/download/nginx-1.19.9.tar.gz
tar -zxvf nginx-1.19.9.tar.gz
cd nginx-1.19.9.tar.gz
2、编译并安装
检查环境配置环境,默认配置路径在/user/local/nginx
./configure --prefix=/usr/local/nginx
也可以自定义路径
./configure \ --prefix=/usr/local/nginx \ --conf-path=/usr/local/nginx/conf/nginx.conf \ --pid-path=/usr/local/nginx/conf/nginx.pid \ --lock-path=/var/lock/nginx.lock \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --with-http_gzip_static_module \ --http-client-body-temp-path=/var/temp/nginx/client \ --http-proxy-temp-path=/var/temp/nginx/proxy \ --http-fastcgi-temp-path=/var/temp/nginx/fastcgi \ --http-uwsgi-temp-path=/var/temp/nginx/uwsgi \ --http-scgi-temp-path=/var/temp/nginx/scgi
执行安装
make&&make install
3、配置文件并启动
切换到/usr/local/nginx主目录
配置文件 vim conf/nginx.conf
启动nginx
cd /usr/local/nginx/sbin/
./nginx
启停检查语法
cd /usr/local/nginx/sbin/ ./nginx ./nginx -s stop ./nginx -s quit ./nginx -s reload
./nginx -t
4、检查访问主页
防火墙添加80端口
firewall-cmd --permanent --add-port=80/tcp firewall-cmd --reload
web端访问ip
二、nginx服务启动
nginx启动脚本
# chkconfig: 2345 85 15 # description:Nginx Server NGINX_HOME=/usr/local/nginx NGINX_SBIN=$NGINX_HOME/sbin/nginx NGINX_CONF=$NGINX_HOME/conf/nginx.conf NGINX_PID=$NGINX_HOME/logs/nginx.pid NGINX_NAME="Nginx" . /etc/rc.d/init.d/functions if [ ! -f $NGINX_SBIN ] then echo "$NGINX_NAME startup: $NGINX_SBIN not exists! " exit fi start() { $NGINX_SBIN -c $NGINX_CONF ret=$? if [ $ret -eq 0 ]; then action $"Starting $NGINX_NAME: " /bin/true else action $"Starting $NGINX_NAME: " /bin/false fi } stop() { kill `cat $NGINX_PID` ret=$? if [ $ret -eq 0 ]; then action $"Stopping $NGINX_NAME: " /bin/true else action $"Stopping $NGINX_NAME: " /bin/false fi } restart() { stop start } check() { $NGINX_SBIN -c $NGINX_CONF -t } reload() { kill -HUP `cat $NGINX_PID` && echo "reload success!" } relog() { kill -USR1 `cat $NGINX_PID` && echo "relog success!" } case "$1" in start) start ;; stop) stop ;; restart) restart ;; check|chk) check ;; status) status -p $NGINX_PID ;; reload) reload ;; relog) relog ;; *) echo $"Usage: $0 {start|stop|restart|reload|status|check|relog}" exit 1 esac
启动Nginx:start nginx
快速停止或关闭Nginx:nginx -s stop
正常停止或关闭Nginx:nginx -s quit
配置文件修改重装载命令:nginx -s reload
三、安装nginx遇到的问题
已经安装gblic版本 2.17-324.el7.9.x86_64版本太高 需要降级
查看当前rpm安装版本
rpm -qa |grep glibc
解决方法:挂载iso镜像 添加本地yum仓库
降低版本,再查看
yum clean all && yum makecache
yum downgrade glibc glibc-devel glibc-common glibc-headers
rpm -qa |grep glibc
安装gblic版本 2.17-317.el7.9.x86_64就可以继续了