##nginx
安装:
先get一个安装包(官网)
tar zxf nginx-1.14.2.tar.gz ##解压安装包
cd nginx-1.14.2
cd auto/
cd cc
vim gcc
将debug 安装取消
yum install gcc -y
yum install pcre-devel -y
yum install openssl-devel -y
##下载关联软件
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module
make && make install
cd /usr/lolscal/
ls
cd nginx/
master管理worker 根据进程的请求调用一个线程(可以共享资源)
进程不能共享资源
保护现场和恢复现场
cpu的绑定
利用nginx做反向代理
在server1和server2上配置好httpd服务
在server3上配置nginx服务
增加server3的cpu数量至4个
[root@server3 ~]# cd /usr/local/nginx/conf/
[root@server3 conf]# vim nginx.conf
1
2 user nginx nginx; ##两个nginx 一个用户 一个组
3 worker_processes 4;
4 worker_cpu_affinity 0001 0010 0100 1000; ##4个cpu
5
6 #error_log logs/error.log;
7 #error_log logs/error.log notice;
8 #error_log logs/error.log info;
9
10 #pid logs/nginx.pid;
11
12
13 events {
14 worker_connections 65535; ##设定打开文件最大数量
15 }
16
17
18 http {
19 include mime.types;
20 default_type application/octet-stream;
21 upstream westos{
22 server 172.25.20.1:80;
23 server 172.25.20.2:80; ##配置反向代理服务
24 }
121 server {
122 listen 80;
123 server_name www.westos.org;
124 location / {
125 proxy_pass http://westos;
126 }
127 }
ulimit -n 65535
ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 7817
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 65535
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 7817
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
[root@server3 conf]# nginx -s reload
[root@server3 conf]# ps aux |grep nginx ##查看nginx打开的进程
root 1176 0.0 0.1 47408 1924 ? Ss 11:48 0:00 nginx: master process nginx
nginx 1194 0.1 2.8 74544 28656 ? S 11:54 0:00 nginx: worker process
nginx 1195 0.2 2.8 74544 28656 ? S 11:54 0:00 nginx: worker process
nginx 1196 0.3 2.8 74544 28656 ? S 11:54 0:00 nginx: worker process
nginx 1197 0.2 2.8 74544 28656 ? S 11:54 0:00 nginx: worker process
root 1199 0.0 0.0 103244 852 pts/0 R+ 11:54 0:00 grep nginx
在真机上:
做好本地解析
curl www.westos.org
##粘性实验
在servre3上:
vim nginx.conf
18 http {
19 include mime.types;
20 default_type application/octet-stream;
21 upstream westos{
22 ip_hash;
23 server 172.25.20.1:80;
24 server 172.25.20.2:80;
25 }
开启server1和2的httpd服务,在真机上访问curl www.westos.org
它会随机粘上一个服务器,关掉之后即可访问到第二个服务器
server1和server2执行相同的工作,如果工作的服务器down机,另外一台会直接顶上
##更改nginx的默认发布文件
进入/usr/local/nginx/html
更改index.html
更改配置文件
18 http {
19 include mime.types;
20 default_type application/octet-stream;
21 upstream westos{
22 server 172.25.20.1:80;
23 server 172.25.20.2:80;
24 server 127.0.0.1:80 backup;
25 }
26
关闭server1和2的httpd服务,添加本地解析
在真机上访问
[root@foundation20 kiosk]# curl www.westos.org
即可看到默认发布文件