主頁 >  其他 > 大型企業中如何批量管理千萬臺服務器之ansible自動化運維工具詳解 [?建議收藏?]

大型企業中如何批量管理千萬臺服務器之ansible自動化運維工具詳解 [?建議收藏?]

2021-09-23 13:03:13 其他

文章目錄

  • ansible 自動化運維工具 詳解
    • 關于作者
    • 作者介紹
    • 一、ansible 概述
      • 1.1 ansible 概述
      • 1.2 是什么要使用 ansible
      • 1.3 ansible 功能
      • 1.4 ansible 優點
      • 1.5 ansible作業機制
      • 1.6 ansible 作業原理/流程圖
    • 二、ansible 批量管理服務部署
      • 2.1 實驗環境
      • 2.2 官網安裝教程
        • 2.2.1 ansible 安裝
        • 2.2.2 ansible 命令引數介紹
        • 2.2.3 定義主機清單
        • 2.2.4 基于ssh 免密登錄
        • 2.2.5 管理端 運行命令測驗
    • 三、ansible 批量管理服務 應用
      • 3.1 ansible ping 模塊實戰
        • 3.1.0 ping模塊引數介紹
        • 3.1.1 ansible 實作自己管理自己
        • 3.1.2 ansible 匹配一個網段機器進行管理
      • 3.2 ansible shell 模塊實戰
        • 3.2.0 shell模塊介紹
        • 3.2.1通過ansible 在docker 服務器上創建/查看目錄
        • 3.2.2 通過ansible shell 模塊遠程查看nginx 服務是否啟動
        • 3.2.3 通過ansible shell 模塊遠程查看防火墻狀態
        • 3.2.4 通過ansible 批量修改 用戶密碼
      • 3.3 ansible command 模塊實戰
        • 3.3.0 command 模塊介紹
        • 3.3.1 通過ansible 使用df -h 查看磁盤空間使用資訊
        • 3.3.2 ansible 遠程查看 系統時間
        • 3.3.3 Ansible 遠程執行下載http安裝包
      • 3.4 ansible copy 模塊實戰
        • 3.4.0 copy 模塊介紹
        • 3.4.1 將 ansible 服務器上的 httpd安裝包遠程考到ip為10.0.0.5 服務器上
      • 3.5 ansible yum 模塊實戰
        • 3.5.0 yum 模塊介紹
        • 3.5.1 ansible 服務器上 遠程在 10.0.0.6 服務器上安裝/啟動/卸載 httpd 服務
        • 3.5.2 將www 組服務器中的所有yum 行程都殺掉
      • 3.6 ansible file 模塊實戰(創建、洗掉、修改、權限、屬性的維護和管理)
        • 3.6.0 ansible file 模塊介紹
        • 3.6.1 在 docker 服務器上 /usr/local 目錄下面創建一個rivers的目錄
        • 3.6.2 在docker 服務器上遠程創建一 腳本檔案
      • 3.7 ansible cron 模塊實戰
        • 3.7.0 cron 模塊介紹
        • 3.7.1 利用cron 模塊創建/洗掉計劃任務---時間同步(阿里云)
        • 3.7.2 給定時任務設定注釋資訊
      • 3.8 ansible user 模塊實戰
        • 3.8.0 模塊介紹
        • 3.8.1 給docker 服務器創建一個用戶名稱 dock普通管理用戶
        • 3.8.2 給web 服務器上的apache 服務創建/洗掉一個apache用戶
      • 3.9 Ansible service模塊實戰
        • 3.9.0 service 模塊介紹
        • 3.9.1 遠程重啟web服務器上的防火墻 服務
        • 3.9.2 遠程重啟eht0 網卡(平滑啟動)
        • 3.9.3 遠程設定nfs 開啟自啟動,啟動級別3,5級別
      • 3.10 ansible synchronize 實戰模塊
        • 3.10.0 synchronize 模塊介紹
        • 3.10.1 將源目錄同步至目標目錄(增量同步)
        • 3.10.2 將源目錄同步至目標目錄(完全同步)
    • 四、ansible 批量管理服務
      • 4.1 ansible 劇本 介紹
        • 4.1.0 ansible playbook劇本介紹和基礎使用說明
        • 4.1.1 playbook 常見的組件及作用
        • 4.1.2 遠程主機安裝httpd-2.4.46.tar.bz2 web服務案例演示
      • 4.2 playbook 企業案列實戰
        • 4.2.0 使用 ansible playbook 安裝 nginx WEB服務,安裝完并啟動Nginx 實戰
        • 4.2.1 使用ansible playbook 批量創建系統用戶
    • 五、ansible 綜合應用實戰 ---部署lnmp架構
      • 5.1 實驗環境介紹
      • 5.1.1 使用ansible playbook 搭建一鍵部署lnmp架構
        • 5.1.2 整合 lnmp 架構、進行測驗
    • 六、ansible 調優
      • 6.1 ansible 組態檔詳解
      • 6.2 ansible 常見優化介紹
        • 6.1.1 關閉ssh 密鑰檢測
        • 6.1.2 openssh 連接優化
        • 6.1.3 加速 ansible 優化
  • 總結

ansible 自動化運維工具 詳解

關于作者

  • 作者介紹


    🍊 博客主頁:作者主頁
    🍊 簡介:云計算領域優質創作者🏆、學長的it故事 公眾號創作者🎓、在校期間參與眾多計算機相關的省賽、國賽,斬獲系列榮譽,考取華為資深工程師、紅帽工程師等系列認證,

    🍊 關注我:關注我簡歷模板、學習資料、檔案下載、技術支持
    讓生命像一團熱烈燃燒的火,直到死亡才能使它熄滅


前言

? 最近有老鐵私信給我,讓我出一份ansible的博文,今天小編就和帶著學習新知識的思想,和大家一起復習自動化運維工具,在早起的自動化運維工具中,常見的有puppet、saltstack、ansible 等軟體,目前常用的就是ansible 和saltstack 2款工具,saltstack 與puppet 都是基于 C/S 模式作業的,他們需要安裝服務端與客戶端,基于Python 撰寫,加入MQ訊息同步,可以是執行命令和執行結果高效回傳,但執行程序需要等客戶端回傳,所以如果客戶端沒有及時回傳或回應,就可能導致部分機器沒有執行結果,目前用的較少,

今天就主要分享ansible 自動化運維工具,我將詳細的從概念、到基礎搞高級,層層遞進,讓你輕松掌握ansible自動化運維

當然,每一篇文章都不是100%的全,我能做的就是將我會的,最大限度的分享給你,讓你也可以掌握,

一、ansible 概述

1.1 ansible 概述

  • Ansible是一款自動化運維工具,基于Python開發,集合了眾多運維工具(puppet、cfengine、chef、func、fabric)的優點,實作了批量系統配置、批量程式部署、批量運行命令等功能,

  • Ansible 是一種安裝在控制節點上的無代理自動化工具,Ansible 從控制節點遠程管理機器和其他設備(默認情況下,通過 SSH 協議),Ansible 與Saltstack均是基于Python 語言開發,Ansible只需要在一臺普通的服務器上運行即可,不需要在客戶端服務器上安裝客戶端,因為 Ansible是基于SSH遠程管理,而Linux 服務器大都離不開SSH,所以Ansible不需要為配置作業添加額外的支持,

  • Ansible是基于模塊作業的,本身沒有批量部署的能力,真正具有批量部署的是Ansible所運行的模塊,Ansible只是提供一種框架,主要包括:

    • (1) 連接插件connection plugins:負責和被監控端實作通信;
      (2) host inventory:指定操作的主機,是一個組態檔里面定義監控的主機;
      (3) 各種模塊核心模塊、command模塊、自定義模塊;
      (4) 借助于插件完成記錄日志郵件等功能;
      (5) playbook:劇本執行多個任務時,非必需可以讓節點一次性運行多個任務
  • 架構圖

  • 在這里插入圖片描述

  • ansible 官網

1.2 是什么要使用 ansible

  • 提高作業的效率
  • 提高作業準確度
  • 減少維護的成本
  • 減少重復性作業

1.3 ansible 功能

  • 可以實作批量系統操作配置
  • 可以實作批量軟體服務部署
  • 可以實作批量檔案資料分發
  • 可以實作批量系統資訊收集

1.4 ansible 優點

  • 管理端不需要啟動服務程式(no server)
  • 管理端不需要撰寫組態檔(/etc/ansible/ansible.cfg)
  • 受控端不需要安裝軟體程式(libselinux-python)
  • 受控端不需要啟動服務程式(no agent)
  • 服務程式管理操作模塊眾多(module)
  • 利用劇本撰寫來實作自動化(playbook)
  • 支持sudo 普通用戶

1.5 ansible作業機制

  • 在這里插入圖片描述

    # 由上面的圖可以看到 Ansible 的組成由 5 個部分組成:
    
    #Ansible :    ansible核心
    #Modules :    包括 Ansible 自帶的核心模塊及自定義模塊
    #Plugins :    完成模塊功能的補充,包括連接插件、郵件插件等
    #Playbooks :  劇本;定義 Ansible 多任務組態檔,由Ansible 自動執行
    #Inventory :  定義 Ansible 管理主機的清單  [??nv?ntri] 清單
    
    

1.6 ansible 作業原理/流程圖

  • 在這里插入圖片描述

二、ansible 批量管理服務部署

2.1 實驗環境

  • 實驗環境

    名稱系統ip地址
    ansible_serverCentos 7.610.0.0.61
    Host-01Centos 7.610.0.0.5
    Host-02Centos 7.610.0.0.6
    Host-03Centos 7.610.0.0.7
  • 實驗拓撲

  • 在這里插入圖片描述

2.2 官網安裝教程

2.2.1 ansible 安裝

  • 官網安裝步驟

    # Centso 需要設定EPEL倉庫
    [root@ansible_server~]# yum install epel-release
    
    # 使用yum 安裝ansible 
    [root@ansible_server~]# yum install ansible
    
    # 查看ansible 安裝版本
    [root@ansible_server~]# ansible --version
    ansible 2.9.25
      config file = /etc/ansible/ansible.cfg
      configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
      ansible python module location = /usr/lib/python2.7/site-packages/ansible
      executable location = /usr/bin/ansible
      python version = 2.7.5 (default, Oct 30 2018, 23:45:53) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]
    
    

2.2.2 ansible 命令引數介紹

  • ansible 常見引數

    # ansible 命令引數
    
    # anisble命令語法: ansible [-i 主機檔案] [-f 批次] [組名] [-m 模塊名稱] [-a 模塊引數]
    ansible詳細引數:
     -v,-verbose            # 詳細模式,如果命令執行成功,輸出詳細的結果 (-vv –vvv -vvvv)
     -i PATH, -inventory=PATH  #  指定 host 檔案的路徑,默認是在 /etc/ansible/hosts 
    inventory  [??nv?ntri]  庫存
     -f NUM,-forks=NUM      # NUM 是指定一個整數,默認是 5 ,指定 fork 開啟同步行程的個數,
     -m NAME,-module-name=NAME    #   指定使用的 module 名稱,默認使用 command模塊
     -a,MODULE_ARGS         #指定 module 模塊的引數
     -k,-ask-pass           #提示輸入 ssh 的密碼,而不是使用基于 ssh 的密鑰認證
     -sudo                  # 指定使用 sudo 獲得 root 權限
     -K,-ask-sudo-pass      #提示輸入 sudo 密碼,與 -sudo 一起使用
     -u USERNAME,-user=USERNAME          # 指定移動端的執行用戶
     -C,-check             #測驗此命令執行會改變什么內容,不會真正的去執行
    
    # ansible-doc詳細引數:
    	ansible-doc -l          #列出所有的模塊串列
    	ansible-doc -s 模塊名    #查看指定模塊的引數  -s,   snippet  [?sn?p?t]   片斷
     
     [root@ansible_server~]#  ansible-doc -s service
     
    #列出模塊使用簡介
     [root@ansible_server~]# ansible-doc -l   
     
    # 指定一個模塊詳細說明
     [root@ansible_server~]# ansible-doc -s fetch   
     
     # 查詢模塊在劇本中應用方法
     [root@ansible_server~]# ansible-doc fetch      
    
    
  • Ansible基于多模塊管理,常用的Ansible工具管理模塊包括: commandshellscriptyumcopyFileasyncdockercronmysql_userpingsysctluseracladd_hosteasy_installhaproxy_等,

  • command 不支持管道符,可以使用shell模塊

  • 可以使用ansible-doc -l more查看ansible支持的模塊,也可以查看每個模塊的幫助檔案,ansible-doc module name

  • 在這里插入圖片描述

2.2.3 定義主機清單

  • 定義主機清單

    [root@ansible_server~]# cd /etc/ansible/
    [root@ansible_server/etc/ansible]# ll
    total 24
    -rw-r--r-- 1 root root 19985 Aug 22 04:07 ansible.cfg
    -rw-r--r-- 1 root root  1016 Aug 22 04:07 hosts
    drwxr-xr-x 2 root root     6 Aug 22 04:07 roles
    
    # 操作組態檔前,習慣先備份 
    [root@ansible_server/etc/ansible]# cp -f hosts hosts.backup
    [root@ansible_server/etc/ansible]# ll
    total 28
    -rw-r--r-- 1 root root 19985 Aug 22 04:07 ansible.cfg
    -rw-r--r-- 1 root root  1016 Aug 22 04:07 hosts
    -rw-r--r-- 1 root root  1016 Sep 14 15:34 hosts.backup
    drwxr-xr-x 2 root root     6 Aug 22 04:07 roles
    
    # 情況hosts 組態檔內容,寫hosts檔案
    [root@ansible_server/etc/ansible]# cat /dev/null > hosts
    [root@ansible_server/etc/ansible]# cat hosts
    
    # 寫入主機IP ,這些寫了[webserver]、[docker] 等都是分組,可以不寫(這樣不方便管理)
    [root@ansible_server/etc/ansible]# cat hosts
    [webserver]
    10.0.0.5
    10.0.0.6
    
    # 管理10.0.0.7 docker服務器
    [docker]
    10.0.0.7
    
    # 本機也可以管理自己管自己
    [manager]
    10.0.0.61
    [root@ansible_server/etc/ansible]# 
    

2.2.4 基于ssh 免密登錄

  • ssh 免密登錄

    # 第一個歷程: 創建秘鑰對(管理端服務器)	
    	sh-keygen -t 秘鑰的型別(dsa|rsa)
    #第二個歷程: 將公鑰進行分發(被管理端服務器)
        ssh-copy-id -i /root/.ssh/id_dsa.pub root@10.0.0.5
        
    # 本地生成rsa 密鑰對
    [root@ansible_server~]# ssh-keygen 
    Generating public/private rsa key pair.
    Enter file in which to save the key (/root/.ssh/id_rsa):    # 直接回車
    Enter passphrase (empty for no passphrase):                 # 直接回車
    Enter same passphrase again:                                # 直接回車
    Your identification has been saved in /root/.ssh/id_rsa.
    Your public key has been saved in /root/.ssh/id_rsa.pub.
    The key fingerprint is:
    SHA256:HhsjmGY6DJoSREojVpJmSI63vuoXKy6sK2ESh/eQJr0 root@ansible_server
    The key's randomart image is:
    +---[RSA 2048]----+
    |+Bo.             |
    |X+o              |
    |==..             |
    |=.B. o           |
    |o*.+= . S        |
    |+BE=.  o =       |
    |B.= o   o        |
    |+o =             |
    |X=+              |
    +----[SHA256]-----+
    
    # 上傳到被管理端
    [root@web01_server~]# ssh-copy-id root@10.0.0.5
    [root@web01_server~]# ssh-copy-id root@10.0.0.6
    [root@web01_server~]# ssh-copy-id root@10.0.0.7
    
    

2.2.5 管理端 運行命令測驗

  • ping模塊檢查網路連通性

    # 常用引數
     -i    #  指定 host 檔案的路徑,默認是在 /etc/ansible/hosts ,用的時候可以省略
     -m    # 指定使用的ping模塊
    
    [root@ansible_server~]# ansible -i /etc/ansible/hosts 'www' -m ping
    10.0.0.5 | SUCCESS => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        }, 
        "changed": false, 
        "ping": "pong"
    }
    10.0.0.6 | SUCCESS => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        }, 
        "changed": false, 
        "ping": "pong"
    }
    [root@ansible_server~]# 
    
    
  • 在這里插入圖片描述


三、ansible 批量管理服務 應用

3.1 ansible ping 模塊實戰

3.1.0 ping模塊引數介紹

  • 模塊介紹

    Ansible最基礎的模塊為ping模塊,主要用于判斷遠程客戶端是否在線,用于ping本身服務器,回傳值為changed、ping,
    

3.1.1 ansible 實作自己管理自己

  • 自己管理自己

    # ansible基于ssh連接-i (inventory)引數后指定的遠程主機時,也可以寫埠,用戶,密碼,
    格式:ansible_ssh_port:指定ssh埠   ansible_ssh_user:指定 ssh 用戶 ansible_ssh_pass:指定 ssh 用戶登錄是認證密碼(明文密碼不安全)  ansible_sudo_pass:指明 sudo 時候的密碼
    
    [root@ansible_server~]# cat /etc/ansible/hosts
    [www]
    10.0.0.5
    10.0.0.6
    
    [docker]
    10.0.0.7
    
    [manager]
    10.0.0.61  ansible_ssh_port=22  ansible_ssh_user=root  ansible_ssh_pass=123456
    [root@ansible_server~]# 
    
    
    # 同時還可以基于SSH 免密登錄,2種方式選一種,
    # 將自己的密鑰拷貝到本地,然后ssh 連接一下即可,
    
    [root@web01_server~]# ssh-copy-id root@10.0.0.61
    

3.1.2 ansible 匹配一個網段機器進行管理

  • ping 網段的連通性

    # ping 某一個網段
    [root@ansible_server~]# ansible 10.0.0.* -m ping
    
    # 路徑是可以省略的  -i ,因為默認路徑就是 /etc/ansible/hosts
    [root@ansible_server~]# ansible -i /etc/ansible/hosts "docker" -m ping
    10.0.0.7 | SUCCESS => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        }, 
        "changed": false, 
        "ping": "pong"
    }
    [root@ansible_server~]# 
    
    
  • 在這里插入圖片描述

3.2 ansible shell 模塊實戰

3.2.0 shell模塊介紹

  • 模塊介紹

    # Ansible shell模塊主要用于遠程客戶端上執行各種Shell命令或者運行腳本,遠程執行命令通過/bin/sh環境來執行,支持比command更多的指令,Shell模塊使用詳解:
    
    # 常用引數
    chdir					執行命令前,切換到目錄;
    creates					當該檔案存在時,則不執行該步驟;
    executable				換用shell環境執行命令;
    free_form				需要執行的腳本;
    removes					當該檔案不存在時,則不執行該步驟;
    warn					如果在ansible.cfg中存在告警,如果設定了False,不會警告此行,
    
    

3.2.1通過ansible 在docker 服務器上創建/查看目錄

  • 創建/查看目錄

    # 在docker服務器上 ,在/opt 目錄下創建一個名字為rivers+當前時間的目錄
    [root@ansible_server~]# ansible docker -m shell -a "mkdir /opt/rivers`date +%F`;ls /opt"
    [WARNING]: Consider using the file module with state=directory rather than
    running 'mkdir'.  If you need to use command because file is insufficient you
    can add 'warn: false' to this command task or set 'command_warnings=False' in
    ansible.cfg to get rid of this message.
    10.0.0.7 | CHANGED | rc=0 >>
    rivers2021-09-16
    
    
    # 通過ls 查看是否創建
    [root@ansible_server~]# ansible docker -m shell -a "ls /opt"
    10.0.0.7 | CHANGED | rc=0 >>
    rivers2021-09-16
    [root@ansible_server~]# 
    
  • 在這里插入圖片描述

3.2.2 通過ansible shell 模塊遠程查看nginx 服務是否啟動

  • 遠程查看nginx 服務狀態

    # 遠程查看docker服務器上nginx 行程資訊
    [root@ansible_server~]# ansible docker -m shell -a "ps -ef|grep nginx"
    10.0.0.7 | CHANGED | rc=0 >>
    root      11711      1  0 15:25 ?        00:00:00 nginx: master process nginx
    nginx     11712  11711  0 15:25 ?        00:00:00 nginx: worker process
    root      11775  11770  3 15:26 pts/0    00:00:00 /bin/sh -c ps -ef|grep nginx
    root      11777  11775  0 15:26 pts/0    00:00:00 grep nginx
    [root@ansible_server~]# 
    
    
  • 在這里插入圖片描述

3.2.3 通過ansible shell 模塊遠程查看防火墻狀態

  • 遠程查看docker 服務器上的防火墻狀態

    # ansible 服務器上遠程查看 dockerf 服務器行的防火墻狀態是否運行
    
    [root@ansible_server~]# ansible docker -m shell -a "firewall-cmd --state"
    10.0.0.7 | CHANGED | rc=0 >>
    running
    [root@ansible_server~]# 
    
    
  • 在這里插入圖片描述

3.2.4 通過ansible 批量修改 用戶密碼

  • 批量修改用戶密碼

    # 通通過shell 遠程批量修改密碼
    [root@ansible_server~]# ansible www -m shell -a "echo 123456|passwd --stdin root"
    10.0.0.5 | CHANGED | rc=0 >>
    Changing password for user root.
    passwd: all authentication tokens updated successfully.
    10.0.0.6 | CHANGED | rc=0 >>
    Changing password for user root.
    passwd: all authentication tokens updated successfully.
    
  • 在這里插入圖片描述

3.3 ansible command 模塊實戰

3.3.0 command 模塊介紹

  • command 模塊介紹

    # Ansible command模塊為ansible默認模塊,主要用于執行Linux基礎命令,可以執行遠程服務器命令執行、任務執行等操作,Command模塊使用詳解:
    
    Chdir					執行命令前,切換到目錄;
    Creates					當該檔案存在時,則不執行該步驟;
    Executable				換用shell環境執行命令;
    Free_form				需要執行的腳本;
    Removes					當該檔案不存在時,則不執行該步驟;
    Warn					如果在ansible.cfg中存在告警,如果設定了False,不會警告此行,
    
    

3.3.1 通過ansible 使用df -h 查看磁盤空間使用資訊

  • 查看磁盤空間

    # 使用df -h 查看 docker組中機器的磁盤使用情況
    [root@ansible_server~]# ansible -i /etc/ansible/hosts 10.0.0.7 -m command -a "df -h"
    10.0.0.7 | CHANGED | rc=0 >>
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/sda3        99G  1.7G   97G   2% /
    devtmpfs        442M     0  442M   0% /dev
    tmpfs           453M     0  453M   0% /dev/shm
    tmpfs           453M  7.2M  446M   2% /run
    tmpfs           453M     0  453M   0% /sys/fs/cgroup
    /dev/sda1       197M  105M   93M  54% /boot
    tmpfs            91M     0   91M   0% /run/user/0
    [root@ansible_server~]# 
    
    # 簡便方式寫(效果一樣的)
    [root@ansible_server~]# ansible docker -m command -a "df -h"
    
    
    # 能否使用shell 查看呢 ?
    [root@ansible_server~]# ansible docker -m shell -a "df -h"
    
    # 答案:可以查看,shell 本質上和command 區別不大,知識支持的命令更多
    
  • 在這里插入圖片描述

3.3.2 ansible 遠程查看 系統時間

  • 使用date 命令查看時間

    # 查看docker 服務器上的時間
    [root@ansible_server~]# ansible docker -m command -a "date %F"
    10.0.0.7 | FAILED | rc=1 >>
    date: invalid date ‘%F’non-zero return code
    [root@ansible_server~]# 
    
    
  • 在這里插入圖片描述

3.3.3 Ansible 遠程執行下載http安裝包

  • 遠程下載

    # 先遠程查看docker服務器上有沒有httpd安裝包
    [root@ansible_server~]# ansible docker -m command -a "ls"
    10.0.0.7 | CHANGED | rc=0 >>
    anaconda-ks.cfg
    
    
    # 在docker 服務器上遠程下載httpd-2.4.46.tar.bz2
    [root@ansible_server~]# ansible docker -m command -a "wget https://downloads.apache.org/httpd/httpd-2.4.46.tar.bz2"
    
    
  • 在這里插入圖片描述

3.4 ansible copy 模塊實戰

3.4.0 copy 模塊介紹

  • 模塊介紹

    # Ansible copy模塊主要用于檔案或者目錄拷貝,支持檔案、目錄、權限、用戶組功能,copy模塊使用詳解:
    
    # 常用引數
    src		 	 	Ansible端源檔案或者目錄,空檔案夾不拷貝;
    content		 	用來替代src,用于將指定檔案的內容,拷貝到遠程檔案內;
    dest			    客戶端目標目錄或者檔案,需要絕對路徑;
    backup			# 拷貝之前,先備份遠程節點上的原始檔案;backup=yes
    directory_mode	用于拷貝檔案夾,新建的檔案會被拷貝,而老舊的不會被拷貝;
    follow			支持link檔案拷貝;
    force			覆寫遠程主機不一致的內容;
    group		 	設定遠程主機檔案夾的組名;
    mode		 	指定遠程主機檔案及檔案及的權限;
    owner		 	設定遠程主機檔案夾的用戶名,擁有者,
    
    

3.4.1 將 ansible 服務器上的 httpd安裝包遠程考到ip為10.0.0.5 服務器上

  • 遠程拷貝

    #將ansible 服務器上的http 安裝包遠程 拷貝到 10.0.0.5 服務器上,且權限設定為 755
    [root@ansible_server~]# ansible -i /etc/ansible/hosts 10.0.0.5 -m command -a "ls"
    10.0.0.5 | CHANGED | rc=0 >>
    anaconda-ks.cfg
    [root@ansible_server~]# ansible -i /etc/ansible/hosts 10.0.0.5 -m copy -a "src=/root/httpd-2.4.46.tar.bz2 dest=/root mode=755"
    10.0.0.5 | CHANGED => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        }, 
        "changed": true, 
        "checksum": "1b7cd10ff3a2a07a576d77e34f0204d95fa4aceb", 
        "dest": "/root/httpd-2.4.46.tar.bz2", 
        "gid": 0, 
        "group": "root", 
        "md5sum": "7d661ea5e736dac5e2761d9f49fe8361", 
        "mode": "0755", 
        "owner": "root", 
        "size": 7187805, 
        "src": "/root/.ansible/tmp/ansible-tmp-1631779035.15-12735-92572188724853/source", 
        "state": "file", 
        "uid": 0
    }
    [root@ansible_server~]# 
    
    # 查看10.0.0.5 檔案是否拷貝成功
    [root@ansible_server~]# ansible -i /etc/ansible/hosts 10.0.0.5 -m command -a "ls"
    10.0.0.5 | CHANGED | rc=0 >>
    anaconda-ks.cfg
    httpd-2.4.46.tar.bz2
    [root@ansible_server~]# 
    
    # 查看同一個www組中的 10.0.0.6 是否也有
    [root@ansible_server~]# ansible -i /etc/ansible/hosts 10.0.0.6 -m command -a "ls"
    10.0.0.6 | CHANGED | rc=0 >>
    anaconda-ks.cfg
    [root@ansible_server~]#
    

3.5 ansible yum 模塊實戰

3.5.0 yum 模塊介紹

  • yum 模塊介紹

    #Ansible yum 模塊主要用于軟體的安裝、升級、卸載,支持紅帽.rpm軟體的管理,YUM模塊使用詳解:
    # 常用引數
    conf_file					    設定遠程yum執行時所依賴的yum組態檔
    disable_gpg_check			    安裝軟體包之前是否堅持gpg  key;
    name						    需要安裝的軟體名稱,支持軟體組安裝;
    update_cache				    安裝軟體前更新快取;
    enablerepo					    指定repo源名稱;
    skip_broken      			    跳過例外軟體節點;
    state						    #軟體包狀態,包括:installed、present、latest、absent、removed,
    
    

3.5.1 ansible 服務器上 遠程在 10.0.0.6 服務器上安裝/啟動/卸載 httpd 服務

  • 遠程安裝/卸載

    # 遠程在 10.0.0.6 服務器上安裝 httpd 服務
    [root@ansible_server~]# ansible -i /etc/ansible/hosts 10.0.0.6 -m yum -a "name=httpd state=installed"
    
    # 遠程啟動 httpd 服務
    [root@ansible_server~]# ansible -i /etc/ansible/hosts 10.0.0.6 -m command -a "systemctl start httpd"
    10.0.0.6 | CHANGED | rc=0 >>
    
    
    # 遠程查看http服務行程
    [root@ansible_server~]# ansible -i /etc/ansible/hosts 10.0.0.6 -m shell -a "ps -ef|grep httpd"
    10.0.0.6 | CHANGED | rc=0 >>
    root      10924      1  0 16:11 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
    apache    10925  10924  0 16:11 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
    apache    10926  10924  0 16:11 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
    apache    10928  10924  0 16:11 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
    apache    10929  10924  0 16:11 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
    apache    10930  10924  0 16:11 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
    root      11066  11061  0 16:12 pts/0    00:00:00 /bin/sh -c ps -ef|grep httpd
    root      11068  11066  0 16:12 pts/0    00:00:00 grep httpd
    
    
    # 停止 httpd 服務
    [root@ansible_server~]# ansible -i /etc/ansible/hosts 10.0.0.6 -m command -a "systemctl stop httpd"
    10.0.0.6 | CHANGED | rc=0 >>
    
    # 遠程卸載 httpd
    [root@ansible_server~]# ansible -i /etc/ansible/hosts 10.0.0.6 -m yum -a "name=httpd state=removed"
    
    
  • 在這里插入圖片描述

3.5.2 將www 組服務器中的所有yum 行程都殺掉

  • 停止yum 行程

    # 停止正在作業的yum行程
    [root@ansible_server~]# ansible www -m shell -a "pkill -yum"
    
    # 查看行程
    [root@ansible_server~]# ansible www -m shell -a "ps -ef|grep yum"
    10.0.0.6 | CHANGED | rc=0 >>
    root      12032  12027  0 09:12 pts/1    00:00:00 /bin/sh -c ps -ef|grep yum
    root      12034  12032  0 09:12 pts/1    00:00:00 grep yum
    10.0.0.5 | CHANGED | rc=0 >>
    root      12260  12255  0 09:12 pts/0    00:00:00 /bin/sh -c ps -ef|grep yum
    root      12262  12260  0 09:12 pts/0    00:00:00 grep yum
    [root@ansible_server~]# 
    
    

3.6 ansible file 模塊實戰(創建、洗掉、修改、權限、屬性的維護和管理)

3.6.0 ansible file 模塊介紹

  • file 模塊介紹

    # Ansible file模塊主要用于對檔案的創建、洗掉、修改、權限、屬性的維護和管理,File模塊使用詳解:
    
    # 常用引數介紹
    src					   Ansible端源檔案或者目錄;
    follow				   支持link檔案拷貝;
    force				   覆寫遠程主機不一致的內容;
    group				   設定遠程主機檔案夾的組名;
    mode				   指定遠程主機檔案及檔案及的權限;
    owner				   設定遠程主機檔案夾的用戶名;
    path				   目標路徑,也可以用dest,name代替;
    state				  #狀態包括:file、link、directory、hard、touch、absent;
    attributes			   檔案或者目錄特殊屬性,
    

3.6.1 在 docker 服務器上 /usr/local 目錄下面創建一個rivers的目錄

  • 使用file模塊創建目錄

    # 在 docker 服務器上 /usr/local 目錄下面創建一個rivers的目錄,名字為 rivers,屬主為nginx
    [root@ansible_server~]# ansible docker -m file -a "path=/usr/local/rivers state=directory mode=644 owner=nginx"
    10.0.0.7 | CHANGED => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        }, 
        "changed": true, 
        "gid": 0, 
        "group": "root", 
        "mode": "0644", 
        "owner": "nginx", 
        "path": "/usr/local/rivers", 
        "size": 6, 
        "state": "directory", 
        "uid": 998
    }
    
    # 查看常見的目錄
    [root@ansible_server~]# ansible docker -m command -a "ls /usr/local/rivers"
    10.0.0.7 | FAILED | rc=2 >>
    
    # path表示目錄的名稱和路徑, state=directory表示創建目錄
    
  • 在這里插入圖片描述

3.6.2 在docker 服務器上遠程創建一 腳本檔案

  • 遠程創建檔案

    #在/usr/local/rivers/script.sh檔案
    [root@ansible_server~]# ansible docker -m file -a "path=/usr/local/rivers/script.sh state=touch mode=777"
    10.0.0.7 | CHANGED => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        }, 
        "changed": true, 
        "dest": "/usr/local/rivers/script.sh", 
        "gid": 0, 
        "group": "root", 
        "mode": "0777", 
        "owner": "root", 
        "size": 0, 
        "state": "file", 
        "uid": 0
    }
    [root@ansible_server~]#
    
    # path表示目錄的名稱和路徑, state=touch 表示創建檔案
    
  • 在這里插入圖片描述

3.7 ansible cron 模塊實戰

3.7.0 cron 模塊介紹

  • cron 模塊介紹

    # Ansible cron模塊主要用于添加、洗掉、更新作業系統Crontab任務計劃,Cron模塊使用詳解:
    
    # 常用引數
    name      					任務計劃名稱;
    cron_file 					替換客戶端該用戶的任務計劃的檔案;
    minute    					分( 0-59 ,* ,*/2 );
    hour      					時( 0-23 ,* ,*/2 );
    day       					日( 1-31 ,* ,*/2 );
    month     					月( 1-12 ,* ,*/2 );
    weekday   					周( 0-6 或 1-7 ,* );
    job       					任何計劃執行的命令,state要等于present;
    backup    					是否備份之前的任務計劃;
    user      					新建任務計劃的用戶;
    state     					指定任務計劃present、absent,
    
    

3.7.1 利用cron 模塊創建/洗掉計劃任務—時間同步(阿里云)

  • 基本同步用法

    # docker 服務器 自動同步 阿里云
    [root@ansible_server~]# ansible 10.0.0.7 -m cron -a "minute=0 hour=2 job='/usr/sbin/ntpdate ntp1.aliyun.com >/dev/null 2>&1'" 
    [DEPRECATION WARNING]: The 'name' parameter will be required in future releases.. This 
    feature will be removed in version 2.12. Deprecation warnings can be disabled by setting
     deprecation_warnings=False in ansible.cfg.
    10.0.0.7 | CHANGED => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        }, 
        "changed": true, 
        "envs": [], 
        "jobs": [
            "None"
        ]
    }
    
    # 如何洗掉定時任務
    
    [root@ansible_server~]# ansible docker -m cron -a "name='#Ansible' state=absent"
    
    
    

3.7.2 給定時任務設定注釋資訊

  • 添加定時任務 名稱注釋

    # 添加注釋資訊
    [root@ansible_server~]# ansible 10.0.0.6 -m cron -a "name='time sync' minute=0 hour=2 job='/usr/sbin/ntpdate ntp1.aliyun.com >/dev/null 2>&1'"
    10.0.0.6 | CHANGED => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        }, 
        "changed": true, 
        "envs": [], 
        "jobs": [
            "time sync"
        ]
    }
    
    #如何查看10.0.0.6這臺服務器上的定時任務
    [root@ansible_server~]# ansible 10.0.0.6 -m shell -a "cat /var/spool/cron/root"
    10.0.0.6 | CHANGED | rc=0 >>
    #time sync by lidao at 2017-03-08
    */5 * * * * /usr/sbin/ntpdate ntp.aliyun.com >/dev/null 2>&1
    #Ansible: time sync
    0 2 * * * /usr/sbin/ntpdate ntp1.aliyun.com >/dev/null 2>&1
    

3.8 ansible user 模塊實戰

3.8.0 模塊介紹

  • user 模塊介紹

    # Ansible user模塊主要用于作業系統用戶、組、權限、密碼等操作,user模塊使用詳解:
    system          				    默認創建為普通用戶,為yes則創建系統用戶;
    append							    添加一個新的組;
    comment 						    新增描述資訊;
    createhome 						    給用戶創建家目錄;
    force							    用于洗掉強制洗掉用戶;
    group							    創建用戶主組;
    groups							    將用戶加入組或者附屬組添加;
    home							    指定用戶的家目錄;
    name							    表示狀態,是否create、remove、modify;
    password						    指定用戶的密碼,此處為加密密碼;
    remove							    洗掉用戶;
    shell							    設定用戶的shell登錄環境;
    uid								    設定用戶id;
    update_password 				    修改用戶密碼;
    state           				    用戶狀態,默認為present表示新建用戶,absent表示洗掉
    
    

3.8.1 給docker 服務器創建一個用戶名稱 dock普通管理用戶

  • 創建普通用戶

    # 在docker 服務器上創建一個普通用戶 nidaye,name=用戶名,home=用戶家目錄
    [root@ansible_server~]# ansible docker -m user -a "name=nidaye home=/home/admin"
    10.0.0.7 | CHANGED => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        }, 
        "changed": true, 
        "comment": "", 
        "create_home": true, 
        "group": 1001, 
        "home": "/home/admin", 
        "name": "nidaye", 
        "shell": "/bin/bash", 
        "state": "present", 
        "system": false, 
        "uid": 1001
    }
    
    # 查看剛新建的用戶 nidaye
    [root@ansible_server~]# ansible docker -m shell -a "id nidaye"
    10.0.0.7 | CHANGED | rc=0 >>
    uid=1001(nidaye) gid=1001(nidaye) groups=1001(nidaye)
    [root@ansible_server~]# 
    
  • 在這里插入圖片描述

3.8.2 給web 服務器上的apache 服務創建/洗掉一個apache用戶

  • 創建apache用戶

    # 在10.0.0.5 服務器上 創建一個 名字apache ,shell /sbin/nologin 家目錄為/opt
    [root@ansible_server~]# ansible 10.0.0.5 -m user -a "name=apache home=/opt shell=/sbin/nologin"
    10.0.0.5 | CHANGED => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        }, 
        "changed": true, 
        "comment": "", 
        "create_home": true, 
        "group": 1001, 
        "home": "/opt", 
        "name": "apache", 
        "shell": "/sbin/nologin", 
        "state": "present", 
        
    # 洗掉apache用戶
    [root@ansible_server~]# ansible 10.0.0.5 -m user -a "name=apache state=absent force=yes"
    10.0.0.5 | CHANGED => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        }, 
        "changed": true, 
        "force": true, 
        "name": "apache", 
        "remove": false, 
        "state": "absent"
    }
    [root@ansible_server~]# 
    
    
    
  • 在這里插入圖片描述

  • 在這里插入圖片描述

3.9 Ansible service模塊實戰

3.9.0 service 模塊介紹

  • service 模塊介紹

    # Ansible service模塊主要用于遠程客戶端各種服務管理,包括啟動、停止、重啟、重新加載等,service模塊使用詳解:
    
    # 常用引數
    enabled				是否開啟啟動服務;
    name				服務名稱;
    runlevel			    服務啟動級別;
    arguments			服務命令列引數傳遞;
    state				    服務操作狀態,狀態包括started, stopped, restarted, reloaded,
    
    

3.9.1 遠程重啟web服務器上的防火墻 服務

  • 遠程重啟/關閉firewalld服務

    # 遠程重啟10.0.0.5 服務器上的 firewalld 服務器
    [root@ansible_server~]# ansible 10.0.0.5  -m service -a "name=firewalld state=restarted"
    10.0.0.5 | CHANGED => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        }, 
        "changed": true, 
        "name": "firewalld", 
        "state": "started", 
        "status": {
            "ActiveEnterTimestampMonotonic": "0", 
            "ActiveExitTimestampMonotonic": "0", 
            "ActiveState": "inactive", 
          ……
    [root@ansible_server~]# 
    # 遠程關閉防火墻
    [root@ansible_server~]# ansible 10.0.0.5  -m service -a "name=firewalld state=stopped"
    
    
    

3.9.2 遠程重啟eht0 網卡(平滑啟動)

  • 平滑啟動 10.0.0.5 服務器上的網卡

    # 遠程啟動 eht0 網卡
    [root@ansible_server~]# ansible 10.0.0.5 -m service -a "name=network args=eth0 state=restarted"
    [WARNING]: Ignoring "args" as it is not used in "systemd"
    10.0.0.5 | CHANGED => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        }, 
        "changed": true, 
        "name": "network", 
        "state": "started", 
        "status": {
            "ActiveEnterTimestamp": "Fri 2021-08-27 16:30:41 CST", 
            ……
    
    

3.9.3 遠程設定nfs 開啟自啟動,啟動級別3,5級別

  • 遠程設定開機自啟動

    # 遠程開機啟動nfs服務,設定3,5級別自動啟動
    root@ansible_server~]# ansible -k all -m service  -a  "name=nfs  enabled=yes  runlevel=3,5"
    SSH password: 
    [WARNING]: Ignoring "runlevel" as it is not used in "systemd"
    [WARNING]: Ignoring "runlevel" as it is not used in "systemd"
    [WARNING]: Ignoring "runlevel" as it is not used in "systemd"
    

3.10 ansible synchronize 實戰模塊

3.10.0 synchronize 模塊介紹

  • 模塊介紹

    # Ansible synchronize模塊主要用于目錄、檔案同步,基于Rsync命令同步目錄,Synchronize模塊使用詳解:
    
    # 常用引數
    compress        			    開啟壓縮,默認為開啟;
    archive         				是否采用歸檔模式同步,保證源和目標檔案屬性一致;
    checksum        			    是否效驗;
    dirs            				以非遞回的方式傳輸目錄;
    links           				同步鏈接檔案;
    recursive       				是否遞回yes/no;
    rsync_opts      				使用rsync 的引數;
    copy_links      				同步的時候是否復制連接;
    delete          				洗掉源中沒有而目標存在的檔案;
    src                          源目錄及檔案;
    dest	        				目標目錄及檔案;
    dest_port       				目標接受的埠;
    rsync_path      				服務的路徑,指定 rsync 命令來在遠程服務器上運行;
    rsync_timeout   				指定rsync操作的IP超時時間;
    set_remote_user 			    設定遠程用戶名;
    --exclude=.log  				忽略同步.log結尾的檔案;
    mode            			同步的模式,rsync同步的方式PUSH、PULL,默認都是推送push,
    
    

3.10.1 將源目錄同步至目標目錄(增量同步)

  • 將源目錄同步至目標目錄(增量同步)

    # 將本地/tmp 目錄遠程同步到 docker服務器上(增量同步)
    [root@ansible_server~]# ansible docker -m synchronize  -a 'src=/tmp/ dest=/tmp/'
    10.0.0.7 | CHANGED => {
        "changed": true, 
        "cmd": "/usr/bin/rsync --delay-updates -F --compress --archive --rsh=/usr/bin/ssh -S none -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null --out-format=<<CHANGED>>%i %n%L /tmp/ 10.0.0.7:/tmp/", 
        "msg": ".d..t...... ./\n<f+++++++++ xxx.xx\ncd+++++++++ ansible_synchronize_payload_Bxuy_S/\n<f+++++++++ ansible_synchronize_payload_Bxuy_S/ansible_synchronize_payload.zip\ncd+++++++++ vmware-root_6044-692160431/\n", 
        "rc": 0, 
        "stdout_lines": [
            ".d..t...... ./", 
            "<f+++++++++ xxx.xx", 
            "cd+++++++++ ansible_synchronize_payload_Bxuy_S/", 
            "<f+++++++++ ansible_synchronize_payload_Bxuy_S/ansible_synchronize_payload.zip", 
            "cd+++++++++ vmware-root_6044-692160431/"
        ]
    }
    [root@ansible_server~]# 
    
    
  • 在這里插入圖片描述

3.10.2 將源目錄同步至目標目錄(完全同步)

  • 將源目錄同步至目標目錄(增量同步)

    # 完全同步,尾巴后添加 delete=yes
    [root@ansible_server/tmp]# ansible docker -m synchronize  -a 'src=/tmp/ dest=/tmp/ delete=yes'
    
    

四、ansible 批量管理服務

4.1 ansible 劇本 介紹

4.1.0 ansible playbook劇本介紹和基礎使用說明

  • 劇本介紹

    # 通過Playbook任務,能夠集中管理多個任務,將多個任務關聯起來,從而實作更加復雜作業,滿足生產環境的各個需求,提高運維人員管理服務器效率
    
    # Playbook劇本的產物YAML檔案,類似XML介面(Tomcat)檔案,內部有固定語法、引數等,要掌握常用的YAML語法撰寫,掌握滿足運維管理方向的語法即可
    
  • playbook 語法

    # yaml 格式語法
    
    # Playbook是以YAML格式撰寫的文本檔案,通常使用擴展名yml保存,Playbook使用空格字符縮進來表示其資料結構,YAML對用于縮進的空格數量沒有嚴格的要求,但有兩個基本的規則:
    
    	處于層次結構中同一級別的資料元素(例如同一串列中的專案)必須具有相同的縮進量,
    	如果專案屬于其他專案的子項,其縮進量必須大于父項
    # 只有空格字符可用于縮進,不允許使用tab鍵,約定俗成的縮進量一般是一級2個空格,
    # Playbook開頭的一行由三個破折號(---)組成,這是檔案開始標記,其末尾可能使用三個圓點(...)作為檔案結束標記,盡管在實踐中這通常會省略,
    
  • playbook 運行/語法檢查

    # 運行 lnmp檔案
    [root@ansible_server~]# ansible-playbook lnmp.yml
    
    # 檢查lnmp 語法
    [root@ansible_server~]# ansible-playbook --syntax-check lnmp.yml
    
    
    
    playbook是一個不同于使用ansible命令列執行方式的模式,功能更強大更靈活,
    1、在playbooks 中常見的定義任務:
    	name: task description     #任務描述資訊
    	module_name: module_args    #需要使用的模塊名字:  模塊引數
        files:存放需要同步到異地服務器的原始碼檔案及組態檔; 
    	handlers:當服務的組態檔發生變化時需要進行的操作,比如:重啟服務,重新加載組態檔,		 	 handlers 
    	meta:角色定義,可留空; 
    	tasks:需要進行的執行的任務; 
    	templates:用于執行lamp安裝的模板檔案,一般為腳本
    	vars:本次安裝定義的變數
    
    
    #playbook是由一個或多個"play"組成的串列,play的主要功能在于將事先歸為一組的主機裝扮成事先通過ansible中的task定義好的角色,
    #github上提供了大量的實體供大家參考  https://github.com/ansible/ansible-examples
    
    

4.1.1 playbook 常見的組件及作用

  • playbook 組件

    • Target 定義playbook的遠程主機組;

      • 常用引數:

        • hosts 定義遠程主機組;

        • user 執行該任務的用戶;

        • sudo 設定為yes的時候,執行任務的時候使用root權限;

        • sudo_user 指定sudo普通用戶;

        • connection 默認基于SSH連接客戶端;

        • gather_facks 獲取遠程主機facts基礎資訊,

    • Variable 定義playbook使用的變數;

      • 常用引數:
        • vars 定義格式,變數名:變數值;
        • vars_files 指定變數檔案;
        • vars_prompt 用戶互動模式自定義變數;
        • setup 模塊去遠程主機的值;
    • Task 定義遠程主機上執行的任務串列;

      • 常用引數:
        • name 任務顯示名稱也即螢屏顯示資訊;
        • action 定義執行的動作;
        • copy 復制本地檔案到遠程主機;
        • template 復制本地檔案到遠程主機,可以參考本地變數;
        • service 定義服務的狀態,
    • Handler 當服務的組態檔發生變化時需要進行的操作,比如:重啟服務,重新加載配置

4.1.2 遠程主機安裝httpd-2.4.46.tar.bz2 web服務案例演示

  • 遠程安裝演示

    # 通過ansible 給www組服務器里面的 10.0.0.5 這臺服務器安裝httpd-2.4.46.tar.bz2服務
    [root@ansible_server~]# cat httpd_install.yaml 
    #author rivers
    ---
    - hosts: 10.0.0.5
      remote_user: root
    
      tasks:
        - name: install httpd-2.4.tar.bz2
          yum: name=apr,apr-devel,apr-util,apr-util-devel,gcc-c++,bzip2  state=installed
      - name: apache httpd-2.4 install process
          shell: cd /opt/; rm -rf httpd-2.4.46.tar.bz2; wget https://downloads.apache.org/httpd/httpd-2.4.46.tar.bz2; tar xjf httpd-2.4.46.tar.bz2 -C /usr/local/; cd /usr/local/httpd-2.4.46/; ./configure --prefix=/usr/local/apache  --with-pmp=worker; make -j4; make install;
    ...
    
    
    
  • 在這里插入圖片描述

  • 檢查 httpd_install.yaml 語法檔案

    # 檢查 httpd_install.yaml 語法,下面是正確通過的
    [root@ansible_server~]# ansible-playbook --syntax-check httpd_install.yaml 
    
    playbook: httpd_install.yaml
    
    
    # 常見報錯提示
    [root@ansible_server~]# ansible-playbook --syntax-check httpd_install.yaml 
    ERROR! We were unable to read either as JSON nor YAML, these are the errors we got from each:
    JSON: No JSON object could be decoded
      
    Syntax Error while loading YAML.
      mapping values are not allowed in this context
    
    The error appears to be in '/root/httpd_install.yaml': line 8, column 10, but may
    be elsewhere in the file depending on the exact syntax problem.
    
    The offending line appears to be:
    
        -name: install httpd-2.4.tar.bz2
          yum: name=apr apr-devel apr-util apr-util-devel gcc-c++ bzip2  state=installed
             ^ here
    
    
  • 在這里插入圖片描述

  • 安裝 成功

  • 在這里插入圖片描述

4.2 playbook 企業案列實戰

4.2.0 使用 ansible playbook 安裝 nginx WEB服務,安裝完并啟動Nginx 實戰

  • playbook劇本

    # 判斷是否安裝有安裝后的nginx目錄,如果有直接啟動,如果沒有安裝nginx
    #author rivershosts: 10.0.0.7
    remote_user: root
    tasks:
    
      - name: install yum_package
        yum: name=pcre-devel,openssl,openssl-devel,gd-devel,gcc,gcc-c++ state=installed
      - name: echo -e "\033[44;37m 判斷是否存在nginx安裝目錄 \033[0m"
        file: path=/usr/local/nginx state=directory
        notify:
          - nginx start
          - nginx install
    
    handlers:
    
      - name: nginx install
        shell: cd /opt/; rm -rf nginx-1.20.1.tar.gz; wget http://nginx.org/download/nginx-1.20.1.tar.gz; tar xf nginx-1.20
          .1.tar.gz -C /usr/local/; useradd -M -s /sbin/nologin nginx; mkdir -p /var/log/nginx;cd /usr/local/nginx-1.20.1; ./confi
          gure --user=nginx --prefix=/usr/local/nginx --with-http_ssl_module --with-http_realip_module --with-http_image_filter_mo
          dule --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --http-log-path=/var/log/ng
          inx/access.log --error-log-path=/var/log/nginx/error.log --without-http_rewrite_module; make && make install; /usr/local
          /nginx/sbin/nginx  -t;
    
      - name: nginx start
        shell: /usr/local/nginx/sbin/nginx
    
    • 在這里插入圖片描述

    4.2.1 使用ansible playbook 批量創建系統用戶

  • 批量創建系統用戶

      # 使用 user 模塊批量創建rivers01、02、03用戶
    # author rivers
    - hosts: 10.0.0.7
      remote_user: root
      tasks:
      - name: Add User list.
        user: name={{ item }} state=present
        with_items:
           - rivers01
           - rivers02
           - rivers03
    
      - name: check system user
        shell: num= `tail -3 /etc/passwd|grep -c rivers`; if [ $num ge 3 ]; then echo is ok!; fi
    
    
    
  • 在這里插入圖片描述

  • 在這里插入圖片描述


五、ansible 綜合應用實戰 —部署lnmp架構

5.1 實驗環境介紹

  • 實驗環境介紹

    名稱系統ip地址部署服務
    ansible_serverCentos 7.610.0.0.61ansible
    Host01Centos 7.610.0.0.5nginx+php
    Host02Centos 7.610.0.0.6mysql

