ansible安装 ansible不是c/s架构,使用的是sshd远程,所以只需在一台机器安装即可 实验机两台: host1:192.168.2.251 host2:192.168.2.252 1:host1使用Yum安装前,需要安装下epel扩展源 [ [emailprotec
ansible安装
ansible不是c/s架构,使用的是sshd远程,所以只需在一台机器安装即可
实验机两台:
host1:192.168.2.251
host2:192.168.2.252
1:host1使用Yum安装前,需要安装下epel扩展源
[
[email protected] ~]#
yum -y install ansible
说明:
报错提示:
"msg": "Aborting, target uses selinux but python bindings (libselinux-python) aren‘t installed!"
解决方法:
yum -y install libselinux-python
2:安装完成后,host1生成秘钥对,将公钥放置在远程机器上
[
[email protected] ~]#
ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
41:d1:e2:6b:12:d7:d6:9c:77:0d:5c:d5:a0:49:89:5f
[email protected]
The key‘s randomart image is:
+--[ RSA 2048]----+
| oo ..o.o=|
| .. o..oE .|
| ..o +oo ..|
| . o.o = . o|
| oSo . . |
| . o |
| o |
| |
| |
+-----------------+
[
[email protected] ~]#
cat /root/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAt9yV5D4MlhzDY+olyDmJmmNqOZUoGa9Ik6LKvofQC+5Ze2IYFknT8Gv388AVkh5dN511SpXA1qUrbOTkcOR9fVRXdyYOxnRDYGFbZDvTQ2N94xrvFlPobhUNcHLagVMIKY33AVV690s9Dg33XGwC3Wwx2Rwh73uAAAE08JjCAtApu8uc21yM96FuOkraMhJHsr54XJ9wtQFK1nPqqjXJv/eeLFanJ99Jr1VncSBj2TYOQafVvXJ4Xy/m3xoUWSQBtUaqNTAbersxWLboqECPxwJ/uJGntXVk/kLtz0bCzYhWF9Jy0RCrgqkjU5i7pzsdTYg3Q/sgOeJ5Yn3FuYKpRw== [email protected]
4:在host2把host1生成的公钥加本地authorized_keys文件,实现免密登录
[
[email protected] ~]#
vim /root/.ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAt9yV5D4MlhzDY+olyDmJmmNqOZUoGa9Ik6LKvofQC+5Ze2IYFknT8Gv388AVkh5dN511SpXA1qUrbOTkcOR9fVRXdyYOxnRDYGFbZDvTQ2N94xrvFlPobhUNcHLagVMIKY33AVV690s9Dg33XGwC3Wwx2Rwh73uAAAE08JjCAtApu8uc21yM96FuOkraMhJHsr54XJ9wtQFK1nPqqjXJv/eeLFanJ99Jr1VncSBj2TYOQafVvXJ4Xy/m3xoUWSQBtUaqNTAbersxWLboqECPxwJ/uJGntXVk/kLtz0bCzYhWF9Jy0RCrgqkjU5i7pzsdTYg3Q/sgOeJ5Yn3FuYKpRw== [email protected]
5:设置权限为600,关闭selinux
[
[email protected] ~]#
chmod 600 /root/.ssh/authorized_keys
[
[email protected] ~]#
setenforce 0
6::测试免密是否能ssh
[
[email protected] ~]#
ssh 192.168.2.252
The authenticity of host ‘ghs.com (192.168.2.252)‘ can‘t be established.
RSA key fingerprint is cb:54:0d:43:50:6c:a2:20:6e:1f:8a:67:df:16:a5:08.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘ghs.com‘ (RSA) to the list of known hosts.
Last login: Sat Jul 22 09:20:39 2017 from 192.168.2.251
[
[email protected] ~]#
ok