nginx启动

web是什么?

nginx 是什么?
http://nginx.org/

nginx是一个做网站服务器的软件,是一个静态的网站
html 写前端静态页面的语言
python,java,php,go等动态语言,写后端的,就是和数据库进行交互

HTTP:就是一个传输网页的协议,在浏览器和服务器(nginx,tomcat)软件之间通信的协议理解为语言,用来交流

reverse proxy server
TCP/UDP

[root@sanchuang ~]# cat  /etc/centos-release   查看linux的版本
CentOS Linux release 8.2.2004 (Core) 
[root@sanchuang ~]# uname -r                查看linux的内核版本
4.18.0-193.el8.x86_64
[root@sanchuang ~]# curl -O http://nginx.org/download/nginx-1.21.4.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 1045k  100 1045k    0     0   487k      0  0:00:02  0:00:02 --:--:--  487k
[root@sanchuang ~]#
=======
curl 是linux里的字符界面的浏览器
wget 是linux里的迅雷
wget 也是一个下载软件,也支持http协议,可以去网站下载软件

nginx安装:

​ 1、yum安装:
​ 到nginx或者centos的官方去下载nginx的软件包安装
​ 快捷、方便、高效

​ 2、编译安装:
​ nginx是使用C语言编写的,将源码编译成二进制程序,然后安装
​ 需要自己解决软件之间的依赖关系,还需要指定很多的配置,难度大,可以定制开启需要的功能–》可以定制功能和指定安装的路径

编译安装经典的3部曲:
1、编译前的配置:选款式(西式),面料,颜色,量尺寸–》定制的方案–》文件
./configure --》生成一个叫做Makefile --》方案 --》设计图纸

2、编译
理解为讲源代码编译成二进制程序 --》做衣服
3、编译安装
将已经编译好的二进制程序安装(cp)到指定的路径 --》交付衣服给客户

拿衣服:

​ 1、去专卖店
​ yum安装
​ 衣服的款式、颜色、面料、大小等都已经固定了
​ 2、去裁缝店
​ 看款式、颜色、面料、量尺寸等,还要等一段时间才能拿到衣服

[root@peng nginx-1.21.4]# ./configure --help

 --prefix=PATH         set installation prefix  指定安装路径
 
 --with-mail                        enable POP3/IMAP4/SMTP proxy module  开启
 --with-http_ssl_module             enable ngx_http_ssl_module  开启
 
 --without-http                     disable HTTP server  禁用http
 
[root@sanchuang sclilin99]# ls
conf  html  logs  sbin
[root@sanchuang sclilin99]#
conf 存放nginx的配置文件
html 存放网站的网页的目录
     [root@sanchuang sclilin99]# cd html
     [root@sanchuang html]# ls
     50x.html  index.html
     [root@sanchuang html]# 
     index.html 首页:进入某个网站看到的第一个页面
     链接:通过首页里的链接跳到其他的页面

