lnmp

lamp = linux apache mysql php   # 都是开源,可以在windows上运行


[root@foundation4 ~]# cd /var/lib/libvirt/images/
[root@foundation4 images]# ls
base.qcow2  vm1  vm2  vm3  vm3.qcow2  vm4
[root@foundation4 images]# rm -fr vm1
[root@foundation4 images]# virt-manager 
[root@foundation4 images]# qemu-img create -f qcow2 -b base.qcow2 vm1
Formatting 'vm1', fmt=qcow2 size=21474836480 backing_file=base.qcow2 cluster_size=65536 lazy_refcounts=off refcount_bits=16
[root@foundation4 images]# qemu-img info vm1
image: vm1
file format: qcow2
virtual size: 20G (21474836480 bytes)
disk size: 196K
cluster_size: 65536
backing file: base.qcow2
Format specific information:
    compat: 1.1
    lazy refcounts: false
    refcount bits: 16
    corrupt: false



[root@foundation4 images]# virsh start vm1
Domain vm1 started



[root@server1 ~]# tar zxf nginx-1.18.0.tar.gz 
[root@server1 ~]# ls
nginx-1.18.0  nginx-1.18.0.tar.gz
[root@server1 ~]# cd nginx-1.18.0
[root@server1 nginx-1.18.0]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  man  README  src
[root@server1 nginx-1.18.0]# vim auto/cc/gcc 

# debug
#CFLAGS="$CFLAGS -g"


[root@server1 nginx-1.18.0]# yum install -y gcc pcre-devel openssl-devel



[root@server1 nginx-1.18.0]# ./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module --with-http_stub_status_module --with-threads --with-file-aio



[root@server1 nginx-1.18.0]# ll Makefile 
-rw-r--r-- 1 root root 396 Aug 11 11:46 Makefile
[root@server1 nginx-1.18.0]# make && make install


[root@server1 nginx-1.18.0]# cd /usr/local/lnmp/
[root@server1 lnmp]# ls
nginx
[root@server1 lnmp]# cd nginx/
[root@server1 nginx]# ls
conf  html  logs  sbin
[root@server1 nginx]# cd sbin/
[root@server1 sbin]# ls
nginx
[root@server1 sbin]# pwd
/usr/local/lnmp/nginx/sbin

[root@server1 sbin]# ln -s /usr/local/lnmp/nginx/sbin/nginx /usr/local/bin/
[root@server1 sbin]# which nginx
/usr/local/bin/nginx
[root@server1 sbin]# nginx -t
nginx: the configuration file /usr/local/lnmp/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/lnmp/nginx/conf/nginx.conf test is successful



[root@server1 ~]# cd /usr/local/lnmp/nginx/conf/
[root@server1 conf]# ls
fastcgi.conf            koi-utf             nginx.conf           uwsgi_params
fastcgi.conf.default    koi-win             nginx.conf.default   uwsgi_params.default
fastcgi_params          mime.types          scgi_params          win-utf
fastcgi_params.default  mime.types.default  scgi_params.default
[root@server1 conf]# vim nginx.conf

[root@server1 conf]# useradd -M -d /usr/local/lnmp/nginx/ -s /sbin/nologin nginx
[root@server1 conf]# id nginx
uid=1000(nginx) gid=1000(nginx) groups=1000(nginx)
[root@server1 conf]# ps aux|grep nginx
root      6209  0.0  0.0 112708   976 pts/0    R+   11:57   0:00 grep --color=auto nginx




[root@server1 sbin]# cd /usr/local/lnmp/nginx/sbin/
[root@server1 sbin]# ls
nginx
[root@server1 sbin]# ./nginx 
[root@server1 sbin]# ps aux | grep nginx
root     13155  0.0  0.0  45880  1144 ?        Ss   12:55   0:00 nginx: master process ./nginx
nginx    13156  0.0  0.0  46340  1916 ?        S    12:55   0:00 nginx: worker process
nginx    13157  0.0  0.0  46340  1916 ?        S    12:55   0:00 nginx: worker process
nginx    13158  0.0  0.0  46340  1916 ?        S    12:55   0:00 nginx: worker process
nginx    13159  0.0  0.0  46340  1916 ?        S    12:55   0:00 nginx: worker process
root     13161  0.0  0.0 112708   972 pts/0    S+   12:55   0:00 grep --color=auto nginx










