自動化運維工具-Ansible實戰指南

這是我參與8月更文挑戰的第7天javascript

@TOChtml


前言

往期Ansible目錄 一、自動化運維工具-Ansible實戰指南 二、自動化運維工具-Ansible的Playbook的使用 三、自動化運維工具-Ansible的Roles的使用 四、B站學習連接java

1、Ansible簡介

1.ansible是什麼?

ansible是新出現的自動化運維工具,基於Python開發,集合了衆多運維工具(puppet、chef、func、fabric)的優勢,實現了批量系統配置、批量程序部署、批量運行命令等功能。node

簡單來講ansible是一種架構,自己沒有批量部署的能力批量部署能力是由模塊來提供的!並且不須要在被控制的主機上安裝任何東西,由於ansible是經過ssh協議來與遠程主機通信的python

2.ansible特色

  1. 部署簡單,只需在主控端部署Ansible環境,被控端無需作任何操做;
  2. 默認使用SSH協議對設備進行管理;
  3. 有大量常規運維操做模塊,可實現平常絕大部分操做;
  4. 配置簡單、功能強大、擴展性強;
  5. 支持API及自定義模塊,可經過Python輕鬆擴展;
  6. 經過Playbooks來定製強大的配置、狀態管理;
  7. 輕量級,無需在客戶端安裝agent,更新時,只需在操做機上進行一次更新便可;

3.ansible架構

在這裏插入圖片描述

主要模塊

  • Ansible:ansible核心程序
  • HostInventory:主機清單,記錄由Ansible管理的主機信息,包括端口、密碼、ip等。
  • Playbooks:劇本,YAML格式文件,多個任務定義在一個文件中,定義主機須要調用哪些模塊來完成的功能。
  • CoreModules:核心模塊,主要操做是經過調用核心模塊來完成管理任務。
  • CustomModules:自定義模塊,完成核心模塊沒法完成的功能,支持多種語言。
  • ConnectionPlugins:鏈接插件,Ansible和Host通訊使用

工做流程

  1. 用戶使用ansible程序
  2. ansible查看主機清單(HostInventory)
  3. ansible知道要控制的都有誰了,開始調用模塊、劇本或角色
  4. 經過鏈接模塊鏈接遠程主機,部署任務開始

命令執行過程

  1. 加載本身的配置文件,默認/etc/ansible/ansible.cfg;
  2. 查找對應的主機配置文件,找到要執行的主機或者組;
  3. 加載本身對應的模塊文件,如 command;
  4. 經過ansible將模塊或命令生成對應的臨時py文件(python腳本), 並將該文件傳輸至遠程服務器;
  5. 對應生成用戶的家目錄的.ansible/tmp/XXX/XXX.PY文件;
  6. 給文件 +x 執行權限;
  7. 執行並返回結果;
  8. 刪除臨時py文件,sleep 0退出;

2、Ansible 配置

1 安裝ansible

參考個人另外一篇連接,經過yum來安裝ansibleblog.csdn.net/qq_45714272…linux

2 目錄結構

安裝目錄以下(yum安裝):   配置文件目錄:/etc/ansible/   執行文件目錄:/usr/bin/   Lib庫依賴目錄:/usr/lib/pythonX.X/site-packages/ansible/   Help文檔目錄:/usr/share/doc/ansible-X.X.X/   Man文檔目錄:/usr/share/man/man1/nginx

3 ansible配置文件

  ansible 的配置文件爲/etc/ansible/ansible.cfg,ansible 有許多參數,下面咱們列出一些常見的參數:shell

inventory = /etc/ansible/hosts		#這個參數表示資源清單inventory文件的位置
library = /usr/share/ansible		#指向存放Ansible模塊的目錄,支持多個目錄方式,只要用冒號(:)隔開就能夠
forks = 5		#併發鏈接數,默認爲5
sudo_user = root		#設置默認執行命令的用戶
remote_port = 22		#指定鏈接被管節點的管理端口,默認爲22端口,建議修改,可以更加安全
host_key_checking = False		#設置是否檢查SSH主機的密鑰,值爲True/False。關閉後第一次鏈接不會提示配置實例
timeout = 60		#設置SSH鏈接的超時時間,單位爲秒
log_path = /var/log/ansible.log		#指定一個存儲ansible日誌的文件(默認不記錄日誌)
複製代碼

4 ansible主機清單

有多種定義方式:apache

1、 直接指明主機地址或主機名:
192.168.100.10

2、定義一個組名,把主機加進去,固然也能夠用通配符來匹配!
[test]
192.168.100.[1:3]0

....
...
...

"/etc/ansible/hosts" 57L, 1169C                                                    1,1 
複製代碼

5 ansible顏色

Ansible執行的時候根據結果會顯示爲綠色(成功執行),黃色(成功伴隨狀態改變)和紅色(執行失敗)等顏色,顏色的顯示與changed的狀態相關聯,並能夠在ansible.cfg中進行定製顏色的設定。vim

3、Ansible 經常使用命令

1 ansible 命令集

/usr/bin/ansible  Ansibe AD-Hoc 臨時命令執行工具,經常使用於臨時命令的執行 /usr/bin/ansible-doc   Ansible 模塊幫助文檔 /usr/bin/ansible-galaxy  下載/上傳優秀代碼或Roles模塊 的官網平臺 /usr/bin/ansible-playbook  Ansible 任務集編排工具 /usr/bin/ansible-pull  Ansible遠程執行命令的工具,拉取配置而非推送配置(使用較少,海量機器時使用,對運維的架構能力要求較高) /usr/bin/ansible-vault  Ansible 文件加密工具 /usr/bin/ansible-console  Ansible基於Linux Consoble界面可與用戶交互的命令執行工具

  其中,咱們比較經常使用的是/usr/bin/ansible和/usr/bin/ansible-playbook。

2 ansible-doc 命令

[root@ansible ~]# ansible-doc
Usage: ansible-doc [options] [module...]

Options:
  -h, --help            show this help message and exit  # 顯示命令參數API文檔
  -l, --list            List available modules  #列出可用的模塊
  -M MODULE_PATH, --module-path=MODULE_PATH  #指定模塊的路徑
                        specify path(s) to module library (default=None) -s, --snippet Show playbook snippet for specified module(s)  #顯示playbook制定模塊的用法 -v, --verbose verbose mode (-vvv for more, -vvvv to enable  # 顯示ansible-doc的版本號查看模塊列表: connection debugging) --version show program's version number and exit 複製代碼

