日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux系统的服务

發布時間:2023/12/20 linux 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux系统的服务 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

目錄

系統服務知識

查看Linux系統服務

chkconfig


系統服務知識

1、系統服務分類,根據其使用的方法來分,可以被分為三類
a、由init控制的服務:基本都是系統級別的服務,運行級別這一章講的就是這一類的服務
b、由System V啟動腳本啟動的服務:和我們打交道最多的一種服務,服務器基本都是這個類型的服務
c、由xinetd管理的服務
2、System V啟動腳本啟動的服務
/etc/rc.d/init.d/目錄下的內容如下:這些常用的服務器都是System v的服務,要控制System V 的服務,我們可以使用以下命令
#/etc/rc.d/init.d/script {start|stop|restart|reload|condrestart|status}
stop:停止這個服務。
restart:先停止,再啟動,也就是重新啟動的意思。
reload:重新加載設定檔,這個參數只有在服務已經啟動的狀況下才能使用。
condrestart:有條件的重新啟動,這個服務必須是已經啟動的,才會被重新啟動;如果這個服務尚未啟動,則無須啟動之。
status:察看目前服務的啟動狀態。
也可以使用service命令來執行腳本,例如 #service network {start|stop|restart|reload|condrestart|status}
System V的服務在不同級別下的默認開關可以不相同。我們還可以用兩種方法來控制默認情況下,開機是否開啟某些服務,使用chkconfig和ntsysv(圖形方式,默認只能定義當前級別,不過可以增加參數來實現如# ntsysv –level 23)來控制。
#chkconfig --list //查看系統system v服務所有級別下的開關情況。
#chkconfig sshd on|off //更改sshd服務2-5級別的默認開關情況
#chkconfig sendmail off //所有級別關閉sendmail服務
#chkconfig --level 23 sendmail off //在2、3級別關閉sendmail服務
3、xinetd服務管理
xinetd服務的管理文件都放在 /etc/xinetd.d目錄內,我們可以編輯這個目錄內的服務文件來開啟和關閉服務。每個服務文件都有disable 這個行,如果把值改成yes就是禁用服務,如果是no,那就是啟動這個服務。修改成功后,要使修改生效,需要從新啟動xinetd服務。
#service xinetd restart

查看Linux系統服務

? ? ? ? ?只要是Linux操作系統,不管發行版本是什么,都有系統服務,Linux系統服務也被稱為守護程序,是啟動時自動加載的且在退出時自動停止的系統服務,本篇文章將為大家講解如何查看Linux的系統服務,以及如何檢查某個服務的狀態,請看下文:

1、CentOS/RHEL 7.X 的systemd系統服務查看

  CentOS從7.X起,就開始使用systemd服務來替代daemon,而systemctl將替代原先的管理系統啟動和管理系統服務的相關命令,命令如下:

  systemctl list-unit-files? ? ?#查看所有服務以及狀態

[root@centos7 nginx]# systemctl list-unit-files UNIT FILE STATE proc-sys-fs-binfmt_misc.automount static dev-hugepages.mount static dev-mqueue.mount static proc-sys-fs-binfmt_misc.mount static run-vmblock\x2dfuse.mount disabled sys-fs-fuse-connections.mount static sys-kernel-config.mount static sys-kernel-debug.mount static tmp.mount disabled brandbot.path disabled systemd-ask-password-console.path static systemd-ask-password-plymouth.path static systemd-ask-password-wall.path static session-1.scope static abrt-ccpp.service enabled abrt-oops.service enabled abrt-pstoreoops.service disabled abrt-vmcore.service enabled abrt-xorg.service enabled abrtd.service enabled

? ? ?systemctl list-units? ? #查看正在運行的服務(沒有運行的服務不會顯示)

[root@centos7 ~]# systemctl list-units|grep test test.service loaded active running this is my first service

############################創建一個服務###############################
1.service放在/etc/systemd/system/multi-user.target.wants/目錄下
[root@centos7 ~]# cat /etc/redhat-release?
CentOS Linux release 7.9.2009 (Core)
[root@centos7 ~]# cat>/etc/systemd/system/multi-user.target.wants/test.service<<EOF
[Unit]
Description=this is my first service

[Service]
ExecStart=/bin/bash /root/test.sh? ? ? ? ? ? # /root/test.sh為腳本文件

[Install]
WantedBy=multi-user.target
EOF
[root@centos7 ~]# cat test.sh?
count=1
while [ 1 ]
do
echo $count
sleep 5
((count+=1))
done
[root@centos7 ~]# systemctl daemon-reload? ? ? #使test.service生效
[root@centos7 ~]# systemctl start test.service

[root@centos7 ~]# journalctl -u test? ?#查看日志
-- Logs begin at Thu 2022-11-03 22:43:00 EDT, end at Thu 2022-11-03 23:07:10 EDT. --
Nov 03 22:43:04 centos7 systemd[1]: Started this is my first service.
Nov 03 22:43:04 centos7 bash[895]: 1
Nov 03 22:43:09 centos7 bash[895]: 2
Nov 03 22:43:14 centos7 bash[895]: 3
Nov 03 22:43:19 centos7 bash[895]: 4
Nov 03 22:43:24 centos7 bash[895]: 5
Nov 03 22:43:29 centos7 bash[895]: 6

2.service放在/usr/lib/systemd/system/multi-user.target.wants/目錄下
[root@centos7 ~]#?cat>/usr/lib/systemd/system/zidingyi.service<<EOF
[Unit]
Description=this is my ceshi

[Service]
ExecStart=/bin/bash /root/zidingyi.sh

[Install]
WantedBy=multi-user.target
EOF
[root@centos7 ~]# cat zidingyi.sh?
echo 1
count=10
while [ 1 ]
do
echo $count
sleep 5
((count+=1))
done
[root@centos7 ~]# systemctl daemon-reload
[root@centos7 ~]# systemctl status zidingyi.service?
● zidingyi.service - this is my ceshi
? ?Loaded: loaded (/usr/lib/systemd/system/zidingyi.service; disabled; vendor preset: disabled)
? ?Active: inactive (dead)
[root@centos7 ~]# systemctl enable --now zidingyi.service?
Created symlink from /etc/systemd/system/multi-user.target.wants/zidingyi.service to /usr/lib/systemd/system/zidingyi.service.

?#############################################################################

2、使用netstat命令

  相信大家對netstat命令一定不陌生,此命令常用來檢查活動的網絡連接、接口統計分析以及路由表達式,netstat命令適用于所有的Linux發行版本,那如何用它來查看系統服務呢?命令如下:

  netstat -pnltu

3、通過系統服務配置文件查看系統服務

  服務配置文件是/etc/services,它是一個ASCII文件,包含了一系列的用戶程序可能會用到的服務,在此文件中,包括服務名稱、端口號及所使用的協議及一些別名,對于此文件,可使用任意文本工具進行查看,vim也可以:

 vim /etc/services

4、查看systemd服務狀態

  在一些相對新的Linux系統上,有很多已經用systemd來代替init進程了,那在這種系統里,該如何查看系統服務呢?命令如下:

  systemctl status service_name

  比如,查看系統上的OpenSSH是否在運行,可以使用以下命令:

  systemclt status sshd

5、早期、現如今版本的服務狀態查看

  現在依然有很多這樣的系統,上面跑著SysV init進程,對于這種系統,查看服務狀態的命令如下:

  service service_name status

  還是查看OpenSSH狀態的例子,命令如下:

  service sshd status

chkconfig

[root@iZbp16mm3xbwen89azh9ffZ ~]# chkconfig

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]'.

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
xuexi ? ? ? ? ??? ?0:off?? ?1:off?? ?2:off?? ?3:on?? ?4:on?? ?5:on?? ?6:off
說明:1.通過chkconfig添加的服務無法用systemctl命令檢索出來#systemctl list-unit-files|grep xuexi? ? ? ?結果為空
? ? ? ? ? ?2.xuexi ? ? ? ? ??? ?0:off?? ?1:off?? ?2:off?? ?3:on?? ?4:on?? ?5:on?? ?6:off表示在345系統運行級別下xuexi程序會開機自啟動
取消服務:chkconfig --level 5 xuexi off? ? #取消運行級別5下xuexi程序的開機自啟動,systemctl disable xuexi不可用

總結

以上是生活随笔為你收集整理的linux系统的服务的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。