准备环境
Linux操作系统 |
IP地址 |
功能 |
Centos7 |
192.168.1.20 |
nginx_server+keepalived |
Centos7 |
192.168.1.21 |
nginxbackup+keepalived |
Centos7 |
192.168.1.22 |
woker2 |
Centos7 |
192.168.1.23 |
woker3 |
部署安装
源码安装
四台机全部安装
1.下载nginx压缩包
wget -c http://nginx.org/download/nginx-1.16.1.tar.gz
2.解压缩nginx包
tar -zxvf nginx-1.20.2.tar.gz
3.进入nginx目录
cd nginx-1.20.2
4.安装依赖关系包
yum install gcc*
5.测试依赖关系并指定安装目录
./configure --prefix=/usr/local/nginx
6.编译并安装
make && make install
7.封装nginx服务
vi /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx - web server
After=network.target remote-fs.target nss-1ookup.target
[Service]
Type=forking
PIDFi1e=/usr/local/nginx/1ogs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecQuit=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
8,自启动nginx
systemctl start nginx && systemctl enable nginx
/usr/local/nginx/ 主要文件目录
html web展示页面
logs 日志
conf 配置文件
yum安装
1.添加epel源
yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
2.安装nginx
yum install nginx -y
3.查看安装目录
rpm -ql nginx
nginx配置文件
最小配置
worker_processes
worker_processes 1; 默认为1,表示开启一个业务进程
worker_connections
worker_connections 1024; 单个业务进程可接受连接数
include mime.types;
include mime.types; 引入http mime类型
default_type application/octet-stream;
default_type application/octet-stream; 如果mime类型没匹配上,默认使用二进制流的方式传输。
sendfile on;
sendfile on; 使用linux的 sendfile