例如:

[root@ansible ansible]# ansible-doc -l |grep nginx
nginx_status_info                                             Retrieve information on nginx stat...
nginx_status_facts                                            Retrieve nginx status facts  

[root@ansible ansible]# ansible-doc -s nginx_status_info
- name: Retrieve information on nginx status.
  nginx_status_info:
      timeout:               # HTTP connection timeout in seconds.
      url:                   # (required) URL of the nginx status.

複製代碼

3 ansible 命令格式

命令的具體格式以下: ansible host-pattern -m 模塊名 -a ‘參數’

經過ansible -h查看

[root@ansible ansible]# ansible -h
-a MODULE_ARGS   #模塊的參數,若是執行默認COMMAND的模塊,便是命令參數,如: 「date」,「pwd」等等
-k,--ask-pass #ask for SSH password。登陸密碼,提示輸入SSH密碼而不是假設基於密鑰的驗證
--ask-su-pass #ask for su password。su切換密碼
-K,--ask-sudo-pass #ask for sudo password。提示密碼使用sudo,sudo表示提權操做
--ask-vault-pass #ask for vault password。假設咱們設定了加密的密碼,則用該選項進行訪問
-B SECONDS #後臺運行超時時間
-C #模擬運行環境並進行預運行,能夠進行查錯測試
-c CONNECTION #鏈接類型使用
-f FORKS #並行任務數,默認爲5
-i INVENTORY #指定主機清單的路徑,默認爲/etc/ansible/hosts
--list-hosts #查看有哪些主機組
-m MODULE_NAME #執行模塊的名字,默認使用 command 模塊,因此若是是隻執行單一命令能夠不用 -m參數
-o #壓縮輸出,嘗試將全部結果在一行輸出,通常針對收集工具使用
-S #用 su 命令
-R SU_USER #指定 su 的用戶,默認爲 root 用戶
-s #用 sudo 命令
-U SUDO_USER #指定 sudo 到哪一個用戶,默認爲 root 用戶
-T TIMEOUT #指定 ssh 默認超時時間,默認爲10s,也可在配置文件中修改
-u REMOTE_USER #遠程用戶,默認爲 root 用戶
-v #查看詳細信息,同時支持-vvv,-vvvv可查看更詳細信息
複製代碼

4 ssh免密登陸

原理

在這裏插入圖片描述

實驗

#1.生成私鑰
[root@ansible ~]# ssh-keygen 
#2.向主機分發私鑰
[root@ansible ~]# ssh-copy-id root@192.168.100.10
[root@ansible ~]# ssh-copy-id root@192.168.100.20
複製代碼

4、Ansible 經常使用模塊

1 ping模塊

[root@ansible ~]# ansible 192.168.100.10 -m ping 
192.168.100.10 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false, 
    "ping": "pong"
}
複製代碼

 這樣就說明咱們的主機是連通狀態的。接下來的操做才能夠正常進行。

2 shell模塊

shell模塊很經常使用,它能夠在遠程主機上調用shell解釋器運行命令

[root@ansible ~]# head -10 /etc/ansible/hosts 
[test]
192.168.100.[1:3]0

[wsr]
192.168.100.10 http_port=81
192.168.100.20 http_port=82

[wsr:vars]
nodename=mail
domainname=edu
[root@ansible ~]# ansible wsr -m shell -a 'ls -l'
192.168.100.10 | CHANGED | rc=0 >>
total 188
drwxr-xr-x. 2 root root      6 Aug 11  2020 a
-rw-------. 1 root root   1260 Jun  3  2020 anaconda-ks.cfg
-rw-r--r--. 1 root root      0 Aug 11  2020 b
-rw-r--r--  1 root root     13 Jun 21 04:09 f4
-rw-r--r--  1 root root   6540 Jun 21 04:22 log.tar.xz
lrwxrwxrwx. 1 root root     17 Jun 20 22:30 selinux -> ../selinux/config
drwxr-xr-x. 2 root root     25 Jun 20 22:08 sh
-rw-r--r--  1 root root 175412 Jun 22 03:53 vsftpd-3.0.2-25.el7.x86_64.rpm
192.168.100.20 | CHANGED | rc=0 >>
total 188
drwxr-xr-x. 2 root root      6 Aug 11  2020 a
-rw-------. 1 root root   1260 Jun  3  2020 anaconda-ks.cfg
-rw-r--r--. 1 root root      0 Aug 11  2020 b
-rw-r--r--  1 root root     13 Jun 21 04:09 f4
-rw-r--r--  1 root root   6516 Jun 21 04:22 log.tar.xz
-rw-r--r--  1 root root 175412 Jun 22 03:53 vsftpd-3.0.2-25.el7.x86_64.rpm

# 總結
<font color=#999AAA >提示:
複製代碼

3 command模塊

這個模塊能夠直接在遠程主機上執行命令,並將結果返回本主機。

命令模塊接受命令名稱,後面是空格分隔的列表參數。給定的命令將在全部選定的節點上執行。它不會經過shell進行處理,好比$HOME和操做如"<",">","|",";","&"工做(須要使用(shell)模塊實現這些功能)。

 

下面來看一看該模塊下經常使用的幾個命令:

  • chdir       # 在執行命令以前,先切換到該目錄 executable # 切換shell來執行命令,須要使用命令的絕對路徑
  • free_form   # 要執行的Linux指令,通常使用Ansible的-a參數代替。
  • creates # 一個文件名,當這個文件存在,則該命令不執行,能夠

用來作判斷

  • removes # 一個文件名,這個文件不存在,則該命令不執行
[root@ansible ~]# ansible wsr -m command -a 'chdir=/data ls'
192.168.100.20 | CHANGED | rc=0 >>
file1
file2
file3
for1.conf
for2.conf
for3.conf
httpd.conf
192.168.100.10 | CHANGED | rc=0 >>
file1
file2
file3
for1.conf
for2.conf
for3.conf
httpd.conf
複製代碼

4 copy模塊

這個模塊用於將文件複製到遠程主機,同時支持給定內容生成文件和修改權限等。 其相關選項以下:

  • src    #被複制到遠程主機的本地文件。能夠是絕對路徑,也能夠是相對路徑。若是路徑是一個目錄,則會遞歸複製,用法相似於"rsync"
  • content   #用於替換"src",能夠直接指定文件的值
  • dest    #必選項,將源文件複製到的遠程主機的絕對路徑
  • backup   #當文件內容發生改變後,在覆蓋以前把源文件備份,備份文件包含時間信息
  • directory_mode    #遞歸設定目錄的權限,默認爲系統默認權限
  • force    #當目標主機包含該文件,但內容不一樣時,設爲"yes",表示強制覆蓋;設爲"no",表示目標主機的目標位置不存在該文件才複製。默認爲"yes"
  • others    #全部的 file 模塊中的選項能夠在這裏使用

