redhat 7.3 本地安装nginx
  lxSY9k0Slakj 2023年11月19日 20 0

系统配置

操作系统

[root@react.com sbin]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.3 (Maipo)

nginx版本

nginx-1.16.1

配置本地yum源

服务器无网络,挂载光盘做为yum源

创建本地源文件夹

mkdir -p /mnt/cdrom
挂载镜像文件至指定的目录
mount /dev/cdrom /mnt/cdrom

备份本地源

[root@react.com ~]# cd /etc/yum.repos.d/
[root@react.com yum.repos.d]#cp -rf /etc/yum.repos.d  /etc/yum.repos.d_$(date '+%Y%m%d_%H%M%S')

删除默认原本地源

[root@react.com1 yum.repos.d]#rm -rf /etc/yum.repos.d/*

配置本地源,创建Media.repo文件,配置内容:


[root@react.com yum.repos.d]#vi /etc/yum.repos.d/local.repo

[local]

name=local

baseurl=file:///mnt/cdrom

gpgcheck=1

enabled=1

gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release

加载本地yum源&测试

清除yum缓存

yum clean all

缓存本地yum源

yum makecache

测试yum本地源

yum list

订阅插件提示:This system is not registered with an entitlement server. You can use subscription-manager to register.

这个Red Hat Subscription Manager订阅管理器,它会让你一直register,解决办法:禁用就好

[root@react.com yum.repos.d]#vim /etc/yum/pluginconf.d/subscription-manager.conf
[main]
enabled=0

安装nginx

创建nginx用户组及用户

[root@react.com yum.repos.d]# groupadd app01
[root@react.com yum.repos.d]# useradd -g app01 app01

安装依赖环境

安装gcc环境

yum install gcc-c++

安装PCRE库,用于解析正则表达式

yum install -y pcre pcre-devel

zlib压缩和解压缩依赖


yum install -y zlib zlib-devel

SSL 安全的加密的套接字协议层,用于HTTP安全传输,也就是https

yum install -y openssl openssl-devel

安装Nginx

去官网下载对应的Nginx包,推荐使用稳定版本

http://nginx.org/en/download.html

redhat 7.3 本地安装nginx_Nginx

上传Nginx到Linux

然后就是将下载下来的Nginx解压缩。

[root@react.com nginx]# tar zxvf nginx-1.16.1.tar.gz

进入解压缩后的Nginx目录。如果你要定制版本号可以更改源码目录src/core/nginx.h文件。

[root@react.com nginx]#cd nginx-1.16.1/

创建一个nginx目录用来存放运行的临时文件夹。

[root@react.com nginx-1.16.1]#mkdir -p /etc/nginx
[root@react.com nginx-1.16.1]#mkdir -p /var/cache/nginx

开始configure Nginx。

[root@react.com nginx-1.16.1]#
./configure \
--prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--user=app01 \
--group=app01 \
--with-pcre \
--with-http_v2_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-ipv6 \
--with-http_v2_module \
--with-threads \
--with-stream \
--with-stream_ssl_module

注:\ 代表在命令行中换行,用于提高可读性

配置命令:

命令

解释

-prefix

指定Nginx安装目录

-pid-path

指向Nginx的pid

-lock-path

锁定安装文件,防止被恶意褚篡改或误操作

-error-log

错误日志

–http-log-path

http日志

–with-http_gzip_static_module

启用gzip模块,在线实时压缩输出数据流

–http-client-body-temp-path

设定客户端请求的临时目录

–http-proxy-temp-path

设定http代理临时目录

–http-fastcgi-temp-path

设定fastcgi临时目录

–http-uwsgi-temp-path

设定uwsgi临时目录

–http-scgi-temp-path

设定scgi临时目录

--user 

nginx用户

--group 

nginx用户组

 接着继续编译

[root@react.com nginx-1.16.1]#make

安装Nginx。

[root@react.com nginx-1.16.1]#make install

配置系统服务

由于我们使用源码编译安装Nginx,因此,我们启动、关闭nginx或重新加载配置文件等也就比较麻烦,需要先进入nginx的可执行文件目录,才可以执行nginx相关命令。

为了方便对nginx进行相关操作,我们可以将nginx配置成系统服务,并设置环境变量。

配置systemctl控制的Nginx服务,将以下下内容复制输入到新建的nginx.service文件中

[root@react.com nginx-1.16.1]# vi /usr/lib/systemd/system/nginx.service
[Unit]
# 描述服务
 Description=The nginx HTTP and reverse proxy server
 After=network.target remote-fs.target nss-lookup.target
#
  [Service]
#  # 后台运行
  Type=forking
  PIDFile=/var/run/nginx.pid
#  # 启动前删除进程文件
  ExecStartPre=/usr/bin/rm -f /var/run/nginx.pid
#  # 启动前检测配置文件
  ExecStartPre=/usr/sbin/nginx  -t -c /etc/nginx/nginx.conf
  # 启动nginx
  ExecStart=/usr/sbin/nginx
#  # 重新加载nginx配置
  ExecReload=/bin/kill -s HUP $MAINPID
  KillMode=process
  KillSignal=SIGQUIT
  TimeoutStopSec=5
  PrivateTmp=true
#
[Install]
 WantedBy=multi-user.target

保存,重新加载 systemd

systemctl daemon-reload

使用systemctl来操作nginx服务, 开机自启动

[root@react.com nginx-1.16.1]#systemctl enable nginx.service

 尝试管理Nginx。

[root@react.com nginx-1.16.1]#systemctl status nginx  #查看Nginx状态
[root@react.com nginx-1.16.1]#systemctl start nginx        #启动Mginx服务
[root@react.com nginx-1.16.1]#systemctl stop nginx         #停止Nginx服务
[root@react.com nginx-1.16.1]#systemctl restart nginx   #重启nginx服务
[root@react.com nginx-1.16.1]#systemctl reload nginx #重新读取nginx配置(不用停止nginx服务就能使修改的配置生效)

查看Nginx版本和编译信息

[root@react.com sbin]# ./nginx -V
nginx version: nginx/1.16.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=app01 --group=app01 --with-pcre --with-http_v2_module --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-http_v2_module --with-threads --with-stream --with-stream_ssl_module
【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月19日 0

暂无评论

推荐阅读
lxSY9k0Slakj