集群管理工具ansible常用命令有哪些
发表于:2025-12-02 作者:千家信息网编辑
千家信息网最后更新 2025年12月02日,这篇文章给大家介绍集群管理工具ansible常用命令有哪些,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。集群管理工具ansible常用命令使用ansible过程如下:主控端:安装
千家信息网最后更新 2025年12月02日集群管理工具ansible常用命令有哪些
这篇文章给大家介绍集群管理工具ansible常用命令有哪些,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
集群管理工具ansible常用命令
使用ansible过程如下:
主控端:安装ansible
# install the epel-release RPM if needed on CentOS, RHEL, or Scientific Linux
[root@tidb01 ~]# yum install epel-release[root@tidb01 ~]# yum -y install ansible[root@tidb01 ~]# ansible --version
ansible 2.9.10 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, Apr 11 2018, 07:36:10) [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)]
配置hosts,添加被管控的主机
[root@tidb01 ~]# cat /etc/ansible/hosts
[servers]192.168.30.101192.168.30.102#192.168.30.103#192.168.30.104192.168.30.105#192.168.30.106
生成密钥
[root@tidb01 ~]# ssh-keygen
使用ssh-copy-id命令来复制ansible公钥到各个节点
[root@tidb01 ~]# ssh-copy-id root@192.168.30.101[root@tidb01 ~]# ssh-copy-id root@192.168.30.102[root@tidb01 ~]# ssh-copy-id root@192.168.30.105
执行ping命令
[root@tidb01 ~]# ansible servers -m ping#或:[root@tidb01 ~]# ansible servers -i /etc/ansible/hosts -m ping#或:[root@tidb01 ~]# ansible -m ping servers#或:[root@tidb01 ~]# ansible -m ping all
192.168.30.102 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "ping": "pong"}192.168.30.105 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "ping": "pong"}192.168.30.101 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "ping": "pong"}指定用户,执行ping命令
[root@tidb01 ~]# ssh-copy-id chen@192.168.30.101[root@tidb01 ~]# ssh-copy-id chen@192.168.30.102[root@tidb01 ~]# ssh-copy-id chen@192.168.30.105[root@tidb01 ~]# ansible all -m ping -u chen
192.168.30.105 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "ping": "pong"}192.168.30.102 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "ping": "pong"}192.168.30.101 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "ping": "pong"}执行命令echo hello
[root@tidb01 ~]# ansible -a "echo hello" servers192.168.30.105 | CHANGED | rc=0 >>hello192.168.30.101 | CHANGED | rc=0 >>hello192.168.30.102 | CHANGED | rc=0 >>hello
执行命令date -R
[root@tidb01 ~]# ansible -m command -a "date -R" servers192.168.30.102 | CHANGED | rc=0 >>Sun, 28 Jun 2020 09:15:55 +0800192.168.30.105 | CHANGED | rc=0 >>Sun, 28 Jun 2020 09:15:54 +0800192.168.30.101 | CHANGED | rc=0 >>Sun, 28 Jun 2020 09:15:56 +0800
执行命令uptime
[root@tidb01 ~]# ansible -m command -a "uptime" servers192.168.30.102 | CHANGED | rc=0 >> 09:17:21 up 23 min, 2 users, load average: 0.00, 0.01, 0.05192.168.30.105 | CHANGED | rc=0 >> 09:17:21 up 22 min, 2 users, load average: 0.24, 0.06, 0.07192.168.30.101 | CHANGED | rc=0 >> 09:17:22 up 11 min, 2 users, load average: 0.08, 0.09, 0.07
执行命令touch /root/cjc.log
[root@tidb01 ~]# ansible -m command -a "touch /root/cjc.log" servers[WARNING]: Consider using the file module with state=touch rather than running 'touch'. Ifyou need to use command because file is insufficient you can add 'warn: false' to this commandtask or set 'command_warnings=False' in ansible.cfg to get rid of this message.192.168.30.102 | CHANGED | rc=0 >>192.168.30.105 | CHANGED | rc=0 >>192.168.30.101 | CHANGED | rc=0 >>
执行命令ls /root/cjc.log
[root@tidb01 ~]# ansible -m command -a "ls /root/cjc.log" servers192.168.30.105 | CHANGED | rc=0 >>/root/cjc.log192.168.30.102 | CHANGED | rc=0 >>/root/cjc.log192.168.30.101 | CHANGED | rc=0 >>/root/cjc.log
执行命令getenforce
[root@tidb01 ~]# ansible -m command -a "getenforce" servers192.168.30.102 | CHANGED | rc=0 >>Disabled192.168.30.105 | CHANGED | rc=0 >>Disabled192.168.30.101 | CHANGED | rc=0 >>Disabled
或:
[root@tidb01 ~]# ansible -a "getenforce" servers192.168.30.105 | CHANGED | rc=0 >>Disabled192.168.30.102 | CHANGED | rc=0 >>Disabled192.168.30.101 | CHANGED | rc=0 >>Disabled
指定其中一个主机执行命令
[root@tidb01 ~]# ansible -a "getenforce" 192.168.30.101192.168.30.101 | CHANGED | rc=0 >>Disabled
执行命令df -h
[root@tidb01 ~]# ansible -a "df -h /" servers192.168.30.102 | CHANGED | rc=0 >>Filesystem Size Used Avail Use% Mounted on/dev/mapper/vg_cjc-lv_root 18G 7.1G 11G 40% /192.168.30.105 | CHANGED | rc=0 >>Filesystem Size Used Avail Use% Mounted on/dev/mapper/vg_cjc-lv_root 18G 7.0G 11G 40% /192.168.30.101 | CHANGED | rc=0 >>Filesystem Size Used Avail Use% Mounted on/dev/mapper/vg_srv-lv_root 25G 8.1G 17G 33% /
执行命令free -m
[root@tidb01 ~]# ansible -a "free -m" servers192.168.30.105 | CHANGED | rc=0 >> total used free shared buff/cache availableMem: 974 411 116 8 446 350Swap: 2043 0 2043192.168.30.102 | CHANGED | rc=0 >> total used free shared buff/cache availableMem: 974 414 156 8 403 350Swap: 2043 0 2043192.168.30.101 | CHANGED | rc=0 >> total used free shared buff/cache availableMem: 974 413 98 8 462 367Swap: 3071 0 3071
执行命令,查看sshd进程
[root@tidb01 ~]# ansible -m shell -a 'ps -ef|grep sshd|grep -v grep' servers192.168.30.105 | CHANGED | rc=0 >>root 1374 1 0 08:54 ? 00:00:00 /usr/sbin/sshd -Droot 2090 1374 0 08:56 ? 00:00:00 sshd: root@pts/0root 8581 1374 0 10:38 ? 00:00:00 sshd: root@pts/1192.168.30.102 | CHANGED | rc=0 >>root 1370 1 0 08:54 ? 00:00:00 /usr/sbin/sshd -Droot 2089 1370 0 08:56 ? 00:00:00 sshd: root@pts/0root 9041 1370 0 10:38 ? 00:00:00 sshd: root@pts/2root 10181 1370 0 10:41 ? 00:00:00 sshd: root@pts/1192.168.30.101 | CHANGED | rc=0 >>root 1009 1 0 09:06 ? 00:00:00 /usr/sbin/sshd -Droot 1242 1009 0 09:06 ? 00:00:00 sshd: root@pts/1root 8590 1009 0 10:38 ? 00:00:00 sshd: root@pts/2
关于集群管理工具ansible常用命令有哪些就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
命令
工具
常用
管理工具
集群
管理
主机
内容
更多
帮助
不错
公钥
兴趣
密钥
小伙
小伙伴
文章
用户
知识
篇文章
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
英语单词笔记软件开发
vf三种数据库类型
中国政企网络安全服务上岗证
基于中文数据库的知...
数据库系统e-r图
软件开发课程教材
无限传感器网络技术
数据库如何做延时队列
软件开发个税怎么交
有潜力的重庆移动服务器托管
国际服务器数量
java连接异构数据库
中兴软件开发南京岗位怎么样
数据库测试结果的正确性
数据库趋势
叮哒助手虚拟打卡连接服务器失败
家网络安全宣传周主题
阿里云学生服务器续费
海口软件开发工作
通达OA网页进入数据库
网络安全风险检测预警
怎么让电脑添加到服务器
查看vivo手机应用数据库
疾病和靶点的数据库
暑假网络安全作业
国家实施网络安全身份战略
什么情况下数据库占内存多
什么是网络安全图片
郑州祥瑞网络技术怎么样
贵州网络时间同步服务器云空间