其中src,dest,backup,mode用的較多

複製

[root@ansible ~]# touch 2021710
[root@ansible ~]# ansible wsr -m copy -a 'src=2021710 dest=/data/2021710'
192.168.100.10 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "checksum": "da39a3ee5e6b4b0d3255bfef95601890afd80709", 
    "dest": "/data/2021710", 
    "gid": 0, 
    "group": "root", 
    "md5sum": "d41d8cd98f00b204e9800998ecf8427e", 
    "mode": "0644", 
    "owner": "root", 
    "size": 0, 
    "src": "/root/.ansible/tmp/ansible-tmp-1625931089.28-8051-80193366038951/source", 
    "state": "file", 
    "uid": 0
}
192.168.100.20 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "checksum": "da39a3ee5e6b4b0d3255bfef95601890afd80709", 
    "dest": "/data/2021710", 
    "gid": 0, 
    "group": "root", 
    "md5sum": "d41d8cd98f00b204e9800998ecf8427e", 
    "mode": "0644", 
    "owner": "root", 
    "size": 0, 
    "src": "/root/.ansible/tmp/ansible-tmp-1625931089.28-8052-82580429716175/source", 
    "state": "file", 
    "uid": 0
}
複製代碼

權限和備份

[root@ansible ~]# ansible wsr -m copy -a 'content="i am bad boy\n" backup=yes dest=/data/2021710 mode=666'
192.168.100.10 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "backup_file": "/data/2021710.11493.2021-07-10@11:32:39~", 
    "changed": true, 
    "checksum": "444281122cde3d31fa394ffe2d29d9a1fa2411f3", 
    "dest": "/data/2021710", 
    "gid": 0, 
    "group": "root", 
    "md5sum": "e2ea0ae0489f588fd0e7adcdc361ff70", 
    "mode": "0666", 
    "owner": "root", 
    "size": 13, 
    "src": "/root/.ansible/tmp/ansible-tmp-1625931158.27-8105-89064400502466/source", 
    "state": "file", 
    "uid": 0
}
192.168.100.20 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "backup_file": "/data/2021710.11427.2021-07-10@11:32:39~", 
    "changed": true, 
    "checksum": "444281122cde3d31fa394ffe2d29d9a1fa2411f3", 
    "dest": "/data/2021710", 
    "gid": 0, 
    "group": "root", 
    "md5sum": "e2ea0ae0489f588fd0e7adcdc361ff70", 
    "mode": "0666", 
    "owner": "root", 
    "size": 13, 
    "src": "/root/.ansible/tmp/ansible-tmp-1625931158.28-8106-201363635505942/source", 
    "state": "file", 
    "uid": 0
}

複製代碼

檢測

其中一大串名字的就是備份後的名字,也能夠看到權限爲666

[root@ansible ~]# ansible wsr -m shell -a 'ls -l /data'
192.168.100.10 | CHANGED | rc=0 >>
total 32
-rw-rw-rw- 1 root   root    13 Jul 10 11:32 2021710
-rw-r--r-- 1 root   root     0 Jul 10 11:31 2021710.11493.2021-07-10@11:32:39~
-rw-rw-rw- 1 root   root    21 Jul 10 11:20 a.sh
-rw-r--r-- 1 root   root     0 Jul  3 23:14 file1
-rw-r--r-- 1 root   root     0 Jul  3 23:14 file2
-rw-r--r-- 1 root   root     0 Jul  3 23:14 file3
-rw-r--r-- 1 root   root    63 Jul  4 11:51 for1.conf
-rw-r--r-- 1 root   root   267 Jul  4 12:06 for2.conf
-rw-r--r-- 1 root   root   171 Jul  5 04:05 for3.conf
-rw-r--r-- 1 apache root 11753 Jul 10 03:21 httpd.conf
192.168.100.20 | CHANGED | rc=0 >>
total 32
-rw-rw-rw- 1 root   root    13 Jul 10 11:32 2021710
-rw-r--r-- 1 root   root     0 Jul 10 11:31 2021710.11427.2021-07-10@11:32:39~
-rw-rw-rw- 1 root   root    21 Jul 10 11:20 a.sh
-rw-r--r-- 1 root   root     0 Jul  3 23:14 file1
-rw-r--r-- 1 root   root     0 Jul  3 23:14 file2
-rw-r--r-- 1 root   root     0 Jul  3 23:14 file3
-rw-r--r-- 1 root   root    63 Jul  4 11:51 for1.conf
-rw-r--r-- 1 root   root   267 Jul  4 12:06 for2.conf
-rw-r--r-- 1 root   root   171 Jul  5 04:05 for3.conf
-rw-r--r-- 1 apache root 11753 Jul 10 03:21 httpd.conf
複製代碼

5 yum模塊

經過yum裝包 其選項以下:

  • name=  #所安裝的包的名稱
  • state=  #present--->安裝, latest--->安裝最新的, absent---> 卸載軟件。
  • 其他不經常使用的就不列舉了

安裝

state默認爲present