[root@server1 sbin]# cd ..
[root@server1 nginx]# cd conf/
[root@server1 conf]# vim nginx.conf



user    nginx nginx;
worker_processes auto;




[root@server1 conf]# nginx -s reload

[root@server1 ~]# lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                4
On-line CPU(s) list:   0-3
Thread(s) per core:    1
Core(s) per socket:    1
Socket(s):             4
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 58
Model name:            Intel Xeon E3-12xx v2 (Ivy Bridge, IBRS)
Stepping:              9
CPU MHz:               2594.108
BogoMIPS:              5188.21
Virtualization:        VT-x
Hypervisor vendor:     KVM
Virtualization type:   full
L1d cache:             32K
L1i cache:             32K
L2 cache:              4096K
L3 cache:              16384K
NUMA node0 CPU(s):     0-3



压测

[root@foundation4 ~]# ab -c1 -n100000 http://172.25.4.1/index.html


top - 13:35:35 up  1:03,  1 user,  load average: 0.80, 0.22, 0.11
Tasks: 125 total,   2 running, 123 sleeping,   0 stopped,   0 zombie
%Cpu0  :  0.0 us,  1.2 sy,  0.0 ni, 71.7 id,  0.0 wa,  0.0 hi, 24.8 si,  2.4 st
%Cpu1  :  0.0 us,  0.3 sy,  0.0 ni, 93.5 id,  0.0 wa,  0.0 hi,  0.0 si,  6.1 st
%Cpu2  :  1.0 us,  2.0 sy,  0.0 ni, 93.3 id,  0.0 wa,  0.0 hi,  0.0 si,  3.7 st
%Cpu3  :  9.9 us, 22.5 sy,  0.0 ni, 65.2 id,  0.0 wa,  0.0 hi,  0.0 si,  2.4 st
KiB Mem :  3880096 total,  3461532 free,    98416 used,   320148 buff/cache
KiB Swap:  2097148 total,  2097148 free,        0 used.  3522432 avail Mem 




[root@server1 ~]# cd /usr/local/lnmp/nginx/conf/
[root@server1 conf]# vim nginx.conf


user    nginx nginx;
worker_processes auto;
worker_cpu_affinity 1000;


[root@server1 conf]# nginx -s reload

[root@foundation4 ~]# ab -c1 -n100000 http://172.25.4.1/index.html


top - 13:40:07 up  1:07,  1 user,  load average: 0.82, 0.30, 0.17
Tasks: 125 total,   3 running, 122 sleeping,   0 stopped,   0 zombie
%Cpu0  :  0.0 us,  0.0 sy,  0.0 ni, 95.3 id,  0.0 wa,  0.0 hi,  0.9 si,  3.8 st
%Cpu1  :  0.0 us,  0.0 sy,  0.0 ni, 98.3 id,  0.0 wa,  0.0 hi,  0.0 si,  1.7 st
%Cpu2  :  0.0 us,  0.0 sy,  0.0 ni, 99.7 id,  0.0 wa,  0.0 hi,  0.0 si,  0.3 st
%Cpu3  : 10.5 us, 29.3 sy,  0.0 ni, 59.1 id,  0.0 wa,  0.0 hi,  0.0 si,  1.1 st






[root@server1 conf]# nginx -s reload

 14 events {
 15     worker_connections  65535;
 16 }



[root@server1 conf]# ps ax



13155 ?        Ss     0:00 nginx: master process ./nginx


[root@server1 conf]# cat /proc/13155/limits 
Limit                     Soft Limit           Hard Limit           Units     
Max cpu time              unlimited            unlimited            seconds   
Max file size             unlimited            unlimited            bytes     
Max data size             unlimited            unlimited            bytes     
Max stack size            8388608              unlimited            bytes     
Max core file size        0                    unlimited            bytes     
Max resident set          unlimited            unlimited            bytes     
Max processes             15062                15062                processes 
Max open files            1024                 4096                 files     
Max locked memory         65536                65536                bytes     
Max address space         unlimited            unlimited            bytes     
Max file locks            unlimited            unlimited            locks     
Max pending signals       15062                15062                signals   
Max msgqueue size         819200               819200               bytes     
Max nice priority         0                    0                    
Max realtime priority     0                    0                    
Max realtime timeout      unlimited            unlimited            us        



