第五章:系統(tǒng)服務(wù)
成都創(chuàng)新互聯(lián)公司長期為上千多家客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺(tái),與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為天祝藏族自治企業(yè)提供專業(yè)的成都網(wǎng)站制作、網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè),天祝藏族自治網(wǎng)站改版等技術(shù)服務(wù)。擁有10年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開發(fā)。在之前的Redhat Linux5.x&6.x的系統(tǒng)中,我們知道,系統(tǒng)的服務(wù)都是存放在/etc/init.d這個(gè)目錄中的,但是在RHEL7.x的系統(tǒng)中,已經(jīng)發(fā)生了改變,如下:
------------------------------------------查看RHEL7之前的系統(tǒng)服務(wù)路徑------------------------------ [root@ freeit ~]# cd /etc/init.d/ [root@ freeit init.d]# ls abrt-ccpp iscsi restorecond abrtd iscsid rhnsd abrt-oops kdump rhsmcertd acpid killall rngd atd libvirt-guests rpcbind auditd lldpad rpcgssd autofs lvm2-lvmetad rpcidmapd blk-availability lvm2-monitor rpcsvcgssd bluetooth mdmonitor rsyslog certmonger messagebus sandbox cgconfig multipathd saslauthd cgred mysqld single cpuspeed named smartd crond netconsole snmpd cups netfs snmptrapd dhcpd network spice-vdagentd dhcpd6 NetworkManager sshd dhcrelay nfs sssd dnsmasq nfslock sysstat fcoe ntpd udev-post firstboot ntpdate vmware-tools functions oddjobd vmware-tools-thinprint haldaemon openct vncserver halt pcscd wdaemon htcacheclean portreserve winbind httpd postfix wpa_supplicant ip6tables psacct xinetd iptables quota_nld ypbind irqbalance rdisc -----------------------------------------查看RHEL7的/etc/init.d/目錄---------------------------------- [root@ freeit tmp]# cd /etc/init.d/ [root@ freeit init.d]# ls functions iprinit netconsole README iprdump iprupdate network rhnsd //如上,此目錄不再是系統(tǒng)服務(wù)的所在路徑,所以,重啟服務(wù)也不能使用/etc/init.d servername restart來啟動(dòng) |
在RHEL7.x之前的系統(tǒng)中,使用命令chkconfig –list即可查看所有服務(wù)的下次啟動(dòng)狀態(tài),但是在RHEL7中,此命令已不可用
[root@ freeit ~]# chkconfig --list Note: This output shows SysV services only and does not include native systemd services. SysV configuration data might be overridden by native systemd configuration. If you want to list systemd services use 'systemctl list-unit-files'. To see services enabled on particular target use 'systemctl list-dependencies [target]'. iprdump 0:off 1:off 2:on 3:on 4:on 5:on 6:off iprinit 0:off 1:off 2:on 3:on 4:on 5:on 6:off iprupdate 0:off 1:off 2:on 3:on 4:on 5:on 6:off 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:off //此命令列出的只是一些基本的服務(wù)。要想查看所有的,根據(jù)提示命令查看(加粗字體) ---------------------------------------------systemctl list-unit-files--------------------------------------------- [root@ freeit ~]# systemctl list-unit-files UNIT FILE STATE proc-sys-fs-binfmt_misc.automount static dev-hugepages.mount static dev-mqueue.mount static proc-fs-nfsd.mount static proc-sys-fs-binfmt_misc.mount static sys-fs-fuse-connections.mount static sys-kernel-config.mount static sys-kernel-debug.mount static tmp.mount disabled var-lib-nfs-rpc_pipefs.mount static brandbot.path disabled cups.path enabled systemd-ask-password-console.path static systemd-ask-password-plymouth.path static ……………………….. |
RHEL7中,系統(tǒng)的運(yùn)行級(jí)別已沒有0-6之說。運(yùn)行級(jí)別的inittab文件也不再包含0-6級(jí)別的說明。如下:
[root@ freeit ~]# vim /etc/inittab # inittab is no longer used when using systemd. # # ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM. # # Ctrl-Alt-Delete is handled by /etc/systemd/system/ctrl-alt-del.targe t # # systemd uses 'targets' instead of runlevels. By default, there are t wo main targets: # # multi-user.target: analogous to runlevel 3 //相當(dāng)于運(yùn)行級(jí)別3,命令行界面 # graphical.target: analogous to runlevel 5 //相當(dāng)于運(yùn)行級(jí)別5,圖形化界面 # # To set a default target, run: # # ln -sf /lib/systemd/system/<target name>.target /etc/systemd/system/ default.target # ~ |
查看系統(tǒng)缺省運(yùn)行級(jí)別
[root@ freeit ~]# systemctl get-default graphical.target //默認(rèn)運(yùn)行級(jí)別為圖形化界面 |
設(shè)置默認(rèn)運(yùn)行級(jí)別
[root@ freeit ~]#systemctl set-default multi-user.target [root@ freeit ~]# systemctl get-default multi-user.target |
查看設(shè)置的運(yùn)行級(jí)別的服務(wù)狀態(tài)(下次啟動(dòng)狀態(tài))
[root@ freeit ~]# systemctl list-unit-files |grep multi-user multi-user.target enabled |
我們知道,服務(wù)啟動(dòng)之后,要想下次重啟生效,RHEL7之前,要使用命令chkconfig servername on,但是在RHEL7中,已不能使用此命令。那么要如何設(shè)置,看下面的例子:
[root@ freeit ~]# systemctl restart postfix.service //啟動(dòng)郵件服務(wù) [root@ freeit ~]# systemctl status postfix.service //查看郵件服務(wù)的運(yùn)行狀態(tài) postfix.service - Postfix Mail Transport Agent Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled) //下次啟動(dòng)為開啟 Active: active (running) since Mon 2015-05-04 11:03:42 CST; 14s ago //當(dāng)前正在運(yùn)行 Process: 4611 ExecStop=/usr/sbin/postfix stop (code=exited, status=0/SUCCESS) Process: 4626 ExecStart=/usr/sbin/postfix start (code=exited, status=0/SUCCESS) Process: 4623 ExecStartPre=/usr/libexec/postfix/chroot-update (code=exited, status=0/SUCCESS) Process: 4621 ExecStartPre=/usr/libexec/postfix/aliasesdb (code=exited, status=0/SUCCESS) Main PID: 4698 (master) CGroup: /system.slice/postfix.service ├─4698 /usr/libexec/postfix/master –w ├─4699 pickup -l -t unix -u └─4700 qmgr -l -t unix -u May 04 11:03:42 localhost.localdomain systemd[1]: Starting Postfix Ma... May 04 11:03:42 localhost.localdomain postfix/master[4698]: daemon st... May 04 11:03:42 localhost.localdomain systemd[1]: Started Postfix Mai... Hint: Some lines were ellipsized, use -l to show in full. ------------------------------------------------關(guān)閉下次開機(jī)啟動(dòng)------------------------------------------- [root@ freeit ~]# systemctl disable postfix.service rm '/etc/systemd/system/multi-user.target.wants/postfix.service' [root@ freeit ~]# systemctl status postfix.service postfix.service - Postfix Mail Transport Agent Loaded: loaded (/usr/lib/systemd/system/postfix.service; disabled) Active: active (running) since Mon 2015-05-04 11:03:42 CST; 4min 30s ago Main PID: 4698 (master) CGroup: /system.slice/postfix.service ├─4698 /usr/libexec/postfix/master -w ├─4699 pickup -l -t unix -u └─4700 qmgr -l -t unix -u May 04 11:03:42 localhost.localdomain systemd[1]: Starting Postfix Ma... May 04 11:03:42 localhost.localdomain postfix/master[4698]: daemon st... May 04 11:03:42 localhost.localdomain systemd[1]: Started Postfix Mai... Hint: Some lines were ellipsized, use -l to show in full. //下次重啟生效功能關(guān)閉之后,重啟系統(tǒng),郵件服務(wù)即為關(guān)閉狀態(tài) |
關(guān)閉之后重啟驗(yàn)證
[root@ freeit ~]# systemctl status postfix.service postfix.service - Postfix Mail Transport Agent Loaded: loaded (/usr/lib/systemd/system/postfix.service; disabled) Active: inactive (dead) //沒有啟動(dòng) |
重新啟動(dòng)郵件服務(wù),并設(shè)置下次開機(jī)啟動(dòng)
[root@ freeit ~]# systemctl restart postfix [root@localhost ~]# systemctl enable postfix.service ln -s '/usr/lib/systemd/system/postfix.service' '/etc/systemd/system/multi-user.target.wants/postfix.service' [root@ freeit ~]# systemctl status postfix.service postfix.service - Postfix Mail Transport Agent Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled) Active: active (running) since Mon 2015-05-04 11:12:14 CST; 35s ago Main PID: 2994 (master) CGroup: /system.slice/postfix.service ├─2994 /usr/libexec/postfix/master -w ├─2995 pickup -l -t unix -u └─2996 qmgr -l -t unix -u May 04 11:12:14 localhost.localdomain systemd[1]: Starting Postfix Ma... May 04 11:12:14 localhost.localdomain postfix/master[2994]: daemon st... May 04 11:12:14 localhost.localdomain systemd[1]: Started Postfix Mai... Hint: Some lines were ellipsized, use -l to show in full. |
查看當(dāng)前啟動(dòng)狀態(tài)
[root@ freeit ~]# systemctl is-active postfix.service Active //當(dāng)前正在運(yùn)行 |
關(guān)閉當(dāng)前運(yùn)行狀態(tài),再次查看
[root@ freeit ~]# systemctl stop postfix.service [root@ freeit ~]# systemctl is-active postfix.service inactive |
查看下次開機(jī)啟動(dòng)狀態(tài)
[root@ freeit ~]# systemctl is-enabled postfix.service enabled //下次開機(jī)為啟動(dòng) |
關(guān)閉下次開機(jī)啟動(dòng),并再次查看
[root@ freeit ~]# systemctl disable postfix.service rm '/etc/systemd/system/multi-user.target.wants/postfix.service' [root@localhost ~]# systemctl is-enabled postfix.service disabled |
例1:對(duì)postfix服務(wù)執(zhí)行mask操作,然后執(zhí)行重啟操作
[root@ freeit ~]# systemctl mask postfix ln -s '/dev/null' '/etc/systemd/system/postfix.service' [root@localhost ~]# systemctl restart postfix Failed to issue method call: Unit postfix.service is masked. //重啟服務(wù)失敗 [root@ freeit ~]# systemctl status postfix postfix.service Loaded: masked (/dev/null) Active: inactive (dead) May 04 11:12:14 localhost.localdomain systemd[1]: Starting Postfix Ma... May 04 11:12:14 localhost.localdomain postfix/master[2994]: daemon st... May 04 11:12:14 localhost.localdomain systemd[1]: Started Postfix Mai... May 04 11:18:39 localhost.localdomain systemd[1]: Stopping Postfix Ma... May 04 11:18:39 localhost.localdomain systemd[1]: Stopped Postfix Mai... Hint: Some lines were ellipsized, use -l to show in full. |
例2:解鎖服務(wù)并再次重啟
[root@ freeit ~]# systemctl unmask postfix //解鎖 rm '/etc/systemd/system/postfix.service' [root@ freeit ~]# systemctl restart postfix //重啟成功 [root@ freeit ~]# systemctl status postfix postfix.service - Postfix Mail Transport Agent Loaded: loaded (/usr/lib/systemd/system/postfix.service; disabled) Active: active (running)since Mon 2015-05-04 11:29:36 CST; 3s ago Process: 3529 ExecStart=/usr/sbin/postfix start (code=exited, status=0/SUCCESS) Process: 3527 ExecStartPre=/usr/libexec/postfix/chroot-update (code=exited, status=0/SUCCESS) Process: 3524 ExecStartPre=/usr/libexec/postfix/aliasesdb (code=exited, status=0/SUCCESS) Main PID: 3601 (master) CGroup: /system.slice/postfix.service ├─3601 /usr/libexec/postfix/master -w ├─3602 pickup -l -t unix -u └─3603 qmgr -l -t unix -u May 04 11:29:36 localhost.localdomain postfix/master[3601]: daemon st... May 04 11:29:36 localhost.localdomain systemd[1]: Started Postfix Mai... Hint: Some lines were ellipsized, use -l to show in full. |
top - 11:34:23 up 25 min, 1 user, load average: 0.00, 0.01, 0.05 Tasks: 297 total, 4 running, 293 sleeping, 0 stopped, 0 zombie %Cpu(s): 0.0 us, 0.0 sy, 0.0 ni, 99.7 id, 0.0 wa, 0.0 hi, 0.3 si, 0.0 st KiB Mem: 1010788 total, 306908 used, 703880 free, 1080 buffers KiB Swap: 2097148 total, 0 used, 2097148 free. 110788 cached Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 3651 root 20 0 123788 1772 1148 R 0.3 0.2 0:00.03 top 1 root 20 0 53948 7808 2548 S 0.0 0.8 0:05.08 systemd 2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd 3 root 20 0 0 0 0 R 0.0 0.0 0:00.04 ksoftirqd/0 5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H 7 root rt 0 0 0 0 S 0.0 0.0 0:00.00 migration/0 8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh ………………….. --------------------------------------------更詳細(xì)查看,按1------------------------------------------------- top - 11:35:00 up 25 min, 1 user, load average: 0.00, 0.01, 0.05 Tasks: 297 total, 2 running, 295 sleeping, 0 stopped, 0 zombie %Cpu0 : 0.7 us, 0.7 sy, 0.0 ni, 98.7 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem: 1010788 total, 307172 used, 703616 free, 1080 buffers KiB Swap: 2097148 total, 0 used, 2097148 free. 110788 cached Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 879 root 20 0 193424 4168 3344 S 1.0 0.4 0:02.80 vmtoolsd 3651 root 20 0 123788 1772 1148 R 0.7 0.2 0:00.20 top 1 root 20 0 53948 7808 2548 S 0.0 0.8 0:05.08 systemd 2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd 3 root 20 0 0 0 0 S 0.0 0.0 0:00.04 ksoftirqd/0 5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H 7 root rt 0 0 0 0 S 0.0 0.0 0:00.00 migration/0 8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh |
按q鍵退出進(jìn)程
前5行說明:
前5行是系統(tǒng)整體的統(tǒng)計(jì)信息
第一行是任務(wù)隊(duì)列信息,同uptime(查看服務(wù)器啟動(dòng)時(shí)間)命令的執(zhí)行結(jié)果。內(nèi)容如下:
11:34:23:當(dāng)前時(shí)間;
up 1:13:系統(tǒng)運(yùn)行時(shí)間,格式為時(shí):分;
1 user:當(dāng)前登錄用戶數(shù);
load average: 0.00, 0.01, 0.05:系統(tǒng)負(fù)載,即任務(wù)隊(duì)列的平均長度。三個(gè)數(shù)值分別為1分鐘、5分鐘、15分鐘前到現(xiàn)在的平均值。
第二、三行為進(jìn)程和CPU的信息。當(dāng)有多個(gè)CPU時(shí),這些內(nèi)容可能會(huì)超過兩行,內(nèi)容如下:
Tasks: 297 total:進(jìn)程總數(shù);
4 running:正在運(yùn)行的進(jìn)程數(shù);
293 sleeping:睡眠的進(jìn)程數(shù);
0 stopped:停止進(jìn)程數(shù);
0 zombie:僵尸進(jìn)程;
%Cpu(s): 0.0 us:用戶空間占用CPU百分比;
0.0 sy:內(nèi)核空間占用CPU百分比;
0.0 ni:用戶進(jìn)程空間內(nèi)改變過優(yōu)先級(jí)的進(jìn)程占用CPU百分比;
99.7 id:id空閑CPU百分比;
0.0 wa:wa等待輸入輸出的CPU時(shí)間百分比
0.0 hi 0.3 si, 0.0 st
最后兩行為內(nèi)存信息。內(nèi)容如下:
KiB Mem: 1010788 total:物理內(nèi)存總量
306908 used:使用的物理內(nèi)存總量;
703880 free:空閑的物理內(nèi)存總量;
1080 buffers:用作內(nèi)核緩存的物理內(nèi)存量;
KiB Swap: 2097148 total:交換區(qū)總量;
0 used:使用的交換分區(qū)總量;
2097148 free:空閑的交換區(qū)總量;
110788 cached Mem:緩沖的交換區(qū)總量。
進(jìn)程區(qū)信息說明:
PID:進(jìn)程ID;
USER:進(jìn)程所有者;
PR:進(jìn)程優(yōu)先級(jí);
NI:nice值。負(fù)值表示高優(yōu)先級(jí);正值表示低優(yōu)先級(jí);
VIRT:進(jìn)程使用的虛擬內(nèi)存總量,單位Kb,VITR=SWAP+RES
RES:進(jìn)程使用的、未被交換出的物理內(nèi)存大小,單位KB,RES=CODE+DATA
SHR:共享內(nèi)存大小,單位Kb;
S:進(jìn)程狀態(tài);
%CPU:上次更新到現(xiàn)在的CPU時(shí)間戰(zhàn)用百分比;
%MEM:進(jìn)程使用的物理內(nèi)存百分比;
TIME+:進(jìn)程使用的CPU時(shí)間總計(jì),單位1/100秒;
COMMAND:命令名/命令行
[root@ freeit ~]# ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.3 0.7 53948 7808 ? Ss 11:09 0:05 /usr/lib/systemd/systemd --s root 2 0.0 0.0 0 0 ? S 11:09 0:00 [kthreadd] root 3 0.0 0.0 0 0 ? S 11:09 0:00 [ksoftirqd/0] root 5 0.0 0.0 0 0 ? S< 11:09 0:00 [kworker/0:0H] root 7 0.0 0.0 0 0 ? S 11:09 0:00 [migration/0] root 8 0.0 0.0 0 0 ? S 11:09 0:00 [rcu_bh] root 9 0.0 0.0 0 0 ? S 11:09 0:00 [rcuob/0] root 10 0.0 0.0 0 0 ? S 11:09 0:00 [rcuob/1] root 11 0.0 0.0 0 0 ? S 11:09 0:00 [rcuob/2] root 12 0.0 0.0 0 0 ? S 11:09 0:00 [rcuob/3] …………………………. |
常用參數(shù):
-a:包含所有終端的進(jìn)程
-u:顯示進(jìn)程的擁有者
-x:顯示不屬于任何終端的進(jìn)程
-f:顯示進(jìn)程的父子關(guān)系
[root@ freeit ~]# pstree systemd─┬─ModemManager───2*[{ModemManager}] ├─NetworkManager───2*[{NetworkManager}] ├─2*[abrt-watch-log] ├─abrtd ├─agetty ├─alsactl ├─atd ├─auditd─┬─audispd─┬─sedispatch │ │ └─{audispd} │ └─{auditd} ├─avahi-daemon───avahi-daemon ├─bluetoothd ├─chronyd ├─crond ├─dbus-daemon───{dbus-daemon} ├─firewalld───{firewalld} ├─iprdump ├─iprinit ├─iprupdate ├─ksmtuned───sleep ├─libvirtd───10*[{libvirtd}] ├─lsmd ├─lvmetad ├─master─┬─pickup │ └─qmgr ├─packagekitd───2*[{packagekitd}] ├─polkitd───5*[{polkitd}] ├─rhsmcertd ├─rngd ├─rpc.statd ├─rpcbind ├─rsyslogd───2*[{rsyslogd}] ├─smartd ├─sshd───sshd───bash───pstree ├─systemd-journal ├─systemd-logind ├─systemd-udevd ├─tuned───4*[{tuned}] └─vmtoolsd |
例:把/usr復(fù)制到/tmp下,由于復(fù)制時(shí)間長,調(diào)用到后臺(tái)復(fù)制。然后再調(diào)用到前臺(tái)。期間再暫停,調(diào)用到后臺(tái),最后kill掉此進(jìn)程
[root@ freeit ~]# cp -r /usr /tmp/ & [1] 3991 //開始復(fù)制,&為后臺(tái)執(zhí)行 [root@ freeit ~]# jobs [1]+ Running cp -i -r /usr /tmp/ & //查看后臺(tái)執(zhí)行的操作 [root@ freeit ~]# fg 1 cp -i -r /usr /tmp/ //調(diào)用到前臺(tái)執(zhí)行進(jìn)程 ^Z [1]+ Stopped cp -i -r /usr /tmp //按ctrl+z停止進(jìn)程 [root@ freeit ~]# bg 1 [1]+ cp -i -r /usr /tmp/ & //繼續(xù)調(diào)用到后臺(tái)執(zhí)行 [root@ freeit ~]# jobs [1]+ Running cp -i -r /usr /tmp/ & [root@ freeit ~]# kill %1 //結(jié)束此進(jìn)程 [root@ freeit ~]# jobs [1]+ Terminated cp -i -r /usr /tmp/ |
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
分享題目:第五章:系統(tǒng)服務(wù)-創(chuàng)新互聯(lián)
URL網(wǎng)址:http://muchs.cn/article12/dcocdc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供全網(wǎng)營銷推廣、云服務(wù)器、自適應(yīng)網(wǎng)站、網(wǎng)站維護(hù)、面包屑導(dǎo)航、搜索引擎優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容