[root@ansible ~]# ansible wsr -m yum -a 'name=vim'
192.168.100.20 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "changes": {
        "installed": [
            "vim"
        ]
    }, 
    "msg": "Repository base is listed more than once in the configuration\nRepository updates is listed more than once in the configuration\nRepository extras is listed more than once in the configuration\nRepository centosplus is listed more than once in the configuration\nRepository epel is listed more than once in the configuration\nRepository epel-debuginfo is listed more than once in the configuration\nRepository epel-source is listed more than once in the configuration\n", 
    "rc": 0, 
    "results": [
        "Loaded plugins: fastestmirror\nLoading mirror speeds from cached hostfile\nResolving Dependencies\n--> Running transaction check\n---> Package vim-enhanced.x86_64 2:7.4.629-8.el7_9 will be installed\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package Arch Version Repository Size\n================================================================================\nInstalling:\n vim-enhanced x86_64 2:7.4.629-8.el7_9 updates 1.1 M\n\nTransaction Summary\n================================================================================\nInstall 1 Package\n\nTotal download size: 1.1 M\nInstalled size: 2.2 M\nDownloading packages:\nRunning transaction check\nRunning transaction test\nTransaction test succeeded\nRunning transaction\n Installing : 2:vim-enhanced-7.4.629-8.el7_9.x86_64 1/1 \n Verifying : 2:vim-enhanced-7.4.629-8.el7_9.x86_64 1/1 \n\nInstalled:\n vim-enhanced.x86_64 2:7.4.629-8.el7_9 \n\nComplete!\n"
    ]
}
192.168.100.10 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "changes": {
        "installed": [
            "vim"
        ]
    }, 
    "msg": "Repository base is listed more than once in the configuration\nRepository updates is listed more than once in the configuration\nRepository extras is listed more than once in the configuration\nRepository centosplus is listed more than once in the configuration\nRepository epel is listed more than once in the configuration\nRepository epel-debuginfo is listed more than once in the configuration\nRepository epel-source is listed more than once in the configuration\n", 
    "rc": 0, 
    "results": [
        "Loaded plugins: fastestmirror\nLoading mirror speeds from cached hostfile\nResolving Dependencies\n--> Running transaction check\n---> Package vim-enhanced.x86_64 2:7.4.629-8.el7_9 will be installed\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package Arch Version Repository Size\n================================================================================\nInstalling:\n vim-enhanced x86_64 2:7.4.629-8.el7_9 updates 1.1 M\n\nTransaction Summary\n================================================================================\nInstall 1 Package\n\nTotal download size: 1.1 M\nInstalled size: 2.2 M\nDownloading packages:\nRunning transaction check\nRunning transaction test\nTransaction test succeeded\nRunning transaction\n Installing : 2:vim-enhanced-7.4.629-8.el7_9.x86_64 1/1 \n Verifying : 2:vim-enhanced-7.4.629-8.el7_9.x86_64 1/1 \n\nInstalled:\n vim-enhanced.x86_64 2:7.4.629-8.el7_9 \n\nComplete!\n"
    ]
}
複製代碼

卸載

改變state的狀態爲absent便可

[root@ansible ~]# ansible wsr -m yum -a 'name=vim state=absent'
192.168.100.20 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "changes": {
        "removed": [
            "vim"
        ]
    }, 
    "msg": "Repository base is listed more than once in the configuration\nRepository updates is listed more than once in the configuration\nRepository extras is listed more than once in the configuration\nRepository centosplus is listed more than once in the configuration\nRepository epel is listed more than once in the configuration\nRepository epel-debuginfo is listed more than once in the configuration\nRepository epel-source is listed more than once in the configuration\n", 
    "rc": 0, 
    "results": [
        "Loaded plugins: fastestmirror\nResolving Dependencies\n--> Running transaction check\n---> Package vim-enhanced.x86_64 2:7.4.629-8.el7_9 will be erased\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package            Arch         Version                   Repository      Size\n================================================================================\nRemoving:\n vim-enhanced       x86_64       2:7.4.629-8.el7_9         @updates       2.2 M\n\nTransaction Summary\n================================================================================\nRemove  1 Package\n\nInstalled size: 2.2 M\nDownloading packages:\nRunning transaction check\nRunning transaction test\nTransaction test succeeded\nRunning transaction\n  Erasing    : 2:vim-enhanced-7.4.629-8.el7_9.x86_64                        1/1 \n  Verifying  : 2:vim-enhanced-7.4.629-8.el7_9.x86_64                        1/1 \n\nRemoved:\n  vim-enhanced.x86_64 2:7.4.629-8.el7_9                                         \n\nComplete!\n"
    ]
}
192.168.100.10 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "changes": {
        "removed": [
            "vim"
        ]
    }, 
    "msg": "Repository base is listed more than once in the configuration\nRepository updates is listed more than once in the configuration\nRepository extras is listed more than once in the configuration\nRepository centosplus is listed more than once in the configuration\nRepository epel is listed more than once in the configuration\nRepository epel-debuginfo is listed more than once in the configuration\nRepository epel-source is listed more than once in the configuration\n", 
    "rc": 0, 
    "results": [
        "Loaded plugins: fastestmirror\nResolving Dependencies\n--> Running transaction check\n---> Package vim-enhanced.x86_64 2:7.4.629-8.el7_9 will be erased\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package            Arch         Version                   Repository      Size\n================================================================================\nRemoving:\n vim-enhanced       x86_64       2:7.4.629-8.el7_9         @updates       2.2 M\n\nTransaction Summary\n================================================================================\nRemove  1 Package\n\nInstalled size: 2.2 M\nDownloading packages:\nRunning transaction check\nRunning transaction test\nTransaction test succeeded\nRunning transaction\n  Erasing    : 2:vim-enhanced-7.4.629-8.el7_9.x86_64                        1/1 \n  Verifying  : 2:vim-enhanced-7.4.629-8.el7_9.x86_64                        1/1 \n\nRemoved:\n  vim-enhanced.x86_64 2:7.4.629-8.el7_9                                         \n\nComplete!\n"
    ]
}
複製代碼

6 file模塊

 該模塊主要用於設置文件的屬性,好比建立文件、建立連接文件、刪除文件等。 下面是一些常見的命令:

force  #須要在兩種狀況下強制建立軟連接,一種是源文件不存在,但以後會創建的狀況下;另外一種是目標軟連接已存在,須要先取消以前的軟鏈,而後建立新的軟鏈,有兩個選項:yes|no
group  #定義文件/目錄的屬組。後面能夠加上mode:定義文件/目錄的權限
owner  #定義文件/目錄的屬主。後面必須跟上path:定義文件/目錄的路徑
recurse  #遞歸設置文件的屬性,只對目錄有效,後面跟上src:被連接的源文件路徑,只應用於state=link的狀況
dest  #被連接到的路徑,只應用於state=link的狀況
state  #狀態,有如下選項:

directory:若是目錄不存在,就建立目錄
file:即便文件不存在,也不會被建立
link:建立軟連接
hard:建立硬連接
touch:若是文件不存在,則會建立一個新的文件,若是文件或目錄已存在,則更新其最後修改時間
absent:刪除目錄、文件或者取消連接文件
複製代碼

建立文件夾

[root@ansible ~]# ansible wsr -m file -a 'path=/data/2339 state=directory'
192.168.100.20 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "gid": 0, 
    "group": "root", 
    "mode": "0755", 
    "owner": "root", 
    "path": "/data/2339", 
    "size": 6, 
    "state": "directory", 
    "uid": 0
}
192.168.100.10 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "gid": 0, 
    "group": "root", 
    "mode": "0755", 
    "owner": "root", 
    "path": "/data/2339", 
    "size": 6, 
    "state": "directory", 
    "uid": 0
}
複製代碼

