码迷,mamicode.com
首页 > 其他好文 > 详细

集群运维ansible

时间:2019-03-17 10:22:08      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:连接   root   星期六   library   sea   秘钥   figure   com   enter   


生成秘钥,一路enter

cd ~/.ssh/
ssh-keygen -t rsa

讲id_rsa.pub文件追加到授权的key文件中

cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

把第一台机器的authorized_keys文件复制到第二台机子上,把公钥给对方,才能免密登录远程服务器

scp authorized_keys root@172.16.92.128:~/.ssh/

把第二台的公钥也追加

cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

把所有公钥文件,汇总到最后一台机子后,再覆盖之前机子的文件,最后测试

ssh root@sjck-node01
Last login: Sat Mar 16 15:30:15 2019 from 172.16.92.1

mac安装ansible

sudo pip install ansible

安装结束

Running setup.py install for ansible ... done
Successfully installed MarkupSafe-1.1.1 ansible-2.7.9 bcrypt-3.1.6 jinja2-2.10 paramiko-2.4.2 pyasn1-0.4.5 pynacl-1.3.0

查看版本

ansible --version
ansible 2.7.9
  config file = None
  configured module search path = [u'/Users/user/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /Library/Python/2.7/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.10 (default, Oct  6 2017, 22:29:07) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)]

集群配置文件

cat /etc/ansible/hosts 
[spark] 
sjck-node01 ansible_user=root  
sjck-node02 ansible_user=root
sjck-node03 ansible_user=root

ping测试

ansible spark -m ping
sjck-node02 | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}
sjck-node03 | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}
sjck-node01 | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}

查看集群基本信息

ansible spark -m setup

执行远程命令

关闭其中加一个节点,返回连接超时

ansible spark -m command -a 'date'
sjck-node02 | CHANGED | rc=0 >>
2019年 03月 16日 星期六 15:23:17 CST

sjck-node03 | CHANGED | rc=0 >>
2019年 03月 16日 星期六 15:23:17 CST

sjck-node01 | UNREACHABLE! => {
    "changed": false, 
    "msg": "Failed to connect to the host via ssh: ssh: connect to host sjck-node01 port 22: Operation timed out", 
    "unreachable": true
}

集群运维ansible

标签:连接   root   星期六   library   sea   秘钥   figure   com   enter   

原文地址:https://www.cnblogs.com/wanli002/p/10545752.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!