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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

Ansible批量在远程主机执行命令

發布時間:2023/12/13 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Ansible批量在远程主机执行命令 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

  Ansible直接執行遠程命令,不用ssh登陸交互執行。
  
  如下:
  
  ansible all -i 192.168.199.180, -m shell -a "ifconfig" -u supermap
  
  參數解釋:
  
  -i 連接到遠程主機“192.168.199.180,”,注意這里的“,”直接指定主機名列表,沒有“,”該參數則被解釋為主機名的列表文件。
  
  -m 為ansible模塊名稱,執行shell命令。
  
  -a 遠程shell命令,為ifconfig(獲取網絡配置參數)。
  
  -u 指定執行的遠程主機用戶名。
  
  -k 可以指定是否交互輸入參數,如果沒有,則需要在本機有預存的訪問密鑰。
  
  可以先使用ssh登錄,選擇保存,即可自動保存下來。
  
  主機文件格式,樣例參考( host-list):
  
  [local]
  
  192.168.199.173 ansible_ssh_port=22 ansible_ssh_host=192.168.199.173 ansible_ssh_user=supermap ansible_ssh_pass=SuperMap
  
  192.168.199.180 ansible_ssh_port=22 ansible_ssh_host=192.168.199.180 ansible_ssh_user=supermap ansible_ssh_pass=SuperMap
  
  192.168.199.249 ansible_www.yongshi123.cn ssh_port=22 www.dfgjpt.com ansible_ssh_www.yongshiyule178.com host=192.168.199.249 ansible_ssh_user=openswitch ansible_ssh_pass=SuperMap
  
  使用主機文件,自動登錄后,批量執行命令:
  
  ansible all -i host-list -m shell -a "ifconfig" -u my-username
  
  這個還是很方便的。
  
  最近遇到一些FreeBSD的故障,在這種操作系統上我們平時用的一些命令無法執行,FreeBSD的一些配置文件也和其他很多Linux系統不一樣。為了方便以后查閱,我特別整理了這篇文檔。
  
  1. 網絡
  
  重啟網絡的命令:
  
  /etc/rc.d/netif restart , /etc/netstart restart
  
  網絡配置文件:
  
  root@mhxy-compile02:~ # cat /etc/rc.conf
  
  ifconfig_em0="DHCP"
  
  sshd_enable="NO"
  
  ntpd_enable="YES"
  
  # Set dumpdev to "AUTO" to enable crash dumps, "NO" to disable
  
  dumpdev="AUTO"
  
  zfs_enable="YES"
  
  puppet_enable="YES"
  
  ipv6_enable="NO"
  
  hostname="mhxy-compile02.i.nease.net"
  
  nfs_client_enable="YES"
  
  rpc_lockd_enable="YES"
  
  rpc_statd_enable="YES"
  
  2. SSH
  
  命令:
  
  /etc/rc.d/sshd start , /etc/rc.d/sshd restart
  
  SSH配置文件:
  
  root@mhxy-compile02:~ # cat /etc/ssh/sshd_config
  
  # THIS FILE IS AUTOMATICALLY GENERATED BY PUPPET.
  
  # DO NOT EDIT THIS FILE.
  
  # 1. Basic
  
  Port 32200
  
  Protocol 2
  
  # 2. Authentication
  
  HostKey /etc/ssh/ssh_host_rsa_key
  
  HostKey www.boyunylpt1.com /etc/ssh/ssh_host_dsa_key
  
  KeyRegenerationInterval 3600
  
  ServerKeyBits 768
  
  UsePrivilegeSeparation yes
  
  LoginGraceTime 120
  
  PermitRootLogin no
  
  StrictModes yes
  
  RSAAuthentication yes
  
  PubkeyAuthentication yes
  
  PermitEmptyPasswords no
  
  ChallengeResponseAuthentication no
  
  PasswordAuthentication no
  
  IgnoreRhosts yes
  
  RhostsRSAAuthentication no
  
  HostbasedAuthentication no
  
  # 3. Features
  
  UseDNS no
  
  X11Forwarding www.maituyul1.cn yes
  
  X11DisplayOffset 10
  
  PrintMotd no
  
  PrintLastLog yes
  
  TCPKeepAlive yes
  
  AcceptEnv LANG LC_*
  
  # 4. Logging
  
  SyslogFacility AUTH
  
  LogLevel INFO
  
  # 5. x509
  
  Subsystem sftp www.enzuovip.com /usr/libexec/sftp-server
  
  #CACertificateFile www.huarenyl.cn /etc/ssh/ca/ca.cer
  
  3. 防火墻
  
  1)停止ipfw防火墻:
  
  ipfw disable firewall
  
  /etc/rc.d/ipfw stop
  
  2)開啟ipfw防火墻:
  
  ipfw enable firewall
  
  /etc/rc.d/ipfw start
  
  3)清防火墻
  
  ipf -Fa
  
  4.賦予用戶root權限
  
  1)pw groupmod www.furongpt.com wheel -m
  
  2)pw user mod -g wheel
  
  5.查看CPU和內存
  
  1)sysctl kern.smp.cpus或dmesg |grep cpu #查看CPU個數
  
  2)dmesg|more或top #查看內存
  
  參考:
  
  Ansible快速開始-指揮集群
  
  Ansible :一個配置管理和IT自動化工具(1/3)
  
  Ansible :一個配置管理和IT自動化工具(2/3)
  
  Ansible :一個配置管理和IT自動化工具 (3/3)
  
  部署生產級的 Kubernetes 集群,使用kubespray
  
  Kubeflow等鏡像部署到集群多節點

轉載于:https://www.cnblogs.com/qwangxiao/p/10464066.html

總結

以上是生活随笔為你收集整理的Ansible批量在远程主机执行命令的全部內容,希望文章能夠幫你解決所遇到的問題。

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