建立連接文件

[root@ansible ~]# ansible wsr -m file -a 'path=/data/2340 src=2339 state=link'
192.168.100.10 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "dest": "/data/2340", 
    "gid": 0, 
    "group": "root", 
    "mode": "0777", 
    "owner": "root", 
    "size": 4, 
    "src": "2339", 
    "state": "link", 
    "uid": 0
}
192.168.100.20 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "dest": "/data/2340", 
    "gid": 0, 
    "group": "root", 
    "mode": "0777", 
    "owner": "root", 
    "size": 4, 
    "src": "2339", 
    "state": "link", 
    "uid": 0
}

測試
[root@ansible ~]# ansible wsr -a 'ls -l /data'
192.168.100.20 | CHANGED | rc=0 >>
total 32
-rw-rw-rw- 1 root   root    13 Jul 10 11:32 2021710
-rw-r--r-- 1 root   root     0 Jul 10 11:31 2021710.11427.2021-07-10@11:32:39~
drwxr-xr-x 2 root   root     6 Jul 10 11:40 2339
lrwxrwxrwx 1 root   root     4 Jul 10 11:42 2340 -> 2339
-rw-rw-rw- 1 root   root    21 Jul 10 11:20 a.sh
-rw-r--r-- 1 root   root     0 Jul  3 23:14 file1
-rw-r--r-- 1 root   root     0 Jul  3 23:14 file2
-rw-r--r-- 1 root   root     0 Jul  3 23:14 file3
-rw-r--r-- 1 root   root    63 Jul  4 11:51 for1.conf
-rw-r--r-- 1 root   root   267 Jul  4 12:06 for2.conf
-rw-r--r-- 1 root   root   171 Jul  5 04:05 for3.conf
-rw-r--r-- 1 apache root 11753 Jul 10 03:21 httpd.conf
192.168.100.10 | CHANGED | rc=0 >>
total 32
-rw-rw-rw- 1 root   root    13 Jul 10 11:32 2021710
-rw-r--r-- 1 root   root     0 Jul 10 11:31 2021710.11493.2021-07-10@11:32:39~
drwxr-xr-x 2 root   root     6 Jul 10 11:40 2339
lrwxrwxrwx 1 root   root     4 Jul 10 11:42 2340 -> 2339
-rw-rw-rw- 1 root   root    21 Jul 10 11:20 a.sh
-rw-r--r-- 1 root   root     0 Jul  3 23:14 file1
-rw-r--r-- 1 root   root     0 Jul  3 23:14 file2
-rw-r--r-- 1 root   root     0 Jul  3 23:14 file3
-rw-r--r-- 1 root   root    63 Jul  4 11:51 for1.conf
-rw-r--r-- 1 root   root   267 Jul  4 12:06 for2.conf
-rw-r--r-- 1 root   root   171 Jul  5 04:05 for3.conf
-rw-r--r-- 1 apache root 11753 Jul 10 03:21 httpd.conf
複製代碼

刪除文件

只需把state改成absent便可 [root@ansible ~]# ansible wsr -m file -a 'path=/data/2339 state=absent'

7 cron模塊

該模塊適用於管理cron計劃任務的。   其使用的語法跟咱們的crontab文件中的語法一致

  • day= #日應該運行的工做( 1-31, *, */2, )
  • hour= # 小時 ( 0-23, *, */2, )
  • minute= #分鐘( 0-59, *, */2, )
  • month= # 月( 1-12, *, /2, )
  • weekday= # 周 ( 0-6 for Sunday-Saturday,, )
  • job= #指明運行的命令是什麼
  • name= #定時任務描述
  • reboot # 任務在重啓時運行,不建議使用,建議使用special_time
  • special_time #特殊的時間範圍,參數:reboot(重啓時),annually(每一年),monthly(每個月),weekly(每週),daily(天天),hourly(每小時)
  • state #指定狀態,present表示添加定時任務,也是默認設置,absent表示刪除定時任務
  • user # 以哪一個用戶的身份執行
[root@ansible ~]# ansible wsr -m cron -a 'name="echo words" minute=*/5 job="echo hello world"'
192.168.100.10 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "envs": [], 
    "jobs": [
        "warningcron", 
        "None", 
        "echo words"
    ]
}
192.168.100.20 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "envs": [], 
    "jobs": [
        "warningcron", 
        "None", 
        "echo words"
    ]
}

測試結果
[root@ansible ~]# ansible wsr -a 'crontab -l'
192.168.100.10 | CHANGED | rc=0 >>
#Ansible: warningcron
#* * * * 1,3,5 /usr/bin/wall FBI warning
#Ansible: None
#* * * * * /usr/bin/wall FBI warning
#Ansible: echo words
*/5 * * * * echo hello world
192.168.100.20 | CHANGED | rc=0 >>
#Ansible: warningcron
#* * * * 1,3,5 /usr/bin/wall FBI warning
#Ansible: None
#* * * * * /usr/bin/wall FBI warning
#Ansible: echo words
*/5 * * * * echo hello world
複製代碼

mission completely!!!

8 user模塊

該模塊主要是用來管理帳戶的

  • comment  # 用戶的描述信息
  • createhome  # 是否建立家目錄
  • force  # 在使用state=absent時, 行爲與userdel –force一致.
  • group  # 指定基本組
  • groups  # 指定附加組,若是指定爲(groups=)表示刪除全部組
  • home  # 指定用戶家目錄
  • move_home  # 若是設置爲home=時, 試圖將用戶主目錄移動到指定的目錄
  • name  # 指定用戶名
  • non_unique  # 該選項容許改變非惟一的用戶ID值
  • password  # 指定用戶密碼
  • remove  # 在使用state=absent時, 行爲是與userdel –remove一致
  • shell  # 指定默認shell
  • state  # 設置賬號狀態,不指定爲建立,指定值爲absent表示刪除
  • system  # 當建立一個用戶,設置這個用戶是系統用戶。這個設置不能更改現有用戶
  • uid  # 指定用戶的uid

添加一個用戶並指定 uid