logs 存放日志
sbin  存放nginx的启动程序的
[root@peng ~]# ps aux |grep nginx   查看nginx的进程
root        1472  0.0  0.0  43424   844 ?        Ss   10:37   0:00 nginx: master process nginx
penglin+    1473  0.0  0.2  76968  4064 ?        S    10:37   0:00 nginx: worker process
root        6825  0.0  0.0  12344  1124 pts/1    R+   19:04   0:00 grep --color=auto nginx
[root@peng ~]# nginx -s stop    关闭nginx
[root@peng ~]# ps aux |grep nginx
root        6828  0.0  0.0  12344  1116 pts/1    R+   19:04   0:00 grep --color=auto nginx
[root@peng ~]# nginx
[root@peng ~]# ps aux |grep nginx
root        6830  0.0  0.0  43424   884 ?        Ss   19:05   0:00 nginx: master process nginx
penglin+    6831  0.0  0.2  76968  5332 ?        S    19:05   0:00 nginx: worker process
root        6833  0.0  0.0  12344  1160 pts/1    R+   19:05   0:00 grep --color=auto nginx
[root@peng ~]# kill -9 6831  关闭了子进程,master父进程又会重新启动一个子进程
[root@peng ~]# ps aux |grep nginx
root        6830  0.0  0.0  43424   884 ?        Ss   19:05   0:00 nginx: master process nginx
penglin+    6834  0.0  0.2  76968  5268 ?        S    19:06   0:00 nginx: worker process
root        6836  0.0  0.0  12344  1140 pts/1    R+   19:06   0:00 grep --color=auto nginx
[root@peng ~]# kill -9 6830
[root@peng ~]# ps aux |grep nginx
penglin+    6834  0.0  0.2  76968  5268 ?        S    19:06   0:00 nginx: worker process
root        6838  0.0  0.0  12344  1140 pts/1    R+   19:06   0:00 grep --color=auto nginx
[root@peng ~]# kill -9 6834
[root@peng ~]# ps aux |grep nginx
root        6840  0.0  0.0  12344  1044 pts/1    R+   19:06   0:00 grep --color=auto nginx
[root@peng ~]# 
[root@peng ~]# nginx
[root@peng ~]# pstree -p   查看两个nginx之间的关系
systemd(1)─┬─NetworkManager(874)─┬─{NetworkManager}(892)
           │                     └─{NetworkManager}(893)
           ├─VGAuthService(871)
           ├─atd(1068)
           ├─auditd(845)───{auditd}(846)
           ├─chronyd(880)
           ├─crond(1071)
           ├─dbus-daemon(867)
           ├─login(6389)───bash(6392)
           ├─mysqld_safe(1699)───mysqld(1863)─┬─{mysqld}(1864)
           │                                  ├─{mysqld}(1865)
           │                                  ├─{mysqld}(1866)
           │                                  ├─{mysqld}(1867)
           │                                  ├─{mysqld}(1868)
           │                                  ├─{mysqld}(1869)
           │                                  ├─{mysqld}(1870)
           │                                  ├─{mysqld}(1871)
           │                                  ├─{mysqld}(1872)
           │                                  ├─{mysqld}(1873)
           │                                  ├─{mysqld}(1874)
           │                                  ├─{mysqld}(1875)
           │                                  ├─{mysqld}(1877)
           │                                  ├─{mysqld}(1878)
           │                                  ├─{mysqld}(1879)
           │                                  ├─{mysqld}(1880)
           │                                  ├─{mysqld}(1881)
           │                                  ├─{mysqld}(1882)
           │                                  ├─{mysqld}(1883)
           │                                  ├─{mysqld}(1884)
           │                                  ├─{mysqld}(1885)
           │                                  ├─{mysqld}(1886)
           │                                  ├─{mysqld}(1887)
           │                                  ├─{mysqld}(1888)
           │                                  ├─{mysqld}(1889)
           │                                  ├─{mysqld}(1890)
           │                                  └─{mysqld}(4901)
           ├─nginx(6844)───nginx(6845)
           ├─polkitd(870)─┬─{polkitd}(891)
           │              ├─{polkitd}(897)
           │              ├─{polkitd}(899)
           │              ├─{polkitd}(900)
           │              └─{polkitd}(927)
           ├─rngd(881)───{rngd}(889)
           ├─rsyslogd(963)─┬─{rsyslogd}(1391)
           │               └─{rsyslogd}(1393)
           ├─sshd(894)─┬─sshd(6464)───sshd(6466)───bash(6467)───pstree(6846)
           │           └─sshd(6475)───sshd(6490)───sftp-server(6491)
           ├─sssd(869)─┬─sssd_be(902)
           │           └─sssd_nss(922)
           ├─systemd(1399)───(sd-pam)(1403)
           ├─systemd-journal(722)
           ├─systemd-logind(1052)
           ├─systemd-udevd(752)
           ├─tuned(895)─┬─{tuned}(1208)
           │            ├─{tuned}(1210)
           │            └─{tuned}(1211)
           └─vmtoolsd(872)─┬─{vmtoolsd}(912)
                           └─{vmtoolsd}(916)