[root@server1 conf]# 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) 15062
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 15062
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited
[root@server1 conf]# vim nginx.conf



  1 user    nginx nginx;
  2 worker_processes auto;
  3 worker_cpu_affinity 1000;
  4 worker_rlimit_nofile 65535;


[root@server1 conf]# nginx -s reload


[root@server1 conf]# 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) 15062
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 15062
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited



[root@server1 conf]# cat /proc/13155/limits 
Limit                     Soft Limit           Hard Limit           Units     
Max cpu time              unlimited            unlimited            seconds   
Max file size             unlimited            unlimited            bytes     
Max data size             unlimited            unlimited            bytes     
Max stack size            8388608              unlimited            bytes     
Max core file size        0                    unlimited            bytes     
Max resident set          unlimited            unlimited            bytes     
Max processes             15062                15062                processes 
Max open files            1024                 4096                 files     
Max locked memory         65536                65536                bytes     
Max address space         unlimited            unlimited            bytes     
Max file locks            unlimited            unlimited            locks     
Max pending signals       15062                15062                signals   
Max msgqueue size         819200               819200               bytes     
Max nice priority         0                    0                    
Max realtime priority     0                    0                    
Max realtime timeout      unlimited            unlimited            us        



[root@server1 conf]# vim /etc/security/limits.conf 

nginx           -       nofile          65535



[root@server1 conf]# vim /etc/security/limits.conf 
[root@server1 conf]# sysctl -a|grep file
fs.file-max = 381622
fs.file-nr = 1024	0	381622
fs.xfs.filestream_centisecs = 3000
sysctl: reading key "net.ipv6.conf.all.stable_secret"
sysctl: reading key "net.ipv6.conf.default.stable_secret"
sysctl: reading key "net.ipv6.conf.eth0.stable_secret"
sysctl: reading key "net.ipv6.conf.lo.stable_secret"




[root@server1 conf]# sysctl net.ipv4.ip_local_port_range
net.ipv4.ip_local_port_range = 32768	60999
[root@server1 conf]# sysctl -w net.ipv4.ip_local_port_range="1024 65535"
net.ipv4.ip_local_port_range = 1024 65535
[root@server1 conf]# ll /etc/sysctl.conf 
-rw-r--r--. 1 root root 449 Aug 24  2018 /etc/sysctl.conf
[root@server1 conf]# cd /etc/sysctl.d/
[root@server1 sysctl.d]# ls
99-sysctl.conf
[root@server1 sysctl.d]# ll
total 0
lrwxrwxrwx. 1 root root 14 Aug  4 11:29 99-sysctl.conf -> ../sysctl.conf

[root@server1 sysctl.d]# vim nginx.conf


net.ipv4.ip_local_port_range = 1024 65535

[root@server1 sysctl.d]# sysctl --system
* Applying /usr/lib/sysctl.d/00-system.conf ...
* Applying /usr/lib/sysctl.d/10-default-yama-scope.conf ...
kernel.yama.ptrace_scope = 0
* Applying /usr/lib/sysctl.d/50-default.conf ...
kernel.sysrq = 16
kernel.core_uses_pid = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.promote_secondaries = 1
net.ipv4.conf.all.promote_secondaries = 1
fs.protected_hardlinks = 1
fs.protected_symlinks = 1
* Applying /etc/sysctl.d/99-sysctl.conf ...
* Applying /etc/sysctl.d/nginx.conf ...
net.ipv4.ip_local_port_range = 1024 65535
* Applying /etc/sysctl.conf ...
[root@server1 sysctl.d]# ls
99-sysctl.conf  nginx.conf
[root@server1 sysctl.d]# cd
[root@server1 ~]# sysctl net.core.somaxconn
net.core.somaxconn = 128


[root@server1 sysctl.d]# vim nginx.conf

net.ipv4.ip_local_port_range = 1024 65535
net.core.somaxconn = 2048