[root@ansible ~]# ansible wsr -m user -a 'name=zs uid=66666'
192.168.100.10 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "comment": "", 
    "create_home": true, 
    "group": 1005, 
    "home": "/home/zs", 
    "name": "zs", 
    "shell": "/bin/bash", 
    "state": "present", 
    "system": false, 
    "uid": 66666
}
192.168.100.20 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "comment": "", 
    "create_home": true, 
    "group": 1005, 
    "home": "/home/zs", 
    "name": "zs", 
    "shell": "/bin/bash", 
    "state": "present", 
    "system": false, 
    "uid": 66666
}
複製代碼
[root@ansible ~]# ansible wsr -m shell -a 'getent passwd|grep zs'
192.168.100.10 | CHANGED | rc=0 >>
zs:x:66666:1005::/home/zs:/bin/bash
192.168.100.20 | CHANGED | rc=0 >>
zs:x:66666:1005::/home/zs:/bin/bash
複製代碼

刪除用戶

指定狀態爲absent便可

[root@ansible ~]# ansible wsr -m user -a 'name=zs uid=66666 state=absent'
192.168.100.10 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "force": false, 
    "name": "zs", 
    "remove": false, 
    "state": "absent"
}
192.168.100.20 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "force": false, 
    "name": "zs", 
    "remove": false, 
    "state": "absent"
}
複製代碼
[root@ansible ~]# ansible wsr -m shell -a 'getent passwd|grep zs'
192.168.100.10 | FAILED | rc=1 >>
non-zero return code
192.168.100.20 | FAILED | rc=1 >>
non-zero return code
複製代碼

9 group模塊

該模塊主要用於添加或刪除組。 經常使用的選項以下:

  • gid=  #設置組的GID號
  • name=  #指定組的名稱
  • state=  #指定組的狀態,默認爲建立,設置值爲absent爲刪除
  • system=  #設置值爲yes,表示建立爲系統組

創建組並指定gid

[root@ansible ~]# ansible wsr -m group -a 'name=ls gid=888888'
192.168.100.20 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "gid": 888888, 
    "name": "ls", 
    "state": "present", 
    "system": false
}
192.168.100.10 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "gid": 888888, 
    "name": "ls", 
    "state": "present", 
    "system": false
}
複製代碼
[root@ansible ~]# ansible wsr -m shell -a 'cat /etc/group |grep 888888'
192.168.100.10 | CHANGED | rc=0 >>
ls:x:888888:
192.168.100.20 | CHANGED | rc=0 >>
ls:x:888888:
複製代碼

刪除組

指定state爲absent便可刪除

[root@ansible ~]# ansible wsr -m group -a 'name=ls state=absent'
192.168.100.20 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "name": "ls", 
    "state": "absent"
}
192.168.100.10 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "name": "ls", 
    "state": "absent"
}
複製代碼

10 script模塊

該模塊用於將本機的腳本在被管理端的機器上運行。

[root@ansible tmp]# cat df.sh 
#!/bin/bash

	date >> /tmp/disk_total.log
	df -lh >> /tmp/disk_total.log 

複製代碼
[root@ansible tmp]# ansible wsr -m script -a '/tmp/df.sh'
192.168.100.10 | CHANGED => {
    "changed": true, 
    "rc": 0, 
    "stderr": "Shared connection to 192.168.100.10 closed.\r\n", 
    "stderr_lines": [
        "Shared connection to 192.168.100.10 closed."
    ], 
    "stdout": "", 
    "stdout_lines": []
}
192.168.100.20 | CHANGED => {
    "changed": true, 
    "rc": 0, 
    "stderr": "Shared connection to 192.168.100.20 closed.\r\n", 
    "stderr_lines": [
        "Shared connection to 192.168.100.20 closed."
    ], 
    "stdout": "", 
    "stdout_lines": []
}
複製代碼

測試

[root@ansible tmp]# ansible wsr -a 'cat /tmp/disk_total.log'
192.168.100.10 | CHANGED | rc=0 >>
Sat Jul 10 21:24:51 EDT 2021
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 475M     0  475M   0% /dev
tmpfs                    487M     0  487M   0% /dev/shm
tmpfs                    487M  7.6M  479M   2% /run
tmpfs                    487M     0  487M   0% /sys/fs/cgroup
/dev/mapper/centos-root  8.0G  1.5G  6.6G  18% /
/dev/sr0                 4.4G  4.4G     0 100% /mnt/centos
/dev/sda1               1014M  136M  879M  14% /boot
tmpfs                     98M     0   98M   0% /run/user/0
192.168.100.20 | CHANGED | rc=0 >>
Sat Jul 10 21:24:51 EDT 2021
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 475M     0  475M   0% /dev
tmpfs                    487M     0  487M   0% /dev/shm
tmpfs                    487M  7.6M  479M   2% /run
tmpfs                    487M     0  487M   0% /sys/fs/cgroup
/dev/mapper/centos-root  8.0G  1.5G  6.6G  18% /
/dev/sr0                 4.4G  4.4G     0 100% /mnt/centos
/dev/sda1               1014M  136M  879M  14% /boot
tmpfs                     98M     0   98M   0% /run/user/0
複製代碼

11 setup模塊

經過調用facts(facts就是變量,內建變量)組件來收集主機信息,如vcpu個數,內存大小等.....

能夠使用filter來查看指定信息,調用後返回不少對應主機的信息,在後面的操做中能夠根據不一樣的信息來作不一樣的操做 如redhat系列用yum安裝,而debian系列用apt來安裝軟件。