5.1.1 使用ansible playbook 搭建一鍵部署lnmp架構

  • 分布式部署 lnmp 架構

    #撰寫 ansible-playbook lnmp.yaml 劇本
    [root@ansible_server~]# cat lnmp_install.yaml 
    # author 
    # 任務1:安裝nginx
    - hosts: 10.0.0.5
      remote_user: root
      tasks:
        - name: 修改主機名,判斷、安裝/啟動nginx
          shell: hostnamectl set-hostname Hosts-01
        - name: install yum_package
          yum: name=pcre-devel,openssl,openssl-devel,gd-devel,gcc,gcc-c++ state=installed
        - name: echo -e "\033[44;37m 判斷是否存在nginx安裝目錄 \033[0m"
          file: path=/usr/local/nginx state=directory
          notify: 
            - nginx start
            - nginx install
      
      handlers:
        - name: nginx install
          shell: cd /opt/; rm -rf nginx-1.20.1.tar.gz; wget http://nginx.org/download/nginx-1.20.1.tar.gz; tar xf nginx-1.20.1.tar.gz -C /usr/local/; useradd -M -s /sbin/nologin nginx; mkdir -p /var/log/nginx;cd /usr/local/nginx-1.20.1; ./configure --user=nginx --prefix=/usr/local/nginx --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --without-http_rewrite_module; make && make install; /usr/local/nginx/sbin/nginx  -t;
    
        - name: nginx start
          shell: /usr/local/nginx/sbin/nginx
      
    # 任務2 安裝mysql
    - hosts: 10.0.0.6
      remote_user: root
      tasks:
        - name: install yum_package
          yum: name=pcre-devel,openssl,openssl-devel,gd-devel,gcc,gcc-c++,ncurses-devel state=installed
        - name: 下載安裝包、并解壓
          shell: cd /opt/; tar -xf mysql-5.1.63.tar.gz -C /usr/local/
        - name: 開始編譯安裝
          shell: cd /usr/local/mysql-5.1.63/; ./configure --prefix=/usr/local/mysql --enable-assembler; make -j8&&make -j8 install; \cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf; \cp /usr/local/mysql/share/mysql/mysql.server  /etc/rc.d/init.d/mysqld;
        - name: 配置啟動/重啟
          shell: chkconfig --add mysqld;chkconfig --level 35 mysqld on; service  mysqld  restart
    
    
    # 任務3 安裝php
    - hosts: 10.0.0.5
      remote_user: root
    
      tasks:
        - name: install php_package
          yum: name=libxml2,libxml2-devel,openssl,openssl-devel,bzip2,bzip2-devel,libcurl,libcurl-devel,libjpeg,libjpeg-devel,libpng,libpng-devel,freetype,freetype-devel,gmp,gmp-devel,libmcrypt,libmcrypt-devel,readline,readline-devel,libxslt,libxslt-devel,pcre-devel,ncurses,ncurses-devel,bison,cmake state=installed
        - name: 下載安裝包、并解壓
          shell: cd /opt/; wget http://mirrors.sohu.com/php/php-7.2.10.tar.gz; tar xf php-7.2.10.tar.gz -C /usr/local/; cd /usr/local/php-7.2.10/; ./configure --prefix=/usr/local/php --disable-fileinfo --enable-fpm --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-openssl --with-zlib --with-curl --enable-ftp --with-gd --with-xmlrpc --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-gd-native-ttf --enable-mbstring --with-mcrypt=/usr/local/libmcrypt --enable-zip --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-mysql-sock=/var/lib/mysql/mysql.sock --without-pear --enable-bcmath; make && make install; ln -s /usr/local/php/bin/* /usr/local/bin/; \cp php.ini-production /etc/php.ini; \cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf; \cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf; \cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm; chmod +x /etc/init.d/php-fpm; chkconfig --add php-fpm 
       
        - name: 啟動php服務
          shell: systemctl start php-fpm
    
  • 在這里插入圖片描述

5.1.2 整合 lnmp 架構、進行測驗

  • 修改nginx 組態檔

    # 修改 /usr/local/nginx/conf/nginx.conf 檔案 
    
    # 1.將user 改為 nginx
    # 2.添加一下內容
    location / {
    		root   html;
    		index  index.php index.html index.htm;
    }
    
    location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name; 
            include        fastcgi_params;
    }
    
    # 設定php 網站檔案
    vim /usr/local/nginx/html/index.php
    [root@hosts-01/usr/local/nginx/html]# cat index.php 
    <?php
            phpinfo();
    ?>
    [root@hosts-01/usr/local/nginx/html]# 
    
    
    # 重啟nginx 服務
    /usr/local/nginx/sbin/nginx
    
  • 在這里插入圖片描述

  • 在這里插入圖片描述

  • 瀏覽器輸入 10.0.0.5 訪問測驗

  • 在這里插入圖片描述


六、ansible 調優

6.1 ansible 組態檔詳解

  • 組態檔說明

    # Ansible默認組態檔為/etc/ansible/ansible.cfg,組態檔中可以對ansible進行各項引數的調整,包括并發執行緒、用戶、模塊路徑、配置優化等,如下為Ansible.cfg常用引數詳解:
    
    [defaults]   								通用默認配置段;
    inventory      = /etc/ansible/hosts     	    被控端IP或者DNS串列;
    library        = /usr/share/my_modules/ 	    Ansible默認搜尋模塊的位置;
    remote_tmp     = $HOME/.ansible/tmp       Ansible遠程執行臨時檔案;
    pattern        = *    				    對所有主機通信;
    forks          = 5    					并行行程數;
    poll_interval  = 15    					    回頻率或輪訓間隔時間;
    sudo_user      = root   					sudo遠程執行用戶名;
    ask_sudo_pass = True   					使用sudo,是否需要輸入密碼;
    ask_pass      = True    					是否需要輸入密碼;
    transport      = smart   				    通信機制;
    remote_port    = 22    					遠程SSH埠;
    module_lang    = C   					模塊和系統之間通信的語言;
    gathering = implicit   					    控制默認facts收集(遠程系統變數);
    roles_path= /etc/ansible/roles 			    用于playbook搜索Ansible roles;
    host_key_checking = False    				檢查遠程主機密鑰;
    #sudo_exe = sudo     					    sudo遠程執行命令;
    #sudo_flags = -H							傳遞sudo之外的引數;
    timeout = 10								SSH超時時間;
    remote_user = root   					    遠程登陸用戶名;
    log_path = /var/log/ansible.log     		    日志檔案存放路徑;
    module_name = command 				    Ansible命令執行默認的模塊;
    #executable = /bin/sh     				    執行的Shell環境,用戶Shell模塊;
    #hash_behaviour = replace    				特定的優先級覆寫變數;
    #jinja2_extensions	    				    允許開啟Jinja2拓展模塊;
    #private_key_file = /path/to/file       	    私鑰檔案存盤位置;
    #display_skipped_hosts = True     			顯示任何跳過任務的狀態;
    #system_warnings = True    				禁用系統運行ansible潛在問題警告;
    #deprecation_warnings = True 				Playbook輸出禁用“不建議使用”警告;
    #command_warnings = False    			    command模塊Ansible默認發出警告;
    #nocolor = 1  							輸出帶上顏色區別,開啟/關閉:0/1; 
    pipelining = False							開啟pipe SSH通道優化;
    [accelerate]								accelerate快取加速,
    accelerate_port = 5099
    accelerate_timeout = 30
    accelerate_connect_timeout = 5.0
    accelerate_daemon_timeout = 30
    accelerate_multi_key = yes
    
    

6.2 ansible 常見優化介紹

6.1.1 關閉ssh 密鑰檢測

  • 關閉ssh 檢測密鑰

    # 在ansible 組態檔中加入以下代碼:
    host_key_checking = False
    

6.1.2 openssh 連接優化

  • 關閉DNS決議

    # 使用OpenSSH服務時,默認服務器端組態檔UseDNS=YES狀態,該選項會導致服務器根據客戶端的IP地址進行DNS PTR反向決議,得到客戶端的主機名,然后根據獲取到的主機名進行DNS正向A記錄查詢,并驗證該IP是否與原始IP一致,關閉DNS決議
    
    sed  -i  '/^GSSAPI/s/yes/no/g;/UseDNS/d;/Protocol/aUseDNS no' /etc/ssh/sshd_config
    /etc/init.d/sshd restart
    

6.1.3 加速 ansible 優化

  • SSH pipelining加速Ansible

    # SSH pipelining是一個加速 Ansible 執行速度的簡單方法,SSH pipelining 默認是關閉的,關閉是為了兼容不同的 sudo 配置,主要是requiretty 選項,
    如果不使用Sudo建議開啟該選項,打開此選項可以減少Ansible 執行沒有檔案傳輸時,SSH在被控機器上執行任務的連接數,使用Sudo操作的時候, 必須在所有被管理的主機上將組態檔/etc/sudoers中requiretty選項禁用,
    
    
    sed    -i    '/^pipelining/s/False/True/g'    /etc/ansible/ansible.cfg
    

總結

在里小編想說,其實ansible 不難,工具比較簡單,其中的shell 模塊是萬能的模塊,所以,如果其他模塊掌握不好,那就用shell 去實作,小撰寫這篇文章花費了3天左右,通過構思、實踐,完整的走了一遍,如果當你讀到這篇文章后,請認真看完,因為這是運維必備的技能,

日常運維中,還有很多細節需要注意,這里不做過多描述,當然這里介紹的并不是非常全,往后的學習中,還是要多去查看官網的說明檔案,上面介紹的最詳細,最權威,學習是一個漫長的程序,如果你想從事運維行業,能參加一個好點的培訓機構最好,如果經濟有限,不想花錢,也可以自學,買一本好點的書籍,看一套完整的視頻,然后做實驗,反復去練習,同時如果對我的云計算專欄感興趣,也可以訂閱我的專欄,進行學習,

以夢為馬,不負韶華,流年笑擲,未來可期!
????????????????—黃昏

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/302236.html

標籤:其他

上一篇:?? Go 有別于其他語言的九個特性 ??