[root@peng ~]# ps aux |grep nginx
root        6844  0.0  0.0  43424   884 ?        Ss   19:12   0:00 nginx: master process nginx
penglin+    6845  0.0  0.2  76968  5216 ?        S    19:12   0:00 nginx: worker process
root        6848  0.0  0.0  12344  1148 pts/1    R+   19:12   0:00 grep --color=auto nginx
[root@peng ~]# 

[root@peng ~]# ps aux |grep nginx
root        6844  0.0  0.0  43424   884 ?        Ss   19:12   0:00 nginx: master process nginx
penglin+    6845  0.0  0.2  76968  5216 ?        S    19:12   0:00 nginx: worker process
root        6848  0.0  0.0  12344  1148 pts/1    R+   19:12   0:00 grep --color=auto nginx
[root@peng ~]# kill -quit 6844
[root@peng ~]# ps aux |grep nginx
root        6851  0.0  0.0  12344  1184 pts/1    R+   19:16   0:00 grep --color=auto nginx
[root@peng ~]# nginx
[root@peng ~]# ps aux |grep nginx
root        6853  0.0  0.0  43424   884 ?        Ss   19:16   0:00 nginx: master process nginx
penglin+    6854  0.0  0.2  76968  5296 ?        S    19:16   0:00 nginx: worker process
root        6856  0.0  0.0  12344  1048 pts/1    R+   19:16   0:00 grep --color=auto nginx
[root@peng ~]# kill -quit 6854
[root@peng ~]# ps aux |grep nginx
root        6853  0.0  0.0  43424   884 ?        Ss   19:16   0:00 nginx: master process nginx
penglin+    6857  0.0  0.2  76968  5296 ?        S    19:16   0:00 nginx: worker process
root        6859  0.0  0.0  12344  1140 pts/1    R+   19:16   0:00 grep --color=auto nginx
[root@peng ~]# kill -term 6853
[root@peng ~]# ps aux |grep nginx
root        6875  0.0  0.0  12344  1124 pts/1    R+   19:17   0:00 grep --color=auto nginx
[root@peng ~]# 

进程和进程之间通信的方式
1.信号
2.信号量
3.管道
4.共享内存
5.socket
6.消息队列

[root@peng ~]# kill -l
 1) SIGHUP	 2) SIGINT	 3) SIGQUIT	 4) SIGILL	 5) SIGTRAP
 6) SIGABRT	 7) SIGBUS	 8) SIGFPE	 9) SIGKILL	10) SIGUSR1
11) SIGSEGV	12) SIGUSR2	13) SIGPIPE	14) SIGALRM	15) SIGTERM
16) SIGSTKFLT	17) SIGCHLD	18) SIGCONT	19) SIGSTOP	20) SIGTSTP
21) SIGTTIN	22) SIGTTOU	23) SIGURG	24) SIGXCPU	25) SIGXFSZ
26) SIGVTALRM	27) SIGPROF	28) SIGWINCH	29) SIGIO	30) SIGPWR
31) SIGSYS	34) SIGRTMIN	35) SIGRTMIN+1	36) SIGRTMIN+2	37) SIGRTMIN+3
38) SIGRTMIN+4	39) SIGRTMIN+5	40) SIGRTMIN+6	41) SIGRTMIN+7	42) SIGRTMIN+8
43) SIGRTMIN+9	44) SIGRTMIN+10	45) SIGRTMIN+11	46) SIGRTMIN+12	47) SIGRTMIN+13
48) SIGRTMIN+14	49) SIGRTMIN+15	50) SIGRTMAX-14	51) SIGRTMAX-13	52) SIGRTMAX-12
53) SIGRTMAX-11	54) SIGRTMAX-10	55) SIGRTMAX-9	56) SIGRTMAX-8	57) SIGRTMAX-7
58) SIGRTMAX-6	59) SIGRTMAX-5	60) SIGRTMAX-4	61) SIGRTMAX-3	62) SIGRTMAX-2
63) SIGRTMAX-1	64) SIGRTMAX	

  1. SIGHUP
    nohup可以用来屏蔽hup信号
    通常是在终端的控制进程结束时, 通知同一session内的各个作业停止运行
    登录Linux时,系统会分配给登录用户一个终端(Session)。在这个终端运行的所有程序,包括前台进程组和后台进程组,一般都 属于这个 Session。当用户退出Linux登录时,前台进程组和后台有对终端输出的进程将会收到SIGHUP信号。这个信号的默认操作为终止进程,因此前台进 程组和后台有终端输出的进程就会中止。
    nohup bash while.sh &

  2. SIGINT
    程序终止(interrupt)信号, 在用户键入INTR字符(通常是Ctrl-C)时发出,用于通知前台进程组终止进程。