[root@server1 sysctl.d]# sysctl --system
* Applying /usr/lib/sysctl.d/00-system.conf ...
* Applying /usr/lib/sysctl.d/10-default-yama-scope.conf ...
kernel.yama.ptrace_scope = 0
* Applying /usr/lib/sysctl.d/50-default.conf ...
kernel.sysrq = 16
kernel.core_uses_pid = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.promote_secondaries = 1
net.ipv4.conf.all.promote_secondaries = 1
fs.protected_hardlinks = 1
fs.protected_symlinks = 1
* Applying /etc/sysctl.d/99-sysctl.conf ...
* Applying /etc/sysctl.d/nginx.conf ...
net.ipv4.ip_local_port_range = 1024 65535
* Applying /etc/sysctl.conf ...
[root@server1 sysctl.d]# ls
99-sysctl.conf  nginx.conf
[root@server1 sysctl.d]# cd
[root@server1 ~]# sysctl net.core.somaxconn
net.core.somaxconn = 128
[root@server1 ~]# vim nginx.conf
[root@server1 ~]# cd /etc/sysctl.d/
[root@server1 sysctl.d]# vim nginx.conf 
[root@server1 sysctl.d]# sysctl --system
* Applying /usr/lib/sysctl.d/00-system.conf ...
* Applying /usr/lib/sysctl.d/10-default-yama-scope.conf ...
kernel.yama.ptrace_scope = 0
* Applying /usr/lib/sysctl.d/50-default.conf ...
kernel.sysrq = 16
kernel.core_uses_pid = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.promote_secondaries = 1
net.ipv4.conf.all.promote_secondaries = 1
fs.protected_hardlinks = 1
fs.protected_symlinks = 1
* Applying /etc/sysctl.d/99-sysctl.conf ...
* Applying /etc/sysctl.d/nginx.conf ...
net.ipv4.ip_local_port_range = 1024 65535
net.core.somaxconn = 2048
* Applying /etc/sysctl.conf ...


[root@server1 sysctl.d]# sysctl net.ipv4.tcp_tw_recycle
net.ipv4.tcp_tw_recycle = 0
[root@server1 sysctl.d]# sysctl net.ipv4.tcp_tw_reuse
net.ipv4.tcp_tw_reuse = 0


net.ipv4.ip_local_port_range = 1024 65535
net.core.somaxconn = 2048
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1

[root@server1 sysctl.d]# sysctl --system
* Applying /usr/lib/sysctl.d/00-system.conf ...
* Applying /usr/lib/sysctl.d/10-default-yama-scope.conf ...
kernel.yama.ptrace_scope = 0
* Applying /usr/lib/sysctl.d/50-default.conf ...
kernel.sysrq = 16
kernel.core_uses_pid = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.promote_secondaries = 1
net.ipv4.conf.all.promote_secondaries = 1
fs.protected_hardlinks = 1
fs.protected_symlinks = 1
* Applying /etc/sysctl.d/99-sysctl.conf ...
* Applying /etc/sysctl.d/nginx.conf ...
net.ipv4.ip_local_port_range = 1024 65535
net.core.somaxconn = 2048
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
* Applying /etc/sysctl.conf ...


[root@server1 sysctl.d]# sysctl -a|wc -l
sysctl: reading key "net.ipv6.conf.all.stable_secret"
sysctl: reading key "net.ipv6.conf.default.stable_secret"
sysctl: reading key "net.ipv6.conf.eth0.stable_secret"
sysctl: reading key "net.ipv6.conf.lo.stable_secret"
796