下一篇:??[資料結構]動圖詳解鏈表(單鏈表/雙鏈表……)(動圖+實體)【建議收藏】!??

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 網閘典型架構簡述

    網閘架構一般分為兩種:三主機的三系統架構網閘和雙主機的2+1架構網閘。 三主機架構分別為內端機、外端機和仲裁機。三機無論從軟體和硬體上均各自獨立。首先從硬體上來看,三機都用各自獨立的主板、記憶體及存盤設備。從軟體上來看,三機有各自獨立的作業系統。這樣能達到完全的三機獨立。對于“2+1”系統,“2”分為 ......

    uj5u.com 2020-09-10 02:00:44 more
  • 如何從xshell上傳檔案到centos linux虛擬機里

    如何從xshell上傳檔案到centos linux虛擬機里及:虛擬機CentOs下執行 yum -y install lrzsz命令,出現錯誤:鏡像無法找到軟體包 前言 一、安裝lrzsz步驟 二、上傳檔案 三、遇到的問題及解決方案 總結 前言 提示:其實很簡單,往虛擬機上安裝一個上傳檔案的工具 ......

    uj5u.com 2020-09-10 02:00:47 more
  • 一、SQLMAP入門

    一、SQLMAP入門 1、判斷是否存在注入 sqlmap.py -u 網址/id=1 id=1不可缺少。當注入點后面的引數大于兩個時。需要加雙引號, sqlmap.py -u "網址/id=1&uid=1" 2、判斷文本中的請求是否存在注入 從文本中加載http請求,SQLMAP可以從一個文本檔案中 ......

    uj5u.com 2020-09-10 02:00:50 more
  • Metasploit 簡單使用教程

    metasploit 簡單使用教程 浩先生, 2020-08-28 16:18:25 分類專欄: kail 網路安全 linux 文章標簽: linux資訊安全 編輯 著作權 metasploit 使用教程 前言 一、Metasploit是什么? 二、準備作業 三、具體步驟 前言 Msfconsole ......

    uj5u.com 2020-09-10 02:00:53 more
  • 游戲逆向之驅動層與用戶層通訊

    驅動層代碼: #pragma once #include <ntifs.h> #define add_code CTL_CODE(FILE_DEVICE_UNKNOWN,0x800,METHOD_BUFFERED,FILE_ANY_ACCESS) /* 更多游戲逆向視頻www.yxfzedu.com ......

    uj5u.com 2020-09-10 02:00:56 more
  • 北斗電力時鐘(北斗授時服務器)讓網路資料更精準

    北斗電力時鐘(北斗授時服務器)讓網路資料更精準 北斗電力時鐘(北斗授時服務器)讓網路資料更精準 京準電子科技官微——ahjzsz 近幾年,資訊技術的得了快速發展,互聯網在逐漸普及,其在人們生活和生產中都得到了廣泛應用,并且取得了不錯的應用效果。計算機網路資訊在電力系統中的應用,一方面使電力系統的運行 ......

    uj5u.com 2020-09-10 02:01:03 more
  • 【CTF】CTFHub 技能樹 彩蛋 writeup

    ?碎碎念 CTFHub:https://www.ctfhub.com/ 筆者入門CTF時時剛開始刷的是bugku的舊平臺,后來才有了CTFHub。 感覺不論是網頁UI設計,還是題目質量,賽事跟蹤,工具軟體都做得很不錯。 而且因為獨到的金幣制度的確讓人有一種想去刷題賺金幣的感覺。 個人還是非常喜歡這個 ......

    uj5u.com 2020-09-10 02:04:05 more
  • 02windows基礎操作

    我學到了一下幾點 Windows系統目錄結構與滲透的作用 常見Windows的服務詳解 Windows埠詳解 常用的Windows注冊表詳解 hacker DOS命令詳解(net user / type /md /rd/ dir /cd /net use copy、批處理 等) 利用dos命令制作 ......

    uj5u.com 2020-09-10 02:04:18 more
  • 03.Linux基礎操作

    我學到了以下幾點 01Linux系統介紹02系統安裝,密碼啊破解03Linux常用命令04LAMP 01LINUX windows: win03 8 12 16 19 配置不繁瑣 Linux:redhat,centos(紅帽社區版),Ubuntu server,suse unix:金融機構,證券,銀 ......

    uj5u.com 2020-09-10 02:04:30 more
  • 05HTML

    01HTML介紹 02頭部標簽講解03基礎標簽講解04表單標簽講解 HTML前段語言 js1.了解代碼2.根據代碼 懂得挖掘漏洞 (POST注入/XSS漏洞上傳)3.黑帽seo 白帽seo 客戶網站被黑帽植入劫持代碼如何處理4.熟悉html表單 <html><head><title>TDK標題,描述 ......

    uj5u.com 2020-09-10 02:04:36 more
最新发布
  • 2023年最新微信小程式抓包教程

    01 開門見山 隔一個月發一篇文章,不過分。 首先回顧一下《微信系結手機號資料庫被脫庫事件》,我也是第一時間得知了這個訊息,然后跟蹤了整件事情的經過。下面是這起事件的相關截圖以及近日流出的一萬條資料樣本: 個人認為這件事也沒什么,還不如關注一下之前45億快遞資料查詢渠道疑似在近日復活的訊息。 訊息是 ......

    uj5u.com 2023-04-20 08:48:24 more
  • web3 產品介紹:metamask 錢包 使用最多的瀏覽器插件錢包

    Metamask錢包是一種基于區塊鏈技術的數字貨幣錢包,它允許用戶在安全、便捷的環境下管理自己的加密資產。Metamask錢包是以太坊生態系統中最流行的錢包之一,它具有易于使用、安全性高和功能強大等優點。 本文將詳細介紹Metamask錢包的功能和使用方法。 一、 Metamask錢包的功能 數字資 ......

    uj5u.com 2023-04-20 08:47:46 more
  • vulnhub_Earth

    前言 靶機地址->>>vulnhub_Earth 攻擊機ip:192.168.20.121 靶機ip:192.168.20.122 參考文章 https://www.cnblogs.com/Jing-X/archive/2022/04/03/16097695.html https://www.cnb ......

    uj5u.com 2023-04-20 07:46:20 more
  • 從4k到42k,軟體測驗工程師的漲薪史,給我看哭了

    清明節一過,盲猜大家已經無心上班,在數著日子準備過五一,但一想到銀行卡里的余額……瞬間心情就不美麗了。最近,2023年高校畢業生就業調查顯示,本科畢業月平均起薪為5825元。調查一出,便有很多同學表示自己又被平均了。看著這一資料,不免讓人想到前不久中國青年報的一項調查:近六成大學生認為畢業10年內會 ......

    uj5u.com 2023-04-20 07:44:00 more
  • 最新版本 Stable Diffusion 開源 AI 繪畫工具之中文自動提詞篇

    🎈 標簽生成器 由于輸入正向提示詞 prompt 和反向提示詞 negative prompt 都是使用英文,所以對學習母語的我們非常不友好 使用網址:https://tinygeeker.github.io/p/ai-prompt-generator 這個網址是為了讓大家在使用 AI 繪畫的時候 ......

    uj5u.com 2023-04-20 07:43:36 more
  • 漫談前端自動化測驗演進之路及測驗工具分析

    隨著前端技術的不斷發展和應用程式的日益復雜,前端自動化測驗也在不斷演進。隨著 Web 應用程式變得越來越復雜,自動化測驗的需求也越來越高。如今,自動化測驗已經成為 Web 應用程式開發程序中不可或缺的一部分,它們可以幫助開發人員更快地發現和修復錯誤,提高應用程式的性能和可靠性。 ......

    uj5u.com 2023-04-20 07:43:16 more
  • CANN開發實踐:4個DVPP記憶體問題的典型案例解讀

    摘要:由于DVPP媒體資料處理功能對存放輸入、輸出資料的記憶體有更高的要求(例如,記憶體首地址128位元組對齊),因此需呼叫專用的記憶體申請介面,那么本期就分享幾個關于DVPP記憶體問題的典型案例,并給出原因分析及解決方法。 本文分享自華為云社區《FAQ_DVPP記憶體問題案例》,作者:昇騰CANN。 DVPP ......

    uj5u.com 2023-04-20 07:43:03 more
  • msf學習

    msf學習 以kali自帶的msf為例 一、msf核心模塊與功能 msf模塊都放在/usr/share/metasploit-framework/modules目錄下 1、auxiliary 輔助模塊,輔助滲透(埠掃描、登錄密碼爆破、漏洞驗證等) 2、encoders 編碼器模塊,主要包含各種編碼 ......

    uj5u.com 2023-04-20 07:42:59 more
  • Halcon軟體安裝與界面簡介

    1. 下載Halcon17版本到到本地 2. 雙擊安裝包后 3. 步驟如下 1.2 Halcon軟體安裝 界面分為四大塊 1. Halcon的五個助手 1) 影像采集助手:與相機連接,設定相機引數,采集影像 2) 標定助手:九點標定或是其它的標定,生成標定檔案及內參外參,可以將像素單位轉換為長度單位 ......

    uj5u.com 2023-04-20 07:42:17 more
  • 在MacOS下使用Unity3D開發游戲

    第一次發博客,先發一下我的游戲開發環境吧。 去年2月份買了一臺MacBookPro2021 M1pro(以下簡稱mbp),這一年來一直在用mbp開發游戲。我大致分享一下我的開發工具以及使用體驗。 1、Unity 官網鏈接: https://unity.cn/releases 我一般使用的Apple ......

    uj5u.com 2023-04-20 07:40:19 more