9)SIGKILL

用来立即结束程序的运行,本信号不能被阻塞,处理和忽略
告诉linux内核去强制杀死进程

3)SIGQUIT
其实可以理解为中断程序正常的运行,同时也会给子进程也终止

  1. SIGTERM

​ 程序结束(terminate)信号,
​ 与SIGKILL不同的是该信号可以被阻塞和处理。通常用来要求程序自己正常退出,shell命令Kill缺省产生这个信号

trap 屏幕各种信号,唯独9这种信号不能被屏蔽
[root@slave-mysql linlin99]# cat while.sh 
trap "echo i am busy"  15 3 2 1 9
i=1
while :
do
	echo $i
	((i++))
	sleep 1
done
[root@slave-mysql linlin99]# 

netstat 查看本机开放那些端口
LISTEN 监听,理解为打开了某个端口,别人可以访问过来
ESTABLISHED 别人已经连接上了某个端口

[root@peng lianxi]# netstat -anplut
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      19258/nginx: master 
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      894/sshd            
tcp        0      0 192.168.218.131:22      192.168.218.1:54040     ESTABLISHED 6475/sshd: root [pr 
tcp        0      0 192.168.218.131:22      192.168.218.1:58896     ESTABLISHED 8595/sshd: root [pr 
tcp        0     36 192.168.218.131:22      192.168.218.1:58895     ESTABLISHED 8586/sshd: root [pr 
tcp        0      0 192.168.218.131:22      192.168.218.1:54039     ESTABLISHED 6464/sshd: root [pr 
tcp6       0      0 :::3306                 :::*                    LISTEN      1863/mysqld         
tcp6       0      0 :::22                   :::*                    LISTEN      894/sshd            
udp        0      0 192.168.218.131:68      192.168.218.254:67      ESTABLISHED 874/NetworkManager  
udp        0      0 127.0.0.1:323           0.0.0.0:*                           880/chronyd         
udp6       0      0 ::1:323                 :::*                                880/chronyd         
[root@peng lianxi]# 
[root@peng lianxi]# ss -anplut   查看打开了哪些端口(只能查看listen,不能查看ESTABLISHED )
Netid State  Recv-Q Send-Q  Local Address:Port   Peer Address:Port                                                            
udp   UNCONN 0      0           127.0.0.1:323         0.0.0.0:*     users:(("chronyd",pid=880,fd=6))                          
udp   UNCONN 0      0               [::1]:323            [::]:*     users:(("chronyd",pid=880,fd=7))                          
tcp   LISTEN 0      128           0.0.0.0:80          0.0.0.0:*     users:(("nginx",pid=19259,fd=9),("nginx",pid=19258,fd=9)) 
tcp   LISTEN 0      128           0.0.0.0:22          0.0.0.0:*     users:(("sshd",pid=894,fd=4))                             
tcp   LISTEN 0      80                  *:3306              *:*     users:(("mysqld",pid=1863,fd=18))                         
tcp   LISTEN 0      128              [::]:22             [::]:*     users:(("sshd",pid=894,fd=6))                             
[root@peng lianxi]# 

[root@peng lianxi]# lsof -i:80   查看哪些服务监听了80端口  
COMMAND   PID      USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   19258      root    9u  IPv4 114987      0t0  TCP *:http (LISTEN)
nginx   19259 penglinxi    9u  IPv4 114987      0t0  TCP *:http (LISTEN)
[root@peng lianxi]# 

[root@slave-mysql ~]# service firewalld stop  立即关闭防火墙
Redirecting to /bin/systemctl stop firewalld.service
[root@slave-mysql ~]# service firewalld status  查看防火墙服务的状态
Redirecting to /bin/systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset:>
   Active: inactive (dead)
     Docs: man:firewalld(1)

[root@slave-mysql ~]# systemctl disable  firewalld  设置firewalld 服务开机不启动,下一次开机不启动
root@slave-mysql logs]# ls
access.log  error.log  nginx.pid
[root@slave-mysql logs]# 

access.log 正常的访问日志
error.log  访问出错的日志
nginx.pid   里面存放master进程的进程号 
[root@peng logs]# cat nginx.pid 
19258
[root@peng logs]# ps aux|grep nginx
root       19258  0.0  0.0  43424   884 ?        Ss   21:25   0:00 nginx: master process nginx
penglin+   19259  0.0  0.2  76968  5204 ?        S    21:25   0:00 nginx: worker process
root       22641  0.0  0.0  12344  1156 pts/1    R+   21:53   0:00 grep --color=auto nginx
[root@peng logs]# 

判断nginx是否启动:

1、看端口

​ netstat -anplut

​ lsof -i :80

​ ss -anplut

2、看进程

ps aux |grep nginx

3、直接访问

4、看日志 tail -f access.log

中间业务会有中断
nginx -s quit
nginx

不会中断业务,相当于刷新服务,启动新的配置
nginx -s reload

[root@peng conf]# ps aux|grep nginx   
root       19258  0.0  0.2  43568  4024 ?        Ss   21:25   0:00 nginx: master process nginx
penglin+   29474  0.0  0.2  77108  5336 ?        S    22:49   0:00 nginx: worker process
penglin+   29475  0.0  0.2  77108  5336 ?        S    22:49   0:00 nginx: worker process
penglin+   29476  0.0  0.2  77108  5336 ?        S    22:49   0:00 nginx: worker process
penglin+   29477  0.0  0.2  77108  5336 ?        S    22:49   0:00 nginx: worker process
root       29483  0.0  0.0  12344  1048 pts/1    R+   22:49   0:00 grep --color=auto nginx
[root@peng conf]# nginx -s reload  master进程不产生新的,worker进程会产生新的
[root@peng conf]# ps aux|grep nginx
root       19258  0.0  0.2  43492  4096 ?        Ss   21:25   0:00 nginx: master process nginx
penglin+   30416  0.0  0.2  77080  5220 ?        S    22:56   0:00 nginx: worker process
penglin+   30417  0.0  0.2  77080  5220 ?        S    22:56   0:00 nginx: worker process
penglin+   30418  0.0  0.2  77080  5220 ?        S    22:56   0:00 nginx: worker process
penglin+   30419  0.0  0.2  77080  5220 ?        S    22:56   0:00 nginx: worker process
root       30427  0.0  0.0  12344  1148 pts/1    R+   22:56   0:00 grep --color=auto nginx
[root@peng conf]# 

nginx.conf 是nginx的主配置文件
nginx.conf的作用:其实就是给nginx进程传递参数的,告诉nginx如何按照人的要求去运行

6 0:00 nginx: worker process
penglin+ 30418 0.0 0.2 77080 5220 ? S 22:56 0:00 nginx: worker process
penglin+ 30419 0.0 0.2 77080 5220 ? S 22:56 0:00 nginx: worker process
root 30427 0.0 0.0 12344 1148 pts/1 R+ 22:56 0:00 grep --color=auto nginx
[root@peng conf]#


nginx.conf  是nginx的主配置文件
nginx.conf的作用:其实就是给nginx进程传递参数的,告诉nginx如何按照人的要求去运行

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-O1iOXkID-1644415019540)(C:\Users\xixi\AppData\Roaming\Typora\typora-user-images\image-20220117225432637.png)]
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值