叢集管理工具ansible常用命令介紹(一)
叢集管理工具ansible常用命令介紹(一)
之前介紹過叢集管理工具C3(Cluster Command & Control (C3) Tool Suite)
連結如下:
http://blog.itpub.net/29785807/viewspace-2695330/
下面介紹另一個叢集管理工具ansible,詳細內容連結如下:
Ansible中文權威指南
http://www.ansible.com.cn/
使用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.101 192.168.30.102 #192.168.30.103 #192.168.30.104 192.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" servers 192.168.30.105 | CHANGED | rc=0 >> hello 192.168.30.101 | CHANGED | rc=0 >> hello 192.168.30.102 | CHANGED | rc=0 >> hello
執行命令date -R
[root@tidb01 ~]# ansible -m command -a "date -R" servers 192.168.30.102 | CHANGED | rc=0 >> Sun, 28 Jun 2020 09:15:55 +0800 192.168.30.105 | CHANGED | rc=0 >> Sun, 28 Jun 2020 09:15:54 +0800 192.168.30.101 | CHANGED | rc=0 >> Sun, 28 Jun 2020 09:15:56 +0800
執行命令uptime
[root@tidb01 ~]# ansible -m command -a "uptime" servers 192.168.30.102 | CHANGED | rc=0 >> 09:17:21 up 23 min, 2 users, load average: 0.00, 0.01, 0.05 192.168.30.105 | CHANGED | rc=0 >> 09:17:21 up 22 min, 2 users, load average: 0.24, 0.06, 0.07 192.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'. 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. 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" servers 192.168.30.105 | CHANGED | rc=0 >> /root/cjc.log 192.168.30.102 | CHANGED | rc=0 >> /root/cjc.log 192.168.30.101 | CHANGED | rc=0 >> /root/cjc.log
執行命令getenforce
[root@tidb01 ~]# ansible -m command -a "getenforce" servers 192.168.30.102 | CHANGED | rc=0 >> Disabled 192.168.30.105 | CHANGED | rc=0 >> Disabled 192.168.30.101 | CHANGED | rc=0 >> Disabled
或:
[root@tidb01 ~]# ansible -a "getenforce" servers 192.168.30.105 | CHANGED | rc=0 >> Disabled 192.168.30.102 | CHANGED | rc=0 >> Disabled 192.168.30.101 | CHANGED | rc=0 >> Disabled
指定其中一個主機執行命令
[root@tidb01 ~]# ansible -a "getenforce" 192.168.30.101 192.168.30.101 | CHANGED | rc=0 >> Disabled
執行命令df -h
[root@tidb01 ~]# ansible -a "df -h /" servers 192.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" servers 192.168.30.105 | CHANGED | rc=0 >> total used free shared buff/cache available Mem: 974 411 116 8 446 350 Swap: 2043 0 2043 192.168.30.102 | CHANGED | rc=0 >> total used free shared buff/cache available Mem: 974 414 156 8 403 350 Swap: 2043 0 2043 192.168.30.101 | CHANGED | rc=0 >> total used free shared buff/cache available Mem: 974 413 98 8 462 367 Swap: 3071 0 3071
執行命令,檢視sshd程式
[root@tidb01 ~]# ansible -m shell -a 'ps -ef|grep sshd|grep -v grep' servers 192.168.30.105 | CHANGED | rc=0 >> root 1374 1 0 08:54 ? 00:00:00 /usr/sbin/sshd -D root 2090 1374 0 08:56 ? 00:00:00 sshd: root@pts/0 root 8581 1374 0 10:38 ? 00:00:00 sshd: root@pts/1 192.168.30.102 | CHANGED | rc=0 >> root 1370 1 0 08:54 ? 00:00:00 /usr/sbin/sshd -D root 2089 1370 0 08:56 ? 00:00:00 sshd: root@pts/0 root 9041 1370 0 10:38 ? 00:00:00 sshd: root@pts/2 root 10181 1370 0 10:41 ? 00:00:00 sshd: root@pts/1 192.168.30.101 | CHANGED | rc=0 >> root 1009 1 0 09:06 ? 00:00:00 /usr/sbin/sshd -D root 1242 1009 0 09:06 ? 00:00:00 sshd: root@pts/1 root 8590 1009 0 10:38 ? 00:00:00 sshd: root@pts/2
歡迎關注我的微信公眾號"IT小Chen",共同學習,共同成長!!
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29785807/viewspace-2700983/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- ClickHouse 邏輯叢集介紹
- Redis 漸進叢集介紹Redis
- kubernetes叢集管理常用命令一
- Redis叢集介紹及測試思路Redis
- 使用 Ansible 快速部署 HBase 叢集
- 叢集自動化工具--Ansible
- Ansible(1)- 簡單介紹
- solr叢集構建的基本流程介紹Solr
- VictoriaMetrics 中文教程(10)叢集版介紹
- 第76篇 Redis叢集詳細介紹Redis
- ansible快速部署cassandra3叢集
- Ansible部署K8s叢集K8S
- 面試官:介紹一下 Redis 三種叢集模式面試Redis模式
- Hadoop叢集常用命令Hadoop
- linux叢集常用命令Linux
- 三千字介紹Redis主從+哨兵+叢集Redis
- Etcd叢集的介紹和選主應用
- 十 叢集管理常用命令
- k8s介紹及與docker搭建叢集K8SDocker
- 用Ansible 自動化搭建本地Kubernetes叢集
- redis叢集管理工具HHDBCSRedis
- sftp常用命令介紹FTP
- Linux常用命令介紹Linux
- 【Redis】常用命令介紹Redis
- RPM常用命令介紹
- 自動化運維工具Ansible介紹運維
- 版本管理工具Git(一)簡要介紹Git
- 介紹一款docker管理工具——portainerDockerAI
- 阿里超大規模 Flink 叢集運維體系介紹阿里運維
- 叢集管理工具C3
- Git 介紹與常用命令Git
- (2)Docker常用命令介紹Docker
- Redis介紹、使用、資料結構和叢集模式總結Redis資料結構模式
- 使用Ansible為叢集初始化並配置免密
- 一文詳細介紹工業交換機叢集以及其連線方式
- 使用Ansible指令碼安裝K8S叢集,介紹元件互動原理,方便直接,不受國內網路環境影響指令碼K8S元件內網
- Zookeeper介紹與叢集安裝
- ceph叢集常用命令精華彙總!