linux系統開機流程和啟動nginx


開機啟動流程

CentOS6

1.內核引導

加電自檢,檢查bios的配置,檢測硬件,開機

2.運行init

  • 0:關機
  • 1:單用戶模式
  • 2:多用戶模式(沒有文件系統和網絡)
  • 3:多用戶模式(命令行,默認模式)
  • 4:沒有使用的模式
  • 5:多用戶模式(圖形化界面)
  • 6:重啟

3.系統初始化

4.建立終端

5.用戶登錄

## 關機命令
init 0
halt
shutdown -h now
shutdown -h 20:20
shutdown -h +10
poweroff

## 重啟命令
init 6
reboot
shutdown -r now
shutdonw -r 20:20
shutdown -r +10

CentOS7開機啟動流程

1.BIOS(開機自檢)
2.MBR ( Master Boot Record 主引導記錄)
3.GRUB2 Bootloader(引導菜單)
4.Kernel(內核引導)
5.Systemd (不再使用init,改成了systemd)

6.Runlevel-Target (運行級別)

運行級別:

init 0.target -> poweroff.target		# 關機
init 1.target -> rescue.target			# 單用戶模式
init 2.target -> multi-user.target		# 多用戶模式(沒有文件系統和網絡)
init 3.target -> multi-user.target		# 多用戶模式(命令行)
init 4.target -> multi-user.target		# 多用戶模式(還是沒有被使用)		
init 5.target -> graphical.target		# 圖形化模式
init 6.target -> reboot.target			# 重啟
# 獲取當前默認的運行級別
[root@qls ~]# systemctl get-default
multi-user.target

# 修改運行級別
[root@qls ~]# systemctl set-default poweroff

## 使用兩條命令修改默認運行級別
[root@qls ~]# rm -f /etc/systemd/system/default.target
[root@qls ~]# ln -s /usr/lib/systemd/system/poweroff.target /etc/systemd/system/default.target


## 相關目錄
[root@qls ~]# ll /etc/systemd/system   (默認的運行級別)
[root@qls ~]# ll /usr/lib/systemd/system (運行級別和服務啟動腳本)

CentOS7進入單用戶模式

1587614688172

1587615323077

在linux16 行末,加上:enforcing=0 init=/bin/bash 修改完之后,按Ctrl + X

## 修改默認啟動方式
bash-4.2# mount -o rw,remount /
bash-4.2# systectl set-default(不能用)
bash-4.2# rm -f /etc/systemd/system/default.target
bash-4.2# ln -s /usr/lib/systemd/system/multi-user.target /etc/systemd/system/default.target
bash-4.2# exec /sbin/init

## 修改密碼
bash-4.2# mount -o rw,remount /
bash-4.2# echo 123|passwd --stdin root
bash-4.2# exec /sbin/init

方法2:

1587615902521

1587615971544

switch_root:/# mount -o rw,remount /sysroot
switch_root:/# chroot /sysroot
sh-4.2# systemctl set-default multi-user.target
sh-4.2# exit
switch_root:/# reboot

nginx相關命令文檔


查看系統當前運行級別

N代表上次運行級別3是本次運行級別。

查看nginx是否開機自啟,disabled是關閉,enabled是開啟,可以看到現在是在關閉開機自啟的狀態,如果想添加到開機自啟可以輸入命令systemctl enable nginx,如下圖所示

啟動nginx並查看nginx狀態
[root@localhost ~]# systemctl start nginx
[root@localhost ~]# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since Sat 2020-04-25 04:32:39 CST; 17min ago
 Main PID: 7201 (nginx)
   CGroup: /system.slice/nginx.service
           ├─7201 nginx: master process /app/nginx/sbin/nginx
           └─7202 nginx: worker process
可以看到running代表服務是啟動的,或者看到有綠色的標志就代表服務實在開啟狀態
這時可以查看下nginx的端口
[root@localhost ~]# netstat -lntup|grep nginx
tcp        0      0 0.0.0.0:90              0.0.0.0:*               LISTEN      7201/nginx: master  
可以看到nginx的端口是90,默認是使用80端口,因為上次我改了一下nginx的配置文件把端口改成了90
[root@localhost ~]# netstat -lntup|grep 90
tcp        0      0 0.0.0.0:90              0.0.0.0:*               LISTEN      7201/nginx: master  

我們把配置文件改成80,首先找到nginx的配置文件我的在/app/nginx里面

cd /app/nginx/conf/

vim nginx.conf

然后我們可以不停止服務,重新加載nginx

[root@localhost nginx]# systemctl reload nginx
[root@localhost nginx]# netstat -lntup|grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      7201/nginx: master  
[root@localhost nginx]# 

Systemctl reload nginx 是不停止服務重新加載配置文件,企業常用手法,確保用戶體驗,這是可以看到端口改成了80

查看下服務是否運行

[root@localhost ~]# systemctl is-active nginx
active
可以看到這個狀態服務是在運行中的

我們可以把服務禁止運行

[root@localhost ~]# systemctl mask nginx
Created symlink from /etc/systemd/system/nginx.service to /dev/null.
再看下服務
[root@localhost ~]# systemctl is-active nginx
unknown
變成了這種狀態
這時候給服務取消禁止
[root@localhost ~]# systemctl unmask nginx 取消禁止
[root@localhost ~]# systemctl restart nginx 重啟服務
[root@localhost ~]# systemctl is-active nginx 
active 查看服務運行狀態
[root@localhost ~]# systemctl stop nginx 關閉服務
[root@localhost ~]# netstat -lutup|grep nginx 查看端口
[root@localhost ~]# ps -ef |grep nginx 查看服務進程
root       7466   7165  0 05:16 pts/0    00:00:00 grep --color=auto nginx
[root@localhost ~]# 
[root@localhost ~]# systemctl is-enabled nginx
disabled
指定查看nginx是否開機自啟


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM