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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

macos下使用aria2_macOS下 ansible简单安装及基础使用

發布時間:2025/3/11 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 macos下使用aria2_macOS下 ansible简单安装及基础使用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

macOS下 ansible簡單安裝及基礎使用,其實命令是相通的,我這篇測試基本都是在macOS下執行的。在Linux操作系統下幾乎同樣的辦法。

ansible是一種自動化運維工具,基于Python開發,實現了批量系統配置、批量程序部署、批量運行命令等功能

我測系統環境:

OS: macOS Catalina 10.15.7

Python2個版本:我準備基于Python3來按照

? ~ which python

/usr/bin/python

? ~ /usr/bin/python -V

Python 2.7.16

? ~ /usr/local/Cellar/python@3.9/3.9.0/bin/python3 -V

Python 3.9.0

? ~ /usr/local/Cellar/python@3.9/3.9.0/bin/pip3 -V

pip 20.2.3 from /usr/local/lib/python3.9/site-packages/pip (python 3.9)

? ~ /usr/bin/pip3 -V

pip 19.2.3 from /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/site-packages/pip (python 3.8

ansible可以通過源碼,yum,pip,brew等方式安裝,本文采用pip安裝方式,首先ansible基于python環境

? ~ /usr/local/Cellar/python@3.9/3.9.0/bin/pip3 -Vpip 20.2.3 from /usr/local/lib/python3.9/site-packages/pip (python 3.9)? ~ /usr/local/Cellar/python@3.9/3.9.0/bin/pip3 install ansibleCollecting ansible

ansible --version 命令 檢查安裝是否成功

? ~ /usr/local/bin/ansible --version

ansible 2.10.2

config file = None

configured module search path = ['/Users/lex/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']

ansible python module location = /usr/local/lib/python3.9/site-packages/ansible

executable location = /usr/local/bin/ansible

python version = 3.9.0 (default, Oct 6 2020, 04:17:54) [Clang 12.0.0 (clang-1200.0.32.2)]

pip安裝是沒有config file文件的 我們可以將官網的默認文件上傳到服務器

https://raw.githubusercontent.com/ansible/ansible/devel/examples/ansible.cfg

mac下安裝后缺少 /etc/ansible 目錄,需要手動添加

sudo mkdir /etc/ansible? ansible pwd/etc/ansible? ansible ls? ansible sudo touch ansible.cfg編輯內容:? ansible cat ansible.cfg[defaults]remote_tmp = $HOME/.ansible/tmplocal_tmp = $HOME/.ansible/tmpremote_port = 22host_key_checking = Falseremote_user = rootmodule_name = commandexecutable = /bin/bashprivate_key_file = /Users/lex/.ssh/id_rsa[privilege_escalation][paramiko_connection][ssh_connection][accelerate][selinux][colors]

再次查看版本:/etc/ansible/ansible.cfg可以看到了

? ~ ansible --version

ansible 2.10.2

config file = /etc/ansible/ansible.cfg

configured module search path = ['/Users/lex/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']

ansible python module location = /usr/local/lib/python3.9/site-packages/ansible

executable location = /usr/local/bin/ansible

python version = 3.9.0 (default, Oct 6 2020, 04:17:54) [Clang 12.0.0 (clang-1200.0.32.2)]

我來測試一個hosts,很重要的一點就是需要配置ssh打通本地主機和服務器。這里不再贅述。

/Users/lex/Downloads/docker/rancher/rancher.txt? rancher cat /Users/lex/Downloads/docker/rancher/rancher.txt# SSH Keys configuration[rancher:vars]ansible_ssh_private_key_file = /Users/lex/.ssh/id_rsaansible_ssh_user=root#My Test Rancher[rancher]10.211.55.4:2210.211.55.5:2210.211.55.6:2210.211.55.7:22

下面貼幾個常用的參數:

-m MODULE_NAME, --module-name MODULE_NAME module name to execute (default=command) -i INVENTORY, --inventory INVENTORY, --inventory-file INVENTORY specify inventory host path or comma separated host list. --inventory-file is deprecated -a MODULE_ARGS, --args MODULE_ARGS module arguments

命令開測:

? ansible -i /Users/lex/Downloads/docker/rancher/rancher.txt -m ping rancher

? ansible -i /Users/lex/Downloads/docker/rancher/rancher.txt -m ping all

? ansible -i /Users/lex/Downloads/docker/rancher/rancher.txt -m raw -a "w" rancher

結果大致如下:

0.211.55.4 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "ping": "pong"}10.211.55.6 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "ping": "pong"}下面是w的結果 10:36:23 up 19 min, 1 user, load average: 0.20, 0.16, 0.16USER TTY FROM LOGIN@ IDLE JCPU PCPU WHATroot pts/0 10.211.55.2 10:36 0.00s 0.01s 0.00s wShared connection to 10.211.55.6 closed.

下面簡單了解幾個模塊:

遠程命令模塊

模塊包括command、script、shell,都可以實現遠程shell命令運行。

command 是Ansible的默認模塊,可以運行遠程權限范圍內的所有shell命令

~ ansible -i /Users/lex/Downloads/docker/rancher/rancher.txt -m shell -a "df -h" rancher~ ansible all -i /Users/lex/Downloads/docker/rancher/rancher.txt -m command -a "ifconfig"~ ansible all -i /Users/lex/Downloads/docker/rancher/rancher.txt -m command -a "w"shell 是執行遠程主機的shell腳本文件ansible all -i /Users/lex/Downloads/docker/rancher/rancher.txt -m shell -a "/home/test.sh"

get_url:實現在遠程主機下載指定URL到服務器本地

ansible all -i /Users/lex/Downloads/docker/rancher/rancher.txt -m get_url -a "url=https://www.toutiao.com/i6887741380542759437/ dest=/tmp/index.html mode=0400 force=yes"

script 是在遠程主機執行主控端存儲的shell腳本文件,相當于scp+shell組合

做個測試:

? rancher chmod 755 test.sh

? rancher cat /Users/lex/Downloads/docker/rancher/test.sh

#!/bin/bash

date +%F-%T >> /tmp/abc

echo "abc" >> /tmp/abc

執行命令

ansible all -i /Users/lex/Downloads/docker/rancher/rancher.txt -m script -a "/Users/lex/Downloads/docker/rancher/test.sh"

執行OK之后可以看到服務器上有/tmp/abc生成

stat模塊

獲取遠程文件狀態信息,包括atime、ctime、mtime、md5、uid、gid等等

ansible all -i /Users/lex/Downloads/docker/rancher/rancher.txt -m stat -a "path=/tmp/test.sh"

copy模塊

實現主控端向目標主機拷貝文件,類似scp,下面例子實現拷貝/Users/lex/Downloads/docker/rancher/test.sh文件到對應的各主機的 /tmp/ 目錄下 ,并更新文件屬組及權限

ansible all -i /Users/lex/Downloads/docker/rancher/rancher.txt -m copy -a "src=/Users/lex/Downloads/docker/rancher/test.sh dest=/tmp/ owner=root group=root mode=0755"結果輸出類似:10.211.55.6 | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": true, "checksum": "0608eba2095775a66bb3de241e56fc2027b50611", "dest": "/tmp/test.sh", "gid": 0, "group": "root", "md5sum": "592b2d653b8559239bd075fedffb1c28", "mode": "0755", "owner": "root", "size": 59, "src": "/root/.ansible/tmp/ansible-tmp-1603778968.826366-45718-266518561249784/source", "state": "file", "uid": 0}

對于拷貝上去的那個文件,也可以單獨使用file模塊實現權限修改

ansible all -i /Users/lex/Downloads/docker/rancher/rancher.txt -m file -a "path=/tmp/test.sh owner=root group=root mode=0775"輸出節略:10.211.55.5 | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": true, "gid": 0, "group": "root", "mode": "0775", "owner": "root", "path": "/tmp/test.sh", "size": 59, "state": "file", "uid": 0}

yum模塊

軟件包管理操作,常見有yum、apt(pkg和name是要安裝的包名)

下面這個可以在支持apt的Linux上測試

? ansible all -i /Users/lex/Downloads/docker/rancher/rancher.txt -m apt -a "name=iptraf state=latest"

下面這個可以在支持Yum的linux主機測試。

ansible all -i /Users/lex/Downloads/docker/rancher/rancher.txt -m yum -a "name=sysstat state=latest"ansible all -i /Users/lex/Downloads/docker/rancher/rancher.txt -m yum -a "pkg=dstat state=latest"10.211.55.6 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "changes": { "installed": [], "updated": [] }, "msg": "", "rc": 0, "results": [ "All packages providing dstat are up to date", "" ]}ansible all -i /Users/lex/Downloads/docker/rancher/rancher.txt -m yum -a "pkg=iptraf state=latest"10.211.55.5 | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": true, "changes": { "installed": [ "iptraf" ], "updated": [] }, "msg": "", "rc": 0, "results": [ "Loaded plugins: fastestmirror, langpacksLoading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirror.bit.edu.cn * updates: mirrors.aliyun.comResolving Dependencies--> Running transaction check---> Package iptraf-ng.x86_64 0:1.1.4-7.el7 will be installed--> Finished Dependency ResolutionDependencies Resolved================================================================================ Package Arch Version Repository Size================================================================================Installing: iptraf-ng x86_64 1.1.4-7.el7 base 301 kTransaction Summary================================================================================Install 1 PackageTotal download size: 301 kInstalled size: 644 kDownloading packages:Running transaction checkRunning transaction testTransaction test succeededRunning transaction Installing : iptraf-ng-1.1.4-7.el7.x86_64 1/1 Verifying : iptraf-ng-1.1.4-7.el7.x86_64 1/1 Installed: iptraf-ng.x86_64 0:1.1.4-7.el7 Complete!" ]}

可以看到服務器上的大概日志:

Oct 27 14:36:28 node1 systemd: Started Session 34 of user root.Oct 27 14:36:28 node1 systemd-logind: New session 34 of user root.Oct 27 14:36:29 node1 python: ansible-ansible.legacy.setup Invoked with filter=ansible_pkg_mgr gather_subset=['!all'] fact_path=/etc/ansible/facts.d gather_timeout=10Oct 27 14:36:29 node1 python: ansible-ansible.legacy.yum Invoked with lock_timeout=30 update_cache=False disable_excludes=None exclude=[] allow_downgrade=False disable_gpg_check=False conf_file=None use_backend=auto state=latest disablerepo=[] releasever=None skip_broken=False autoremove=False download_dir=None enable_plugin=[] installroot=/ install_weak_deps=True name=['sysstat'] download_only=False bugfix=False list=None install_repoquery=True update_only=False disable_plugin=[] enablerepo=[] security=False validate_certs=True

service模塊

系統服務管理

state(started/stopped/restarted/reloaded)ansible all -i /Users/lex/Downloads/docker/rancher/rancher.txt -m service -a "name=sshd state=restarted"

日志大致如下:

Oct 27 14:40:39 node1 systemd: Started Session 36 of user root.Oct 27 14:40:40 node1 python: ansible-ansible.legacy.setup Invoked with filter=ansible_service_mgr gather_subset=['!all'] fact_path=/etc/ansible/facts.d gather_timeout=10Oct 27 14:40:41 node1 python: ansible-ansible.legacy.systemd Invoked with no_block=False force=None name=sshd daemon_reexec=False enabled=None daemon_reload=False state=restarted masked=None scope=system user=NoneOct 27 14:40:41 node1 systemd: Stopping OpenSSH server daemon...Oct 27 14:40:41 node1 systemd: Stopped OpenSSH server daemon.Oct 27 14:40:41 node1 systemd: Starting OpenSSH server daemon...Oct 27 14:40:41 node1 systemd: Started OpenSSH server daemon.Oct 27 14:41:41 node1 systemd-logind: Removed session 36.

