版權聲明:本文為部落客原創文章,轉載請注明出處。 https://blog.csdn.net/twilight_karl/article/details/76714066
系統運作級别
- runlevel 檢視運作級别
- init num 設定運作級别
運作級别 | 含義 |
---|---|
關機 | |
1 | 單使用者模式,可以想象為安全模式,主要使用者系統修複 |
2 | 不完全的指令行模式 |
3 | 完全的指令行模式,标準字元界面 |
4 | 系統保留 |
5 | 圖形模式 |
6 | 重新開機動 |
[root@localhost ~]# init 3
[root@localhost ~]# runlevel
5 3
修改預設運作級别傳統方式是更改/etc/inittab檔案。但是在Centos7中,該檔案的内容:
# inittab is no longer used when using systemd.
#
# ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
#
# Ctrl-Alt-Delete is handled by /usr/lib/systemd/system/ctrl-alt-del.target
#
# systemd uses 'targets' instead of runlevels. By default, there are two main targets:
#
# multi-user.target: analogous to runlevel 3
# graphical.target: analogous to runlevel 5
#
# To view current default target, run:
# systemctl get-default
#
# To set a default target, run:
# systemctl set-default TARGET.target
表示該檔案已經不起作用,可以使用指令方式修改:
- multi-user.target: runlevel 3
- graphical.target: runlevel 5
使用
systemctl get-default
擷取預設級别。使用
systemctl set-default TARGET.target
設定預設級别
獲得預設運作級别
[root@localhost etc]# systemctl get-default
graphical.target
設定預設運作級别為字元界面:
[root@localhost etc]# systemctl set-default multi-user.target
Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/multi-user.target.
檢視自啟動狀态
chkconfig –list
檢視服務自啟動狀态,可以看到所有RPM包安裝的服務
[root@localhost rc.d]# chkconfig --list
NetworkManager 0:關閉 1:關閉 2:啟用 3:啟用 4:啟用 5:啟用 6:關閉
abrt-ccpp 0:關閉 1:關閉 2:關閉 3:啟用 4:關閉 5:啟用 6:關閉
abrtd 0:關閉 1:關閉 2:關閉 3:啟用 4:關閉 5:啟用 6:關閉
acpid 0:關閉 1:關閉 2:啟用 3:啟用 4:啟用 5:啟用 6:關閉
atd 0:關閉 1:關閉 2:關閉 3:啟用 4:啟用 5:啟用 6:關閉
auditd 0:關閉 1:關閉 2:啟用 3:啟用 4:啟用 5:啟用 6:關閉
autofs 0:關閉 1:關閉 2:關閉 3:啟用 4:啟用 5:啟用 6:關閉
檢視已啟動的軟體
- netstat -an 檢視所有端口,檢視已連接配接端口
- netstat -tulnp 檢視已開啟的監聽狀态的端口
rpm如何啟動軟體
- 通過絕對路徑啟動(标準啟動方式)
/etc/init.d/httpd start
/etc/rc.d/init.d/httpd start
- service 指令啟動(rethat系統專有指令)
service httpd start|stop|restart|status
設定自啟動狀态
- chkconfig [–level] [獨立服務名] [on|off]
[root@localhost rc.d]# chkconfig --level 2345 httpd on
[root@localhost rc.d]# chkconfig --list | grep httpd
httpd 0:關閉 1:關閉 2:啟用 3:啟用 4:啟用 5:啟用 6:關閉
- 修改/etc/rc.d/rc.local 檔案,系統啟動時會最後執行檔案中的内容,可以加上啟動特定服務的指令。最後執行的檔案。
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
# 自啟動指令
/etc/init.d/httpd start
- ntsysv [級别号] 圖形化工具,作用和chkconfig相同。
chkconfig 和 ntsysv 做出的更改會同步,但是在rc.local檔案中做出的修改,在chkconfig中無法檢視到
源碼包的自啟動
更改
/etc/rc.d/rc.local
檔案,将啟動指令追加到檔案末尾即可。
chkconfig
指令不能識别源碼包服務。
讓源碼包被service識别
将源碼包的啟動腳本複制到init.d目錄下,改腳本需要能接受相關參數,比如start|stop等
讓源碼包的服務能被chkconfig 與ntsysv指令管理
- 在init.d 目錄下的腳本中起始處添加
# chkconfig: 35 86 76
chkconfig: 運作級别 啟動順序 關閉順序 (/etc/rc3.d/)
- 在腳本中添加
# description: ..
說明, 内容随意
-
将init.d下的啟動腳本加入chkconfig到指令中chkconfig --add 腳本名稱