成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

第五章:系統(tǒng)服務

第五章:系統(tǒng)服務

我們提供的服務有:成都網(wǎng)站建設、做網(wǎng)站、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認證、湘鄉(xiāng)ssl等。為數(shù)千家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務,是有科學管理、有技術的湘鄉(xiāng)網(wǎng)站制作公司

1.服務目錄

 

在之前的Redhat Linux5.x&6.x的系統(tǒng)中,我們知道,系統(tǒng)的服務都是存放在/etc/init.d這個目錄中的,但是在RHEL7.x的系統(tǒng)中,已經(jīng)發(fā)生了改變,如下:

------------------------------------------查看RHEL7之前的系統(tǒng)服務路徑------------------------------

[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)服務的所在路徑,所以,重啟服務也不能使用/etc/init.d servername  restart來啟動

 

 

 

2.服務下次啟動狀態(tài)

 

在RHEL7.x之前的系統(tǒng)中,使用命令chkconfig –list即可查看所有服務的下次啟動狀態(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

//此命令列出的只是一些基本的服務。要想查看所有的,根據(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 

………………………..

 

 

 

3.系統(tǒng)運行級別

 

RHEL7中,系統(tǒng)的運行級別已沒有0-6之說。運行級別的inittab文件也不再包含0-6級別的說明。如下:

[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

//相當于運行級別3,命令行界面

#  graphical.target: analogous to runlevel 5

//相當于運行級別5,圖形化界面

#

# To set a default target, run:

#

# ln -sf /lib/systemd/system/<target  name>.target /etc/systemd/system/

default.target

#

~                                                                

 

查看系統(tǒng)缺省運行級別

[root@ freeit ~]# systemctl  get-default

graphical.target

//默認運行級別為圖形化界面

 

設置默認運行級別

[root@ freeit ~]#systemctl set-default  multi-user.target

[root@ freeit ~]# systemctl get-default

multi-user.target

 

查看設置的運行級別的服務狀態(tài)(下次啟動狀態(tài))

[root@ freeit ~]# systemctl  list-unit-files |grep multi-user

multi-user.target                           enabled

 

 

 

 

4.服務下次啟動狀態(tài)

 

我們知道,服務啟動之后,要想下次重啟生效,RHEL7之前,要使用命令chkconfig servername on,但是在RHEL7中,已不能使用此命令。那么要如何設置,看下面的例子:

[root@ freeit ~]# systemctl restart  postfix.service

//啟動郵件服務

[root@ freeit ~]# systemctl status  postfix.service

//查看郵件服務的運行狀態(tài)

postfix.service - Postfix Mail Transport  Agent

    Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled)

//下次啟動為開啟

    Active: active (running)since Mon 2015-05-04 11:03:42 CST; 14s  ago

//當前正在運行

   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.

 

------------------------------------------------關閉下次開機啟動-------------------------------------------

[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.

//下次重啟生效功能關閉之后,重啟系統(tǒng),郵件服務即為關閉狀態(tài)

 

關閉之后重啟驗證

[root@ freeit ~]# systemctl status  postfix.service

postfix.service - Postfix Mail Transport  Agent

    Loaded: loaded (/usr/lib/systemd/system/postfix.service; disabled)

    Active: inactive (dead)

//沒有啟動

 

 

重新啟動郵件服務,并設置下次開機啟動

 [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.

 

 

 

5.服務狀態(tài)相關命令

 

  • 查看當前啟動狀態(tài)

[root@ freeit ~]# systemctl is-active  postfix.service

Active

//當前正在運行

 

  • 關閉當前運行狀態(tài),再次查看

[root@ freeit ~]# systemctl stop  postfix.service

[root@ freeit ~]# systemctl is-active  postfix.service

inactive

 

  • 查看下次開機啟動狀態(tài)

[root@ freeit ~]# systemctl is-enabled  postfix.service

enabled

//下次開機為啟動

 

  • 關閉下次開機啟動,并再次查看

[root@ freeit ~]# systemctl disable  postfix.service

rm '/etc/systemd/system/multi-user.target.wants/postfix.service'

[root@localhost ~]# systemctl is-enabled  postfix.service

disabled

 

 

 

6.鎖定服務(mask)

 

例1:對postfix服務執(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.

//重啟服務失敗

[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:解鎖服務并再次重啟

[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.

 

 

7.系統(tǒng)進程

 

 

7.1.實時查看系統(tǒng)進程

 

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     

…………………..

--------------------------------------------更詳細查看,按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鍵退出進程

 

  • 前5行說明:

前5行是系統(tǒng)整體的統(tǒng)計信息

  • 第一行是任務隊列信息,同uptime(查看服務器啟動時間)命令的執(zhí)行結果。內(nèi)容如下:

  • 11:34:23:當前時間;

  • up  1:13:系統(tǒng)運行時間,格式為時:分;

  • 1 user:當前登錄用戶數(shù);

  • load average: 0.00, 0.01, 0.05:系統(tǒng)負載,即任務隊列的平均長度。三個數(shù)值分別為1分鐘、5分鐘、15分鐘前到現(xiàn)在的平均值。

  • 第二、三行為進程和CPU的信息。當有多個CPU時,這些內(nèi)容可能會超過兩行,內(nèi)容如下:

  • Tasks: 297 total:進程總數(shù);

  • 4 running:正在運行的進程數(shù);

  • 293 sleeping:睡眠的進程數(shù);

  • 0 stopped:停止進程數(shù);

  • 0 zombie:僵尸進程;

  • %Cpu(s):  0.0 us:用戶空間占用CPU百分比;

  • 0.0 sy:內(nèi)核空間占用CPU百分比; 

  • 0.0 ni:用戶進程空間內(nèi)改變過優(yōu)先級的進程占用CPU百分比;

  • 99.7 id:id空閑CPU百分比; 

  • 0.0 wa:wa等待輸入輸出的CPU時間百分比 

  • 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ū)總量。

 

  • 進程區(qū)信息說明:

  • PID:進程ID;

  • USER:進程所有者;

  • PR:進程優(yōu)先級;

  • NI:nice值。負值表示高優(yōu)先級;正值表示低優(yōu)先級;

  • VIRT:進程使用的虛擬內(nèi)存總量,單位Kb,VITR=SWAP+RES

  • RES:進程使用的、未被交換出的物理內(nèi)存大小,單位KB,RES=CODE+DATA

  • SHR:共享內(nèi)存大小,單位Kb;

  • S:進程狀態(tài);

  • %CPU:上次更新到現(xiàn)在的CPU時間戰(zhàn)用百分比;

  • %MEM:進程使用的物理內(nèi)存百分比;

  • TIME+:進程使用的CPU時間總計,單位1/100秒;

  • COMMAND:命令名/命令行

 

 

7.2.靜態(tài)查看當前進程狀態(tài)

 

[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:包含所有終端的進程

     -u:顯示進程的擁有者

     -x:顯示不屬于任何終端的進程

     -f:顯示進程的父子關系

 

 

7.3.查看進程樹

 

[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

 

 

 

8.前臺后臺(fg&bg)

 

例:把/usr復制到/tmp下,由于復制時間長,調(diào)用到后臺復制。然后再調(diào)用到前臺。期間再暫停,調(diào)用到后臺,最后kill掉此進程

[root@ freeit ~]# cp -r /usr /tmp/ &

[1] 3991

//開始復制,&為后臺執(zhí)行

 

[root@ freeit ~]# jobs

[1]+   Running                 cp -i -r  /usr /tmp/ &

//查看后臺執(zhí)行的操作

 

[root@ freeit ~]# fg 1

cp -i -r /usr /tmp/

//調(diào)用到前臺執(zhí)行進程

^Z

[1]+   Stopped                 cp -i -r  /usr /tmp

//按ctrl+z停止進程

 

[root@ freeit ~]# bg 1

[1]+ cp -i -r /usr /tmp/ &

//繼續(xù)調(diào)用到后臺執(zhí)行

 

[root@ freeit ~]# jobs

[1]+   Running                 cp -i -r  /usr /tmp/ &

 

 [root@ freeit ~]# kill %1

//結束此進程

 

[root@ freeit ~]# jobs

[1]+   Terminated              cp -i -r  /usr /tmp/

 


名稱欄目:第五章:系統(tǒng)服務
新聞來源:http://jinyejixie.com/article46/ppeshg.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供、網(wǎng)站維護、服務器托管、關鍵詞優(yōu)化網(wǎng)頁設計公司、企業(yè)網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

成都seo排名網(wǎng)站優(yōu)化
新乡市| 漯河市| 丰城市| 浠水县| 松江区| 健康| 阿克苏市| 什邡市| 荥经县| 中江县| 镇平县| 札达县| 兴文县| 博兴县| 潍坊市| 浦城县| 邯郸县| 景泰县| 邯郸县| 浪卡子县| 当雄县| 桃江县| 永嘉县| 稷山县| 重庆市| 鄂托克前旗| 香河县| 喜德县| 故城县| 鲁山县| 香格里拉县| 枝江市| 博湖县| 广昌县| 仁化县| 博白县| 宣威市| 弥渡县| 得荣县| 阿克苏市| 岱山县|