如何安装和管理服务器?

企业IT需要的不仅仅是传统IT工具。因为在IT基础设施中有不同的体系结构和风格。在一个小公司里,一台web服务器就足够了,但在一个企业公司里,可能有10到100台web服务器来满足部门的不同需求。这里最重要的事情之一是以简单而自信的方式协调和管理基础设施。 安西布尔 是一个为服务器管理员或devops提供此功能的工具。

Linux视频教程 基础Shell编程 openstack/Nginx/redis运维ansible
手机、电脑、平板直接观看 | 月销量46件
优惠价29.9元
原价¥29.9

淘口令:

¥rLLvXPnjLTH¥
 

安装

我们将使用 Fedora服务器 本教程为24位,我们的体系结构为64位。1GB对于简单的测试来说已经足够了,但是请记住,如果您的工作很复杂,那么还有更多的空间。我们有两个名为poftut1和poftut2的服务器。我们将从poftut1管理这两个服务器。

$ sudo dnf install ansible -y

安装nano以编辑Ansible hosts文件。

$ sudo dnf install nano -y

打开并添加IP地址为poftutu servers组的服务器

$ nano /etc/ansible/hosts

添加以下行。这个文件在Ansible术语中称为inventory。

[poftut_servers] 127.0.0.1       poftut1   192.168.122.234 poftut2

从简单开始

我们已完成安装和设置。现在,我们将尝试使用组名访问服务器。

$ ansible poftut_servers -a "hostname" The authenticity of host '127.0.0.1 (127.0.0.1)' can't be established. ECDSA key fingerprint is SHA256:BG7kN+MYiC1SB84l7XuyW/ahCtDIs1Ewf4u0CiHgZ3M. ECDSA key fingerprint is MD5:25:f7:ea:8f:ae:7f:59:22:44:3e:97:fa:ec:c6:f7:62. Are you sure you want to continue connecting (yes/no)? The authenticity of host '192.168.122.234 (192.168.122.234)' can't be established. ECDSA key fingerprint is SHA256:GsOxJithwTGuhXUQUSAEsmjI+kjo3Bk43iGxGZJ90UA. ECDSA key fingerprint is MD5:e4:bd:d7:0d:a2:68:df:f5:84:75:11:6f:7f:e6:12:82. Are you sure you want to continue connecting (yes/no)? yes 127.0.0.1 | UNREACHABLE! => {     "changed": false,                                                                                                                     "msg": "Failed to connect to the host via ssh.",                                                                                      "unreachable": true                                                                                                               }

我们不能跑 主机名 命令在这里。因为我们必须为当前用户提供密码,或者为ssh设置基于密钥的身份验证。其次是更安全。

$ ssh-copy-id localhost /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub" The authenticity of host 'localhost (::1)' can't be established. ECDSA key fingerprint is SHA256:BG7kN+MYiC1SB84l7XuyW/ahCtDIs1Ewf4u0CiHgZ3M. ECDSA key fingerprint is MD5:25:f7:ea:8f:ae:7f:59:22:44:3e:97:fa:ec:c6:f7:62. Are you sure you want to continue connecting (yes/no)? yes /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys [email protected]'s password:   Number of key(s) added: 1  Now try logging into the machine, with:   "ssh 'localhost'" and check to make sure that only the key(s) you wanted were added.
$ ssh-copy-id 192.168.122.234 /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub" The authenticity of host '192.168.122.234 (192.168.122.234)' can't be established. ECDSA key fingerprint is SHA256:GsOxJithwTGuhXUQUSAEsmjI+kjo3Bk43iGxGZJ90UA. ECDSA key fingerprint is MD5:e4:bd:d7:0d:a2:68:df:f5:84:75:11:6f:7f:e6:12:82. Are you sure you want to continue connecting (yes/no)? yes /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys [email protected]'s password:   Number of key(s) added: 1  Now try logging into the machine, with:   "ssh '192.168.122.234'" and check to make sure that only the key(s) you wanted were added.

现在再次尝试相同的简单命令。

$ ansible poftut_servers -a "hostname" 127.0.0.1 | SUCCESS | rc=0 >> poftut1                                                                192.168.122.234 | SUCCESS | rc=0 >> poftut2

现在在poftutu servers组的所有服务器中创建一个目录。

$ ansible poftut_servers -a "mkdir poftut" 127.0.0.1 | SUCCESS | rc=0 >>                     192.168.122.234 | SUCCESS | rc=0 >>

它似乎成功了,但是我们可以通过列出目录来再次检查Ansible。

$ ansible poftut_servers -a "ls"           192.168.122.234 | SUCCESS | rc=0 >> image-build                                                                           original-ks.cfg            poftut                                 127.0.0.1 | SUCCESS | rc=0 >> original-ks.cfg             poftut              

如何安装和管理服务器?信息图表

How to Install Ansible and Manage Servers? Infographic
如何安装和管理服务器?信息图表

相关文章: 如何在Linux中使用Ssh Add添加Ssh密钥?

© 版权声明
THE END
喜欢就支持一下吧,技术咨询可以联系QQ407933975
点赞0
分享