[root@server1 sysctl.d]# sysctl -a|grep tcp
sysctl: reading key "net.ipv6.conf.all.stable_secret"
net.ipv4.tcp_abort_on_overflow = 0
net.ipv4.tcp_adv_win_scale = 1
net.ipv4.tcp_allowed_congestion_control = cubic reno
net.ipv4.tcp_app_win = 31
net.ipv4.tcp_autocorking = 1
net.ipv4.tcp_available_congestion_control = cubic reno
net.ipv4.tcp_base_mss = 512
net.ipv4.tcp_challenge_ack_limit = 1000
net.ipv4.tcp_congestion_control = cubic
net.ipv4.tcp_dsack = 1
net.ipv4.tcp_early_retrans = 3
net.ipv4.tcp_ecn = 2
net.ipv4.tcp_fack = 1
net.ipv4.tcp_fastopen = 0
net.ipv4.tcp_fastopen_key = 00000000-00000000-00000000-00000000
net.ipv4.tcp_fin_timeout = 60
net.ipv4.tcp_frto = 2
net.ipv4.tcp_invalid_ratelimit = 500
net.ipv4.tcp_keepalive_intvl = 75
net.ipv4.tcp_keepalive_probes = 9
net.ipv4.tcp_keepalive_time = 7200
net.ipv4.tcp_limit_output_bytes = 262144
net.ipv4.tcp_low_latency = 0
net.ipv4.tcp_max_orphans = 16384
net.ipv4.tcp_max_ssthresh = 0
net.ipv4.tcp_max_syn_backlog = 128
net.ipv4.tcp_max_tw_buckets = 16384
net.ipv4.tcp_mem = 88491	117991	176982
net.ipv4.tcp_min_tso_segs = 2
net.ipv4.tcp_moderate_rcvbuf = 1
net.ipv4.tcp_mtu_probing = 0
net.ipv4.tcp_no_metrics_save = 0
net.ipv4.tcp_notsent_lowat = -1
net.ipv4.tcp_orphan_retries = 0
net.ipv4.tcp_reordering = 3
net.ipv4.tcp_retrans_collapse = 1
net.ipv4.tcp_retries1 = 3
net.ipv4.tcp_retries2 = 15
net.ipv4.tcp_rfc1337 = 0
net.ipv4.tcp_rmem = 4096	87380	6291456
net.ipv4.tcp_sack = 1
net.ipv4.tcp_slow_start_after_idle = 1
net.ipv4.tcp_stdurg = 0
net.ipv4.tcp_syn_retries = 6
net.ipv4.tcp_synack_retries = 5
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_thin_dupack = 0
net.ipv4.tcp_thin_linear_timeouts = 0
net.ipv4.tcp_timestamps = 1
net.ipv4.tcp_tso_win_divisor = 3
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_wmem = 4096	16384	4194304
net.ipv4.tcp_workaround_signed_windows = 0



[root@server1 ~]# cd /usr/local/lnmp/nginx/logs/
[root@server1 logs]# ls
access.log  error.log  nginx.pid
[root@server1 logs]# ll
total 60360
-rw-r--r-- 1 root root 61800086 Aug 11 14:42 access.log
-rw-r--r-- 1 root root     1048 Aug 11 14:27 error.log
-rw-r--r-- 1 root root        6 Aug 11 12:55 nginx.pid
[root@server1 logs]# du -h access.log 
59M	access.log




[root@server1 logs]# vim /opt/nginxlog.sh




#! /bin/bash
cd /usr/local/lnmp/nginx/logs && mv access.log access_$(date +%F -d -1day).log
/usr/local/lnmp/nginx/sbin/nginx -s reload


或者


#! /bin/bash
cd /usr/local/lnmp/nginx/logs && mv access.log access_$(date +%F -d -1day).log
kill -USE1 `cat /usr/local/lnmp/nginx/logs/nginx.pid`




[root@foundation4 ~]# sysctl -a|wc -l
2354
[root@foundation4 ~]# date +%F -d -1day
2020-08-10
[root@foundation4 ~]# date
Tue Aug 11 15:25:00 CST 2020

[root@server1 logs]# cd /opt
[root@server1 opt]# ll nginxlog.sh 
-rw-r--r-- 1 root root 135 Aug 11 15:22 nginxlog.sh
[root@server1 opt]# chmod +x nginxlog.sh 
[root@server1 opt]# crontab -e
no crontab for root - using an empty one
crontab: installing new crontab

00 00 * * * /opt/nginxlog.sh &>/dev/null



[root@server1 opt]# /opt/nginxlog.sh 
[root@server1 opt]# cd /usr/local/lnmp/nginx/
[root@server1 nginx]# ll
total 0
drwx------ 2 nginx root   6 Aug 11 11:52 client_body_temp
drwxr-xr-x 2 root  root 333 Aug 11 15:17 conf
drwx------ 2 nginx root   6 Aug 11 11:52 fastcgi_temp
drwxr-xr-x 2 root  root  40 Aug 11 11:48 html
drwxr-xr-x 2 root  root  87 Aug 11 15:29 logs
drwx------ 2 nginx root   6 Aug 11 11:52 proxy_temp
drwxr-xr-x 2 root  root  19 Aug 11 11:48 sbin
drwx------ 2 nginx root   6 Aug 11 11:52 scgi_temp
drwx------ 2 nginx root   6 Aug 11 11:52 uwsgi_temp
[root@server1 nginx]# cd logs/
[root@server1 logs]# ll
total 60360
-rw-r--r-- 1 root root 61800086 Aug 11 14:42 access_2020-08-10.log
-rw-r--r-- 1 root root        0 Aug 11 15:29 access.log
-rw-r--r-- 1 root root     1113 Aug 11 15:29 error.log
-rw-r--r-- 1 root root        6 Aug 11 12:55 nginx.pid


