RedHatEL7 的一些新的操做【待更新】

一、掛載光驅

# mount /dev/cdrom /mediaapache

二、安裝時默認的文件系統從ext4改成xfs

/dev/mapper/rhel_rh7-root xfs        50G  4.8G   46G  10% /bash

說明:rhel_rh7-root的組成是rhel_主機名-分區標籤app

三、管理系統服務(systemctl)

RHEL7版本開始對系統服務啓動腳本的管理再也不放到/etc/init.d/目錄下,這裏只有少數幾個啓動腳本,例如:less

netconsole  network  rhnsd函數

說明:上面的啓動腳本仍是可使用傳統的chkconfig --list 來查看啓動級別的,而大部分啓動腳本用這個命令是看不到的工具

# chkconfig --list
netconsole      0:off   1:off   2:off   3:off   4:off   5:off   6:off
network         0:off   1:off   2:on    3:on    4:on    5:on    6:off
rhnsd           0:off   1:off   2:on    3:on    4:on    5:on    6:offoop

提示:傳統的放到/etc/init.d目錄下的啓動腳本仍是能夠用的,須要調用的/etc/init.d/functions啓動腳本函數庫文件還在。spa

#! /bin/bashrest

# chkconfig: 2345 10 90
# description: Activates/Deactivates all network interfaces configured to start at boot time.
# Source function library.
. /etc/init.d/functions
……
code

RHEL7開始大部分啓動腳本的管理都必須使用 systemctl 這個命令

LinuxSystemctl是一個系統管理守護進程、工具和庫的集合,用於取代System V、service和chkconfig命令,初始進程主要負責控制systemd系統和服務管理器。經過Systemctl –help能夠看到該命令主要分爲:查詢或發送控制命令給systemd服務,管理單元服務的命令,服務文件的相關命令,任務、環境、快照相關命令,systemd服務的配置重載,系統開機關機相關的命令。

1)查看已經安裝軟件的是否開機自動啓動或禁止   systemctl list-unit-files (也可使用這個命令查看啓動服務的名稱是怎麼寫的)

舉例:列出全部可用的服務名稱,及其開機自動啓動狀態

# systemctl list-unit-files --type=service

UNIT FILE                              STATE   
abrt-ccpp.service                      enabled
abrt-oops.service                      enabled
abrt-pstoreoops.service                disabled
abrt-vmcore.service                    enabled

2)啓動|中止|重啓|從新加載   systemctl start|stop|restart|reload  foobar.service

2)中止某個服務啓動

# systemctl stop firewalld.service

3)設置開機容許|禁止啓動    systemctl enable|disable  foobar.service

例如:設置開機禁止防火牆服務啓動

# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.

例如:設置開機自動啓動防火牆服務

# systemctl enable firewalld.service
Created symlink from /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service to /usr/lib/systemd/system/firewalld.service.
Created symlink from /etc/systemd/system/basic.target.wants/firewalld.service to /usr/lib/systemd/system/firewalld.service.

4)進入援救模式或緊急模式

啓動救援模式 

# systemctl rescue

進入緊急模式 

# systemctl emergency

重啓

# systemctl reboot

關閉電源關機

# systemctl poweroff

使用systemctl 命令管理的原理:

(1)真實的啓動Daemon都保存在/usr/lib/systemd/system目錄下,例如:httpd.service

(2)systemctl根據啓動級別會在/etc/systemd/system目錄下建立一些子目錄

sysinit.target.wants(lvm2-monitor.service)    multi-user.target.wants(多用戶能夠啓動的腳本,大部分都放這裏)    basic.target.wants(firewalld.service和microcode.service)

(3)若是設置成開機自動啓動的啓動Daemon都會在/etc/systemd/system/不一樣級別子目錄下/建立一個軟鏈接,來源就是從/usr/lib/systemd/system目錄下建立的。

例如:

# systemctl enable httpd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

# ls -l /etc/systemd/system/multi-user.target.wants|grep httpd
lrwxrwxrwx. 1 root root 37 Apr 18 05:57 httpd.service -> /usr/lib/systemd/system/httpd.service

(4)若是禁止開機自動啓動,就把軟鏈接刪除

(5)真實的啓動Daemon腳本文件內容以下所示,用httpd.service舉例

[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)

[Service]
Type=notify
EnvironmentFile=/etc/sysconfig/httpd    加載環境變量文件
ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND    執行start命令時真正執行的命令和參數
ExecReload=/usr/sbin/httpd $OPTIONS -k graceful        執行reload命令時真正執行的命令和參數
ExecStop=/bin/kill -WINCH ${MAINPID}                        執行stop命令時真正執行的命令和參數
# We want systemd to give httpd some time to finish gracefully, but still want
# it to kill httpd after TimeoutStopSec if something went wrong during the
# graceful stop. Normally, Systemd sends SIGTERM signal right after the
# ExecStop, which would kill httpd. We are sending useless SIGCONT here to give
# httpd time to finish.
KillSignal=SIGCONT
PrivateTmp=true

[Install]
WantedBy=multi-user.target
 

對比RHEL6與RHEL7對服務的管理命令

顯示全部服務 chkconfig --list systemctl list-unit-files --type=service
顯示全部已啓動的服務 chkconfig --list|grep on systemctl list-units --type=service    
使某服務開機自動啓動 chkconfig --level 3 httpd on systemctl enable httpd.service
使某服務開機禁止啓動 chkconfig --level 3 httpd off systemctl disable httpd.service
檢查服務狀態 service httpd status systemctl status httpd.service (服務詳細信息) systemctl is-active httpd.service (僅顯示是否 Active)
啓動某服務 service httpd start systemctl start httpd.service
中止某服務 service httpd stop systemctl stop httpd.service
重啓某服務 service httpd restart systemctl restart httpd.service

 

四、

相關文章
相關標籤/搜索