再更加詳細的使用方式。大家可以檢索的看看。

1 962 ansible controller,compute -a "systemctl status libvirtd && systemctl restart libvirtd" 1 954 ansible controller,compute -m shell -a "systemctl stop openstack-ceilometer*" 1 953 ansible controller,compute -m shell -a "systemctl start openstack-ceilometer*" 1 952 ansible controller,compute -m shell -a "systemctl stop openstack-ceilometer*" 1 951 ansible controller,compute -m shell -a "openstack-service status"

總結

以上是生活随笔為你收集整理的macos下使用aria2_macOS下 ansible简单安装及基础使用的全部內容,希望文章能夠幫你解決所遇到的問題。

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

主站蜘蛛池模板: 日本大尺度做爰呻吟舌吻 | 青青操国产 | 成人做爰9片免费视频 | 96精品视频 | 色花堂在线 | 91精品久久久久久久 | 国产吞精囗交久久久 | 午夜在线观看视频 | 手机在线亚洲 | 亚洲色图网站 | 免费成人在线网站 | 亚洲一区二区视频在线观看 | 中国丰满熟妇xxxx性 | www.色就是色 | 91精品在线视频观看 | 亚洲精品国产电影 | 国产在线播放一区二区三区 | 91精品国产乱码 | 打屁股疼的撕心裂肺的视频 | 二级毛片在线观看 | 麻豆com| 中文字幕亚洲在线观看 | 在线永久看片免费的视频 | 插骚| 亚洲精品在线观看免费 | 欧美亚洲一区二区在线观看 | 桃色成人| 亚洲乱码国产乱码精品精剪 | 老师张开让我了一夜av | 91蜜桃视频 | 黄色三级视频在线观看 | 亚洲天堂中文在线 | 五十路六十路 | 人人澡人人透人人爽 | 亚洲美女高潮久久久 | 风间ゆみ大战黑人 | xxxxx国产 | 免费黄色激情视频 | 亚洲精品视频网址 | 少妇视频网站 | 毛片黄色片 | 一级片一区 | 风间由美一区二区 | 成年人看的视频网站 | 国产免费中文字幕 | 丰满岳妇乱一区二区三区 | 欧美性生活一区二区三区 | 欧美日韩乱国产 | 国产xxxxx视频 | 国产第一亚洲 | 中文字幕日韩欧美 | 人妻一区二区视频 | 视频国产在线 | 影音先锋蜜桃 | 国产美女免费无遮挡 | 免费看毛片的网站 | 欧美日韩在线观看一区 | 欧美激情一二三 | 一级黄色片在线播放 | 亚洲精品久久久中文字幕 | www.色播| 日本动漫艳母 | 九九精品影院 | 亚洲涩涩爱 | 欧美草比视频 | 免费看黄网址 | 日本三级韩国三级美三级91 | 在线五月天 | 16—17女人毛片 | 四虎国产成人永久精品免费 | 国产一二区在线观看 | 一区国产在线 | 欧美日韩看片 | 毛片免费一区二区三区 | 国产精品黄| 99ri在线观看 | 黄色网址你懂得 | 黄色一级网址 | 日本一区二区三区四区五区 | 长河落日电视连续剧免费观看 | 亚洲精品视频在线播放 | 山外人精品影院 | 亚洲成人乱码 | 日韩精品久久久久久免费 | 狠狠地日 | 一区二区三区在线观看免费视频 | 99久久久成人国产精品 | 国产人妖一区 | 使劲插视频 | 亚洲国产www| 欧美一区视频在线 | 黄色小视屏 | 精品亚洲aⅴ无码一区二区三区 | 91久久国产精品 | 亚洲色图40p| 青青草手机视频在线观看 | ass大乳尤物肉体pics | 黄瓜视频在线免费观看 | 一区二区三区视频免费看 |