[root@server1 logs]# vim /usr/local/lnmp/nginx/conf/nginx.conf



 30     sendfile        on;
 31     tcp_nopush     on;
 32     tcp_nodelay    on;



避免网络延迟
tcp_nopush on
tcp_nodelay on 


[root@server1 logs]# ps ax |grep nginx
13155 ?        Ss     0:00 nginx: master process ./nginx
16083 ?        S      0:00 nginx: worker process
16084 ?        S      0:00 nginx: worker process
16085 ?        S      0:00 nginx: worker process
16086 ?        S      0:00 nginx: worker process
16435 pts/0    R+     0:00 grep --color=auto nginx
[root@server1 logs]# kill 16085
[root@server1 logs]# ps ax |grep nginx
13155 ?        Ss     0:00 nginx: master process ./nginx
16083 ?        S      0:00 nginx: worker process
16084 ?        S      0:00 nginx: worker process
16086 ?        S      0:00 nginx: worker process
16461 ?        S      0:00 nginx: worker process
16467 pts/0    S+     0:00 grep --color=auto nginx










平滑升级,热部署



[root@server1 ~]# ls
nginx-1.18.0  nginx-1.18.0.tar.gz  nginx-1.19.1.tar.gz
[root@server1 ~]# tar zxf nginx-1.19.1.tar.gz 
[root@server1 ~]# ls
nginx-1.18.0  nginx-1.18.0.tar.gz  nginx-1.19.1  nginx-1.19.1.tar.gz
[root@server1 ~]# cd nginx-1.19.1
[root@server1 nginx-1.19.1]# ./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module --with-http_stub_status_module --with-threads --with-file-aio


[root@server1 nginx-1.19.1]# make


[root@server1 nginx-1.19.1]# ps ax |grep nginx
13155 ?        Ss     0:00 nginx: master process ./nginx
16083 ?        S      0:00 nginx: worker process
16084 ?        S      0:00 nginx: worker process
16086 ?        S      0:00 nginx: worker process
16461 ?        S      0:00 nginx: worker process
19463 pts/0    S+     0:00 grep --color=auto nginx
[root@server1 nginx-1.19.1]# nginx -v
nginx version: nginx/1.18.0
[root@server1 nginx-1.19.1]# ls
auto     CHANGES.ru  configure  html     Makefile  objs    src
CHANGES  conf        contrib    LICENSE  man       README
[root@server1 nginx-1.19.1]# cd objs/
[root@server1 objs]# ls
autoconf.err  nginx    ngx_auto_config.h   ngx_modules.c  src
Makefile      nginx.8  ngx_auto_headers.h  ngx_modules.o
[root@server1 objs]# ./nginx -v
nginx version: nginx/1.19.1
[root@server1 objs]# cd /usr/local/lnmp/nginx/sbin/
[root@server1 sbin]# ls
nginx
[root@server1 sbin]# cp nginx nginx.old
[root@server1 sbin]# cd -
/root/nginx-1.19.1/objs
[root@server1 objs]# ls
autoconf.err  nginx    ngx_auto_config.h   ngx_modules.c  src
Makefile      nginx.8  ngx_auto_headers.h  ngx_modules.o
[root@server1 objs]# cp -f nginx /usr/local/lnmp/nginx/sbin/
cp: overwrite ‘/usr/local/lnmp/nginx/sbin/nginx’? y
[root@server1 objs]# ls
autoconf.err  nginx    ngx_auto_config.h   ngx_modules.c  src
Makefile      nginx.8  ngx_auto_headers.h  ngx_modules.o
[root@server1 objs]# ./nginx -v
nginx version: nginx/1.19.1
[root@server1 objs]# ps ax|grep nginx
13155 ?        Ss     0:00 nginx: master process ./nginx
16083 ?        S      0:00 nginx: worker process
16084 ?        S      0:00 nginx: worker process
16086 ?        S      0:00 nginx: worker process
16461 ?        S      0:00 nginx: worker process
19691 pts/0    R+     0:00 grep --color=auto nginx
[root@server1 objs]# cd -
/usr/local/lnmp/nginx/sbin
[root@server1 sbin]# cat ../logs/nginx.pid 
13155
[root@server1 sbin]# kill -USR2 13155
[root@server1 sbin]# ps ax|grep nginx
13155 ?        Ss     0:00 nginx: master process ./nginx
16083 ?        S      0:00 nginx: worker process
16084 ?        S      0:00 nginx: worker process
16086 ?        S      0:00 nginx: worker process
16461 ?        S      0:00 nginx: worker process
19777 ?        S      0:00 nginx: master process ./nginx
19778 ?        S      0:00 nginx: worker process
19779 ?        S      0:00 nginx: worker process
19780 ?        S      0:00 nginx: worker process
19781 ?        S      0:00 nginx: worker process
19795 pts/0    S+     0:00 grep --color=auto nginx
[root@server1 sbin]# ./nginx -v
nginx version: nginx/1.19.1
[root@server1 sbin]# kill -WINCH 13155
[root@server1 sbin]# ps ax|grep nginx
13155 ?        Ss     0:00 nginx: master process ./nginx
19777 ?        S      0:00 nginx: master process ./nginx
19778 ?        S      0:00 nginx: worker process
19779 ?        S      0:00 nginx: worker process
19780 ?        S      0:00 nginx: worker process
19781 ?        S      0:00 nginx: worker process
20018 pts/0    R+     0:00 grep --color=auto nginx


