0
点赞
收藏
分享

微信扫一扫

安装和基本使用

伽马星系 2022-01-08 阅读 46
nginx运维

准备工作


系统环境

Linux localhost.localdomain 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

centos7

安装用户使用root用户,否则在使用的过程中可能会出现权限不够的问题

安装系统依赖

yum install openssl

yum install openssl-devel

yum install -y install gcc-c++

安装pcre正则表达式库

这个在后期的一些模块中可以使用到

cd /usr/local

wget https://images-1258301517.cos.ap-nanjing.myqcloud.com/file/pcre-8.40.tar.gz

tar -xvf pcre-8.40.tar.gz
cd pcre-8.40

./configure
make && make install

安装


下载nginx

cd /usr/local

wget https://images-1258301517.cos.ap-nanjing.myqcloud.com/file/nginx-1.19.0.tar.gz

tar -xvf nginx-1.19.0.tar.gz

下载模块

nginx需要在安装前准备好模块,因为nginx不支持在安装完成再次添加模块,如果安装完成后想再次添加模块,那么需要重新编译

cd nginx-1.19.0
mkdir module
cd module
#负载均衡模块
wget https://images-1258301517.cos.ap-nanjing.myqcloud.com/file/nginx-goodies-nginx-sticky-module-ng-08a395c66e42.tar.gz
tar -xvf nginx-goodies-nginx-sticky-module-ng-08a395c66e42.tar.gz 
mv nginx-goodies-nginx-sticky-module-ng-08a395c66e42 nginx-sticky-module

修改文件ngx_http_sticky_misc.c

vi ngx_http_sticky_misc.c

image-20220106110110963

在最上方添加如下内容

#include <openssl/sha.h>
#include <openssl/md5.h>

编译nginx

cd nginx-1.19.0

./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/usr/local/nginx/nginx.lock \
--error-log-path=/usr/local/nginx/log/error.log \
--http-log-path=/usr/local/nginx/log/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/usr/local/nginx/client \
--http-proxy-temp-path=/usr/local/nginx/proxy \
--http-fastcgi-temp-path=/usr/local/nginx/fastcgi \
--http-uwsgi-temp-path=/usr/local/nginx/uwsgi \
--http-scgi-temp-path=/usr/local/nginx/scgi \--with-http_stub_status_module \
--with-http_realip_module \
--add-module=/usr/local/nginx-1.19.0/module/nginx-sticky-module

如上面的代码所示,编译需要设置一些信息,如日志的位置,需要添加的模块,脚本运行的路径等。

编译完成后执行如下的命令:

make && make install

启动

因为在编译期间设置了脚本的启动路径/usr/local/nginx,所以切换到该目录下。

image-20220106110501559

从上面的图可以看到有很多的信息,如日志,启动目录,配置目录。。。

现在先启动nginx

cd sbin
./nginx

启动完成后,可以在浏览器输入服务器的IP即可看到如下的页面了(nginx默认代理的端口是80)

image-20220106110712049

nginx常用命令


#启动
./nginx 
#立即停止
./nginx -s stop
#平滑停止
./nginx -s quit
#重启服务
./nginx -s reload
#查看帮助
./nginx -h
#查看nginx的版本
./nginx -v
#查看版本和nginx的配置选项
./nginx -V
#测试配置文件的正确性
./nginx -t
#测试配置文件,并显示配置文件(这个命令可以快速查看配置文件)
./Nginx -T 
#测试配置文件,但是只显示错误信息
./nginx -q
#发送信号,包括停止,重新加载
./nginx -s
#设置前缀
./nginx -p
#设置配置文件
./nginx -c
#附加配置文件路径
./nginx -g

centos防火墙


1、查看防火墙状态

firewall-cmd --state

2、停止防火墙

systemctl stop firewalld.service

3、禁止开机自启

systemctl disable firewalld.service 

4、开放端口

注意在生产环境中,我们肯定是不能将防火墙关闭的,那么最好的办法是开发端口

firewall-cmd --zone=public --add-port=端口号/tcp --permanent

5、移除开放的端口

firewall-cmd --zone=public --remove-port=端口号/tcp --permanent

6、查看开放的端口

firewall-cmd --zone=public --list-ports

7、刷新防火墙

firewall-cmd --reload
举报

相关推荐

0 条评论