集群运维ansible


####生成秘钥,一路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
}
上一篇:Codeforces Round #292 (Div. 1)A. Drazil and Factorial 构造


下一篇:CSS3学习笔记(5)—页面遮罩效果