• Linux--CE--ansible安装以及配置主控服务器和被控服务器


    ansible配置一台主控服务器,两台被控服务器,搭建:

    (1)准备三台机器:

            配置IP,主机名,/etc/hosts然后去配置免密登录

            server.example.com

            node1.example.com

            node2.example.com

     #:免密登录需要让控制主机登录到其他的被控主机上,所以要在控制主机上生成公私钥,然后发送给被控主机,实现免密登录,还要配置被控主机地址到域名的映射关系:

    1. [root@rhce-128 ~]# ssh-keygen -t rsa
    2. [root@rhce-128 ~]# cd /root/.ssh/
    3. [root@rhce-128 .ssh]# ll
    4. total 12
    5. -rw-------. 1 root root 1679 Aug 2 14:19 id_rsa
    6. -rw-r--r--. 1 root root 395 Aug 2 14:19 id_rsa.pub
    7. [root@rhce-128 .ssh]# vim /etc/hosts
    8. --------------------------------------------------------------
    9. 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
    10. ::1 localhost localhot.localdomain localhost6 localhost6.localdomain6
    11. 192.168.188.128 server.example.com
    12. 192.168.188.130 node1.example.com
    13. 192.168.188.131 node2.example.com
    14. --------------------------------------------------------------

    配置如下所示结果:

    #:在同步配置主机到域名的映射时,可以通过XSHELL一次操作多台虚拟机点击如下所示工具,即可实现:有两种方式:

    第一种:

    第二种:

     #:配置完主机到域名的映射之后将控制服务器的公钥进行转发:免密登录

    1. [root@rhce-128 ~]# ssh-copy-id root@node1.example.com
    2. [root@rhce-128 ~]# ssh-copy-id root@node2.example.com
    3. [root@rhce-128 ~]# ssh root@node1.example.com // 第一次登录需要密码
    4. [root@rhce-128 ~]# ssh root@node2.example.com //与上同理,第一次需要密码

    (2)配置yum源使用Centos-stream.repo安装ansible

    # :安装ansible必须还要安装python,所以检查一下是否有python:没有可以下载一下

     #:下面来安装ansible:

    在CentOS7中,安装需要借助扩展源,进行如下所示配置:

    1. [root@rhce-128 ~]# yum install epel-release -y
    2. [root@rhce-128 ~]# cd /etc/yum.repos.d/
    3. [root@rhce-128 yum.repos.d]# ls
    4. CentOS-Base.repo CentOS-Sources.repo
    5. CentOS-CR.repo CentOS-Vault.repo
    6. CentOS-Debuginfo.repo epel.repo
    7. CentOS-fasttrack.repo epel-testing.repo
    8. CentOS-Media.repo
    9. [root@rhce-128 yum.repos.d]#
    10. [root@rhce-128 ~]# yum install ansible -y
    11. [root@rhce-128 ~]# ansible --version
    12. ansible 2.9.27
    13. config file = /etc/ansible/ansible.cfg
    14. configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
    15. ansible python module location = /usr/lib/python2.7/site-packages/ansible
    16. executable location = /usr/bin/ansible
    17. python version = 2.7.5 (default, Aug 4 2017, 00:39:18) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]
    18. [root@rhce-128 ~]#

    #:如上所示即为安装成功;

    (3)使用ansible --version去验证配置清单:

    1. [root@rhce-128 ~]# ansible --version
    2. ansible 2.9.27
    3. config file = /etc/ansible/ansible.cfg
    4. configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
    5. ansible python module location = /usr/lib/python2.7/site-packages/ansible
    6. executable location = /usr/bin/ansible
    7. python version = 2.7.5 (default, Aug 4 2017, 00:39:18) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]
    8. [root@rhce-128 ~]#

            配置/etc/ansible/hosts

            [node]

            node1.example.com

            node2.example.com

    1. [root@rhce-128 ~]# vim /etc/ansible/hosts
    2. ------------------------------------------------
    3. ## db-[99:101]-node.example.com
    4. [node]
    5. node1.example.com
    6. node2.example.com
    7. ------------------------------------------------

    使用ansible node -m ping去验证

    1. [root@rhce-128 .ssh]# ansible -m ping node
    2. node2.example.com | SUCCESS => {
    3. "ansible_facts": {
    4. "discovered_interpreter_python": "/usr/bin/python"
    5. },
    6. "changed": false,
    7. "ping": "pong"
    8. }
    9. node1.example.com | SUCCESS => {
    10. "ansible_facts": {
    11. "discovered_interpreter_python": "/usr/bin/python"
    12. },
    13. "changed": false,
    14. "ping": "pong"
    15. }
    16. [root@rhce-128 .ssh]#
  • 相关阅读:
    九、GC收集日志
    springmvc中异步转同步
    MySQL8.0与MySQL5.7区别
    今天面了个腾讯拿 38K 出来的大佬,让我见识到了 Java 面试八股文的天花板
    我的个人网站不让接入微信登录,于是我做了这个
    FPGA - 7系列 FPGA内部结构之Clocking -03- 时钟管理模块(CMT)
    HDLbits: Lfsr5
    Blazor前后端框架Known-V1.2.8
    MySQL和Oracle的区别有什么
    App Inventor 2 实现Ascii码转换(Ascii编码与解码)
  • 原文地址:https://blog.csdn.net/AiTTTTTT/article/details/126128866