[root@server1 sbin]# ls
nginx  nginx.old
[root@server1 sbin]# cp -f nginx.old nginx
cp: overwrite ‘nginx’? y
[root@server1 sbin]# ./nginx -v
nginx version: nginx/1.18.0
[root@server1 sbin]# kill -HUP 13155
[root@server1 sbin]# ps ax|grep nginx
13155 ?        Ss     0:00 nginx: master process ./nginx
19777 ?        S      0:00 nginx: master process ./nginx
19778 ?        S      0:00 nginx: worker process
19779 ?        S      0:00 nginx: worker process
19780 ?        S      0:00 nginx: worker process
19781 ?        S      0:00 nginx: worker process
20172 ?        S      0:00 nginx: worker process
20173 ?        S      0:00 nginx: worker process
20174 ?        S      0:00 nginx: worker process
20175 ?        S      0:00 nginx: worker process
20180 pts/0    R+     0:00 grep --color=auto nginx
[root@server1 sbin]# kill -WINCH 19777
[root@server1 sbin]# ps ax|grep nginx
13155 ?        Ss     0:00 nginx: master process ./nginx
19777 ?        S      0:00 nginx: master process ./nginx
20172 ?        S      0:00 nginx: worker process
20173 ?        S      0:00 nginx: worker process
20174 ?        S      0:00 nginx: worker process
20175 ?        S      0:00 nginx: worker process
20216 pts/0    S+     0:00 grep --color=auto nginx
[root@server1 sbin]# kill -QUIT 19777
[root@server1 sbin]# ps ax|grep nginx
13155 ?        Ss     0:00 nginx: master process ./nginx
20172 ?        S      0:00 nginx: worker process
20173 ?        S      0:00 nginx: worker process
20174 ?        S      0:00 nginx: worker process
20175 ?        S      0:00 nginx: worker process
20255 pts/0    R+     0:00 grep --color=auto nginx



[root@server1 sbin]# nginx -v
nginx version: nginx/1.18.0



reload 


[root@server1 sbin]# vim /usr/local/lnmp/nginx/conf/nginx.conf

 47         location / {
 48             root   html;
 49             index  index.html index.htm;
 50         }
 51 
 52         location /status {
 53             stub_status;
 54         }


[root@server1 sbin]# nginx -s reload


网页测试:


[root@server1 sbin]# cat /usr/local/lnmp/nginx/logs/access.log 

 52         location /status {
 53             stub_status;
 54             access_log off;
 55         }


[root@server1 sbin]# vim /usr/local/lnmp/nginx/conf/nginx.conf
[root@server1 sbin]# nginx -t
nginx: the configuration file /usr/local/lnmp/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/lnmp/nginx/conf/nginx.conf test is successful
[root@server1 sbin]# nginx -s reload

网页访问