[root@ansible tmp]# ansible wsr -m setup -a 'filter=*cpu*'
192.168.100.20 | SUCCESS => {
    "ansible_facts": {
        "ansible_processor_vcpus": 2, 
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false
}
192.168.100.10 | SUCCESS => {
    "ansible_facts": {
        "ansible_processor_vcpus": 2, 
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false
}
複製代碼

12 service 模塊

該模塊用於服務程序的管理。  其主要選項以下:

  • arguments #命令行提供額外的參數
  • enabled #設置開機啓動。
  • name= #服務名稱
  • runlevel #開機啓動的級別,通常不用指定。
  • sleep #在重啓服務的過程當中,是否等待。如在服務關閉之後等待2秒再啓動。(定義在劇本中。)
  • state #有四種狀態,分別爲:started--->啓動服務, stopped--->中止服務,
  • restarted--->重啓服務, reloaded--->重載配置
[root@ansible tmp]# ansible wsr -m service -a 'name=httpd state=restarted enabled=true'
192.168.100.20 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "enabled": true, 
    "name": "httpd", 
    "state": "started", 
    "status": {
        "ActiveEnterTimestampMonotonic": "0", 
        "ActiveExitTimestampMonotonic": "0", 
        "ActiveState": "inactive", 
        "After": "basic.target remote-fs.target system.slice systemd-journald.socket network.target tmp.mount nss-lookup.target -.mount", 
        "AllowIsolate": "no", 
        "AmbientCapabilities": "0", 
        "AssertResult": "no", 
        "AssertTimestampMonotonic": "0", 
        "Before": "shutdown.target", 
        "BlockIOAccounting": "no", 
        "BlockIOWeight": "18446744073709551615", 
        "CPUAccounting": "no", 
        "CPUQuotaPerSecUSec": "infinity", 
        "CPUSchedulingPolicy": "0", 
        "CPUSchedulingPriority": "0", 
        "CPUSchedulingResetOnFork": "no", 
        "CPUShares": "18446744073709551615", 
        "CanIsolate": "no", 
        "CanReload": "yes", 
        "CanStart": "yes", 
        "CanStop": "yes", 
        "CapabilityBoundingSet": "18446744073709551615", 
        "ConditionResult": "no", 
        "ConditionTimestampMonotonic": "0", 
        "Conflicts": "shutdown.target", 
        "ControlPID": "0", 
        "DefaultDependencies": "yes", 
        "Delegate": "no", 
        "Description": "The Apache HTTP Server", 
        "DevicePolicy": "auto", 
        "Documentation": "man:httpd(8) man:apachectl(8)", 
        "EnvironmentFile": "/etc/sysconfig/httpd (ignore_errors=no)", 
        "ExecMainCode": "0", 
        "ExecMainExitTimestampMonotonic": "0", 
        "ExecMainPID": "0", 
        "ExecMainStartTimestampMonotonic": "0", 
        "ExecMainStatus": "0", 
        "ExecReload": "{ path=/usr/sbin/httpd ; argv[]=/usr/sbin/httpd $OPTIONS -k graceful ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }", 
        "ExecStart": "{ path=/usr/sbin/httpd ; argv[]=/usr/sbin/httpd $OPTIONS -DFOREGROUND ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }", 
        "ExecStop": "{ path=/bin/kill ; argv[]=/bin/kill -WINCH ${MAINPID} ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }", 
        "FailureAction": "none", 
        "FileDescriptorStoreMax": "0", 
        "FragmentPath": "/usr/lib/systemd/system/httpd.service", 
        "GuessMainPID": "yes", 
        "IOScheduling": "0", 
        "Id": "httpd.service", 
        "IgnoreOnIsolate": "no", 
        "IgnoreOnSnapshot": "no", 
        "IgnoreSIGPIPE": "yes", 
        "InactiveEnterTimestampMonotonic": "0", 
        "InactiveExitTimestampMonotonic": "0", 
        "JobTimeoutAction": "none", 
        "JobTimeoutUSec": "0", 
        "KillMode": "control-group", 
        "KillSignal": "18", 
        "LimitAS": "18446744073709551615", 
        "LimitCORE": "18446744073709551615", 
        "LimitCPU": "18446744073709551615", 
        "LimitDATA": "18446744073709551615", 
        "LimitFSIZE": "18446744073709551615", 
        "LimitLOCKS": "18446744073709551615", 
        "LimitMEMLOCK": "65536", 
        "LimitMSGQUEUE": "819200", 
        "LimitNICE": "0", 
        "LimitNOFILE": "4096", 
        "LimitNPROC": "3795", 
        "LimitRSS": "18446744073709551615", 
        "LimitRTPRIO": "0", 
        "LimitRTTIME": "18446744073709551615", 
        "LimitSIGPENDING": "3795", 
        "LimitSTACK": "18446744073709551615", 
        "LoadState": "loaded", 
        "MainPID": "0", 
        "MemoryAccounting": "no", 
        "MemoryCurrent": "18446744073709551615", 
        "MemoryLimit": "18446744073709551615", 
        "MountFlags": "0", 
        "Names": "httpd.service", 
        "NeedDaemonReload": "no", 
        "Nice": "0", 
        "NoNewPrivileges": "no", 
        "NonBlocking": "no", 
        "NotifyAccess": "main", 
        "OOMScoreAdjust": "0", 
        "OnFailureJobMode": "replace", 
        "PermissionsStartOnly": "no", 
        "PrivateDevices": "no", 
        "PrivateNetwork": "no", 
        "PrivateTmp": "yes", 
        "ProtectHome": "no", 
        "ProtectSystem": "no", 
        "RefuseManualStart": "no", 
        "RefuseManualStop": "no", 
        "RemainAfterExit": "no", 
        "Requires": "-.mount basic.target", 
        "RequiresMountsFor": "/var/tmp", 
        "Restart": "no", 
        "RestartUSec": "100ms", 
        "Result": "success", 
        "RootDirectoryStartOnly": "no", 
        "RuntimeDirectoryMode": "0755", 
        "SameProcessGroup": "no", 
        "SecureBits": "0", 
        "SendSIGHUP": "no", 
        "SendSIGKILL": "yes", 
        "Slice": "system.slice", 
        "StandardError": "inherit", 
        "StandardInput": "null", 
        "StandardOutput": "journal", 
        "StartLimitAction": "none", 
        "StartLimitBurst": "5", 
        "StartLimitInterval": "10000000", 
        "StartupBlockIOWeight": "18446744073709551615", 
        "StartupCPUShares": "18446744073709551615", 
        "StatusErrno": "0", 
        "StopWhenUnneeded": "no", 
        "SubState": "dead", 
        "SyslogLevelPrefix": "yes", 
        "SyslogPriority": "30", 
        "SystemCallErrorNumber": "0", 
        "TTYReset": "no", 
        "TTYVHangup": "no", 
        "TTYVTDisallocate": "no", 
        "TasksAccounting": "no", 
        "TasksCurrent": "18446744073709551615", 
        "TasksMax": "18446744073709551615", 
        "TimeoutStartUSec": "1min 30s", 
        "TimeoutStopUSec": "1min 30s", 
        "TimerSlackNSec": "50000", 
        "Transient": "no", 
        "Type": "notify", 
        "UMask": "0022", 
        "UnitFilePreset": "disabled", 
        "UnitFileState": "disabled", 
        "Wants": "system.slice", 
        "WatchdogTimestampMonotonic": "0", 
        "WatchdogUSec": "0"
    }
}
192.168.100.10 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "enabled": true, 
    "name": "httpd", 
    "state": "started", 
    "status": {
        "ActiveEnterTimestampMonotonic": "0", 
        "ActiveExitTimestampMonotonic": "0", 
        "ActiveState": "inactive", 
        "After": "remote-fs.target nss-lookup.target tmp.mount basic.target -.mount systemd-journald.socket system.slice network.target", 
        "AllowIsolate": "no", 
        "AmbientCapabilities": "0", 
        "AssertResult": "no", 
        "AssertTimestampMonotonic": "0", 
        "Before": "shutdown.target", 
        "BlockIOAccounting": "no", 
        "BlockIOWeight": "18446744073709551615", 
        "CPUAccounting": "no", 
        "CPUQuotaPerSecUSec": "infinity", 
        "CPUSchedulingPolicy": "0", 
        "CPUSchedulingPriority": "0", 
        "CPUSchedulingResetOnFork": "no", 
        "CPUShares": "18446744073709551615", 
        "CanIsolate": "no", 
        "CanReload": "yes", 
        "CanStart": "yes", 
        "CanStop": "yes", 
        "CapabilityBoundingSet": "18446744073709551615", 
        "ConditionResult": "no", 
        "ConditionTimestampMonotonic": "0", 
        "Conflicts": "shutdown.target", 
        "ControlPID": "0", 
        "DefaultDependencies": "yes", 
        "Delegate": "no", 
        "Description": "The Apache HTTP Server", 
        "DevicePolicy": "auto", 
        "Documentation": "man:httpd(8) man:apachectl(8)", 
        "EnvironmentFile": "/etc/sysconfig/httpd (ignore_errors=no)", 
        "ExecMainCode": "0", 
        "ExecMainExitTimestampMonotonic": "0", 
        "ExecMainPID": "0", 
        "ExecMainStartTimestampMonotonic": "0", 
        "ExecMainStatus": "0", 
        "ExecReload": "{ path=/usr/sbin/httpd ; argv[]=/usr/sbin/httpd $OPTIONS -k graceful ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }", 
        "ExecStart": "{ path=/usr/sbin/httpd ; argv[]=/usr/sbin/httpd $OPTIONS -DFOREGROUND ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }", 
        "ExecStop": "{ path=/bin/kill ; argv[]=/bin/kill -WINCH ${MAINPID} ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }", 
        "FailureAction": "none", 
        "FileDescriptorStoreMax": "0", 
        "FragmentPath": "/usr/lib/systemd/system/httpd.service", 
        "GuessMainPID": "yes", 
        "IOScheduling": "0", 
        "Id": "httpd.service", 
        "IgnoreOnIsolate": "no", 
        "IgnoreOnSnapshot": "no", 
        "IgnoreSIGPIPE": "yes", 
        "InactiveEnterTimestampMonotonic": "0", 
        "InactiveExitTimestampMonotonic": "0", 
        "JobTimeoutAction": "none", 
        "JobTimeoutUSec": "0", 
        "KillMode": "control-group", 
        "KillSignal": "18", 
        "LimitAS": "18446744073709551615", 
        "LimitCORE": "18446744073709551615", 
        "LimitCPU": "18446744073709551615", 
        "LimitDATA": "18446744073709551615", 
        "LimitFSIZE": "18446744073709551615", 
        "LimitLOCKS": "18446744073709551615", 
        "LimitMEMLOCK": "65536", 
        "LimitMSGQUEUE": "819200", 
        "LimitNICE": "0", 
        "LimitNOFILE": "4096", 
        "LimitNPROC": "3795", 
        "LimitRSS": "18446744073709551615", 
        "LimitRTPRIO": "0", 
        "LimitRTTIME": "18446744073709551615", 
        "LimitSIGPENDING": "3795", 
        "LimitSTACK": "18446744073709551615", 
        "LoadState": "loaded", 
        "MainPID": "0", 
        "MemoryAccounting": "no", 
        "MemoryCurrent": "18446744073709551615", 
        "MemoryLimit": "18446744073709551615", 
        "MountFlags": "0", 
        "Names": "httpd.service", 
        "NeedDaemonReload": "no", 
        "Nice": "0", 
        "NoNewPrivileges": "no", 
        "NonBlocking": "no", 
        "NotifyAccess": "main", 
        "OOMScoreAdjust": "0", 
        "OnFailureJobMode": "replace", 
        "PermissionsStartOnly": "no", 
        "PrivateDevices": "no", 
        "PrivateNetwork": "no", 
        "PrivateTmp": "yes", 
        "ProtectHome": "no", 
        "ProtectSystem": "no", 
        "RefuseManualStart": "no", 
        "RefuseManualStop": "no", 
        "RemainAfterExit": "no", 
        "Requires": "basic.target -.mount", 
        "RequiresMountsFor": "/var/tmp", 
        "Restart": "no", 
        "RestartUSec": "100ms", 
        "Result": "success", 
        "RootDirectoryStartOnly": "no", 
        "RuntimeDirectoryMode": "0755", 
        "SameProcessGroup": "no", 
        "SecureBits": "0", 
        "SendSIGHUP": "no", 
        "SendSIGKILL": "yes", 
        "Slice": "system.slice", 
        "StandardError": "inherit", 
        "StandardInput": "null", 
        "StandardOutput": "journal", 
        "StartLimitAction": "none", 
        "StartLimitBurst": "5", 
        "StartLimitInterval": "10000000", 
        "StartupBlockIOWeight": "18446744073709551615", 
        "StartupCPUShares": "18446744073709551615", 
        "StatusErrno": "0", 
        "StopWhenUnneeded": "no", 
        "SubState": "dead", 
        "SyslogLevelPrefix": "yes", 
        "SyslogPriority": "30", 
        "SystemCallErrorNumber": "0", 
        "TTYReset": "no", 
        "TTYVHangup": "no", 
        "TTYVTDisallocate": "no", 
        "TasksAccounting": "no", 
        "TasksCurrent": "18446744073709551615", 
        "TasksMax": "18446744073709551615", 
        "TimeoutStartUSec": "1min 30s", 
        "TimeoutStopUSec": "1min 30s", 
        "TimerSlackNSec": "50000", 
        "Transient": "no", 
        "Type": "notify", 
        "UMask": "0022", 
        "UnitFilePreset": "disabled", 
        "UnitFileState": "disabled", 
        "Wants": "system.slice", 
        "WatchdogTimestampMonotonic": "0", 
        "WatchdogUSec": "0"
    }
}
複製代碼

參考

my.oschina.net/u/3413282/b… www.cnblogs.com/keerya/p/79…

相關文章
相關標籤/搜索