nginx

一、nginx的安装

1.安装插件

yum install -y gcc

yum install -y pcre-devel

yum install -y openssl-devel

2.安装nginx

1.lftp 172.25.254.250 -->get nginx-1.20.1.tar.gz	下载安装包
2.tar zxf nginx-1.20.1.tar.gz							解压
3vim /root/nginx-1.20.1/auto/cc/gcc					关闭debug
	#debug
	#CFLAGS="$CFLAGS -g"	
4./configure --prefix=/usr/local/nginx --with-threads --with-file-aio --with-http_ssl_module --with-http_stub_status_module	编译
5.make	
6.make install 

3.修改nginx配置文件

1、ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ 建立软链接开启全局nginx

2、which nginx
3、nginx -t                                                检测语法
4、nginx                                                    开启服务
5、netstat -antlp                                            查看端口
6、ps ax | grep nginx                                        查看进程
7、useradd -d /usr/local/nginx/ -M -s /sbin/nologin nginx    建立nginx的管理用户
8、vim /usr/local/nginx/conf/nginx.conf                     编辑初始化配置文件
    user  nginx;                        管理用户
    worker_processes  2或者auto;            工作进程数,不得大于cpu内核数
    
          worker_connections  65535;        单个工作进程并发连接数
    }
    
9、vim /etc/security/limits.conf
    nginx - nofile 65536                                worker进程的最大打开文件数限制,大于单个工作进程并发连接数
10、nginx -s reload                                            重置服务不报错
11、nginx -s stop                                            停止服务
12、cd /usr/lib/systemd/system                                开启systemd启动
13、vim nginx.service    
    [Unit]                                        对服务的说明
    Description=The NGINX HTTP and reverse proxy server    描述服务
    After=syslog.target network.target remote-fs.target nss-lookup.target        描述服务类别

    [Service]                                    服务的一些具体运行参数的设置
    Type=forking                                后台运行的形式
    PIDFile=/usr/local/nginx/logs/nginx.pid        PID文件的路径
    ExecStartPre=/usr/local/sbin/nginx -t        启动准备
    ExecStart=/usr/local/sbin/nginx                启动命令
    ExecReload=/usr/local/sbin/nginx -s reload    重启命令
    ExecStop=/bin/kill -s QUIT $MAINPID            停止命令
    PrivateTmp=true                                给服务分配临时空间

    [Install]
    WantedBy=multi-user.target                    服务用户的模式    

systemctl daemon-reload                            刷新服务列表
systemctl enable --now nginx.service            启动服务
systemctl status nginx                            查看nginx状态
vim /usr/local/nginx/html/index.html
nginx -s reload

二、并发优化

Linux下高并发socket最大连接数所受的各种限制
修改用户进程可打开文件数限制
/etc/security/limits.conf
nginx - nofile 65535
Linux系统级的最大打开文件数限制
fs.file-max = 188414		//和内存容量相关
修改网络内核对TCP连接的有关限制
net.ipv4.ip_local_port_range = 1024	65535
限制接收新 TCP 连接侦听队列的大小
net.core.somaxconn = 2048

 三、负载均衡+反向代理

vim /usr/local/nginx/conf/nginx.conf

 

真机中做域名解析

 然后分别在server2和server3中设置配置

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值