[root@server1 sbin]# cd /etc/pki/tls/certs/
[root@server1 certs]# ls
ca-bundle.crt  ca-bundle.trust.crt  make-dummy-cert  Makefile  renew-dummy-cert
[root@server1 certs]# make cert.pem
umask 77 ; \
PEM1=`/bin/mktemp /tmp/openssl.XXXXXX` ; \
PEM2=`/bin/mktemp /tmp/openssl.XXXXXX` ; \
/usr/bin/openssl req -utf8 -newkey rsa:2048 -keyout $PEM1 -nodes -x509 -days 365 -out $PEM2  ; \
cat $PEM1 >  cert.pem ; \
echo ""    >> cert.pem ; \
cat $PEM2 >> cert.pem ; \
rm -f $PEM1 $PEM2
Generating a 2048 bit RSA private key
....................................................................................................+++
...................................................+++
writing new private key to '/tmp/openssl.ZSPRv9'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:cn
State or Province Name (full name) []:shaanxi
Locality Name (eg, city) [Default City]:xi'an
Organization Name (eg, company) [Default Company Ltd]:westos
Organizational Unit Name (eg, section) []:linux
Common Name (eg, your name or your server's hostname) []:server1
Email Address []:root@localhost



[root@server1 certs]# mv cert.pem /usr/local/lnmp/nginx/conf/

[root@server1 sbin]# vim /usr/local/lnmp/nginx/conf/nginx.conf




107     server {
108         listen       443 ssl;
109         server_name  localhost;
110 
111         ssl_certificate      cert.pem;
112         ssl_certificate_key  cert.pem;
113 
114         ssl_session_cache    shared:SSL:1m;
115         ssl_session_timeout  5m;
116 
117         ssl_ciphers  HIGH:!aNULL:!MD5;
118         ssl_prefer_server_ciphers  on;
119 
120         location / {
121             root   html;
122             index  index.html index.htm;
123         }
124     }
125 
126 }


[root@server1 certs]# nginx -t
nginx: the configuration file /usr/local/lnmp/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/lnmp/nginx/conf/nginx.conf test is successful
[root@server1 certs]# nginx -s reload



 37     #gzip  on;
 38 
 39         limit_conn_zone $binary_remote_addr zone=addr:10m;
 40 
 41     server {
 42         listen       80;
 43         server_name  localhost;
 44 
 45         #charset koi8-r;
 46 
 47         #access_log  logs/host.access.log  main;
 48 
 49         location / {
 50                 limit_conn      addr 1;
 51 }


[root@server1 certs]# nginx -t
nginx: the configuration file /usr/local/lnmp/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/lnmp/nginx/conf/nginx.conf test is successful
[root@server1 certs]# nginx -s reload

[root@foundation4 Downloads]# ab -c10 -n10 http://172.25.4.1/index.html
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 172.25.4.1 (be patient).....done


Server Software:        nginx/1.18.0
Server Hostname:        172.25.4.1
Server Port:            80

Document Path:          /index.html
Document Length:        612 bytes

Concurrency Level:      10
Time taken for tests:   0.002 seconds
Complete requests:      10
Failed requests:        0
Total transferred:      8450 bytes
HTML transferred:       6120 bytes
Requests per second:    6161.43 [#/sec] (mean)
Time per request:       1.623 [ms] (mean)
Time per request:       0.162 [ms] (mean, across all concurrent requests)
Transfer rate:          5084.38 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:     0    0   0.1      0       1
Waiting:        0    0   0.1      0       1
Total:          1    1   0.1      1       1

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      1
  75%      1
  80%      1
  90%      1
  95%      1
  98%      1
  99%      1
 100%      1 (longest request)


[root@server1 certs]# cd /usr/local/lnmp/nginx/html/
[root@server1 html]# mkdir download
[root@server1 html]# cd download/
[root@server1 download]# ls
123.png  456.png  redhat.png  test1.png  test.png  virt.png  westos.png  wwy.png

[root@foundation4 ~]# ab -c1 -n10 http://172.25.4.1/download/123.png


 49         location /download {
 50                 limit_conn      addr 1;
 51                 limit_rate      50k;
 52 }


[root@server1 download]# vim /usr/local/lnmp/nginx/conf/nginx.conf
[root@server1 download]# nginx -t
nginx: the configuration file /usr/local/lnmp/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/lnmp/nginx/conf/nginx.conf test is successful
[root@server1 download]# nginx -s reload


 49         location / {
 50         root html;
 51         index index.html index.htm;
 52         limit_req zone=one;
 53 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值