zoukankan      html  css  js  c++  java
  • 使用windos电脑模拟搭建web集群(一)

    资源规划

    1.环境准备

    centos7.2 虚拟机 13个 可以先配置一台,做好基础优化,然后克隆13台分布在 windos宿主机上

    两台windos笔记  都是8g的内存 一台有点内存吃紧。 没有物理服务器玩,屌丝的玩法,有硬件资源的老兄,只能羡慕你了 。

    vmare 虚拟 13台虚拟机  

    eth0 用的是nat模式    eth1用是桥接模式

    2.在监控主机安装ansible 

    直接yum安装

    yum install -y ansible

     如果不想配置密钥对使用ansible

    更改 /etc/ansible/ansible.cfg   配置

    host_key_checking = False  //打开这个注释

    3.根据资源分布表配置ansible的 主机清单

    [root@mage-monitor-01 ~]# tail -15 /etc/ansible/hosts 
    192.168.5.103 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass=123
    192.168.5.110 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass=123
    192.168.5.111 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass=123
    192.168.5.130 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass=123
    192.168.5.131 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass=123
    192.168.5.132 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass=123
    192.168.5.150 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass=123
    192.168.5.151 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass=123
    192.168.5.152 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass=123
    192.168.5.153 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass=123
    192.168.5.161 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass=123
    192.168.5.162 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass=123
    192.168.5.163 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass=123
    192.168.5.200 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass=123
    192.168.5.201 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass=123

    测试一下配置 

    [root@mage-monitor-01 ~]# ansible all -m ping
    192.168.5.130 | SUCCESS => {
        "changed": false, 
        "ping": "pong"
    }
    192.168.5.102 | SUCCESS => {
        "changed": false, 
        "ping": "pong"
    }
    192.168.5.110 | SUCCESS => {
        "changed": false, 
        "ping": "pong"
    }
    192.168.5.101 | SUCCESS => {
        "changed": false, 
        "ping": "pong"
    }
    192.168.5.111 | SUCCESS => {
        "changed": false, 
        "ping": "pong"
    }
    192.168.5.131 | SUCCESS => {
        "changed": false, 
        "ping": "pong"
    }
    192.168.5.161 | SUCCESS => {
        "changed": false, 
        "ping": "pong"
    }
    192.168.5.150 | SUCCESS => {
        "changed": false, 
        "ping": "pong"
    }
    192.168.5.153 | SUCCESS => {
        "changed": false, 
        "ping": "pong"
    }
    192.168.5.151 | SUCCESS => {
        "changed": false, 
        "ping": "pong"
    }
    192.168.5.162 | SUCCESS => {
        "changed": false, 
        "ping": "pong"
    }
    192.168.5.201 | SUCCESS => {
        "changed": false, 
        "ping": "pong"
    }
    192.168.5.200 | SUCCESS => {
        "changed": false, 
        "ping": "pong"
    }

    4.配置DNS  (所有主机)

    先在monitor主机上配一份 然后用ansible的copy模块批量分发

    直接复制excel 也管用

    [root@mage-monitor-01 ~]# cat /etc/hosts
    127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
    ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
    192.168.5.101           LB-nginx-01                     lb01.woniu.com
    192.168.5.102           LB-nginx-02                     lb02.woniu.com
    192.168.5.110           WEB-LNMJ-01                     web01.woniu.com
    192.168.5.111           WEB-LNMJ-02                     web02.woniu.com
    192.168.5.130           STORE-NFS-01                    nfs.woniu.com
    192.168.5.131           STORE-Rsync-01                  rsync.woniu.com
    192.168.5.150           MySQL-master-01                 dbmaster01.woniu.com
    192.168.5.151           MySQL-master-02                 dbmaster02.woniu.com
    192.168.5.153           MySQL-slave-01                  dbslave01.woniu.com
    192.168.5.161           Cache-Mc-01                     cache01.woniu.com
    192.168.5.162           Cache-Mc-02                     cache02.woniu.com
    192.168.5.200           MAGE-monitor-01                 monitor.woniu.com
    192.168.5.201           MAGE-jump-01                    jump.woniu.com

    随机测试一个是否真的管用

    结论:管用

     4.使用ansible    copy模块分发文件

    [root@mage-monitor-01 ~]# ansible all -m copy -a "src=/etc/hosts dest=/etc/ backup=yes"
    192.168.5.111 | SUCCESS => {
        "backup_file": "/etc/hosts.4654.2018-07-04@05:43:06~", 
        "changed": true, 
        "checksum": "221c515383928f333f15de0e7b68a49de47bf1d8", 
        "dest": "/etc/hosts", 
        "gid": 0, 
        "group": "root", 
        "md5sum": "39a534a177bbef2d011ba5c1db448f70", 
        "mode": "0644", 
        "owner": "root", 
        "size": 805, 
        "src": "/root/.ansible/tmp/ansible-tmp-1530697385.22-47924055524411/source", 
        "state": "file", 
        "uid": 0
    }
    192.168.5.130 | SUCCESS => {
        "backup_file": "/etc/hosts.4615.2018-07-04@05:43:07~", 
        "changed": true, 
        "checksum": "221c515383928f333f15de0e7b68a49de47bf1d8", 
        "dest": "/etc/hosts", 
        "gid": 0, 
        "group": "root", 
        "md5sum": "39a534a177bbef2d011ba5c1db448f70", 
        "mode": "0644", 
        "owner": "root", 
        "size": 805, 
        "src": "/root/.ansible/tmp/ansible-tmp-1530697385.3-197755389326565/source", 
        "state": "file", 
        "uid": 0
    }
    192.168.5.110 | SUCCESS => {
        "backup_file": "/etc/hosts.4147.2018-07-04@05:43:07~", 
        "changed": true, 
        "checksum": "221c515383928f333f15de0e7b68a49de47bf1d8", 
        "dest": "/etc/hosts", 
        "gid": 0, 
        "group": "root", 
        "md5sum": "39a534a177bbef2d011ba5c1db448f70", 
        "mode": "0644", 
        "owner": "root", 
        "size": 805, 
        "src": "/root/.ansible/tmp/ansible-tmp-1530697385.16-251244921102860/source", 
        "state": "file", 
        "uid": 0
    }
    192.168.5.101 | SUCCESS => {
        "backup_file": "/etc/hosts.9355.2018-07-04@17:43:07~", 
        "changed": true, 
        "checksum": "221c515383928f333f15de0e7b68a49de47bf1d8", 
        "dest": "/etc/hosts", 
        "gid": 0, 
        "group": "root", 
        "md5sum": "39a534a177bbef2d011ba5c1db448f70", 
        "mode": "0644", 
        "owner": "root", 
        "size": 805, 
        "src": "/root/.ansible/tmp/ansible-tmp-1530697385.08-106777289042025/source", 
        "state": "file", 
        "uid": 0
    }
    192.168.5.102 | SUCCESS => {
        "backup_file": "/etc/hosts.9438.2018-07-04@17:43:07~", 
        "changed": true, 
        "checksum": "221c515383928f333f15de0e7b68a49de47bf1d8", 
        "dest": "/etc/hosts", 
        "gid": 0, 
        "group": "root", 
        "md5sum": "39a534a177bbef2d011ba5c1db448f70", 
        "mode": "0644", 
        "owner": "root", 
        "size": 805, 
        "src": "/root/.ansible/tmp/ansible-tmp-1530697385.09-259223683192222/source", 
        "state": "file", 
        "uid": 0
    }
    192.168.5.131 | SUCCESS => {
        "backup_file": "/etc/hosts.4552.2018-07-04@05:43:08~", 
        "changed": true, 
        "checksum": "221c515383928f333f15de0e7b68a49de47bf1d8", 
        "dest": "/etc/hosts", 
        "gid": 0, 
        "group": "root", 
        "md5sum": "39a534a177bbef2d011ba5c1db448f70", 
        "mode": "0644", 
        "owner": "root", 
        "size": 805, 
        "src": "/root/.ansible/tmp/ansible-tmp-1530697387.2-149000912314060/source", 
        "state": "file", 
        "uid": 0
    }
    192.168.5.161 | SUCCESS => {
        "backup_file": "/etc/hosts.3986.2018-07-04@05:43:08~", 
        "changed": true, 
        "checksum": "221c515383928f333f15de0e7b68a49de47bf1d8", 
        "dest": "/etc/hosts", 
        "gid": 0, 
        "group": "root", 
        "md5sum": "39a534a177bbef2d011ba5c1db448f70", 
        "mode": "0644", 
        "owner": "root", 
        "size": 805, 
        "src": "/root/.ansible/tmp/ansible-tmp-1530697387.46-259570305288606/source", 
        "state": "file", 
        "uid": 0
    }
    192.168.5.150 | SUCCESS => {
        "backup_file": "/etc/hosts.13119.2018-07-04@17:43:08~", 
        "changed": true, 
        "checksum": "221c515383928f333f15de0e7b68a49de47bf1d8", 
        "dest": "/etc/hosts", 
        "gid": 0, 
        "group": "root", 
        "md5sum": "39a534a177bbef2d011ba5c1db448f70", 
        "mode": "0644", 
        "owner": "root", 
        "size": 805, 
        "src": "/root/.ansible/tmp/ansible-tmp-1530697387.21-147931918956879/source", 
        "state": "file", 
        "uid": 0
    }
    192.168.5.153 | SUCCESS => {
        "backup_file": "/etc/hosts.11253.2018-07-04@17:43:08~", 
        "changed": true, 
        "checksum": "221c515383928f333f15de0e7b68a49de47bf1d8", 
        "dest": "/etc/hosts", 
        "gid": 0, 
        "group": "root", 
        "md5sum": "39a534a177bbef2d011ba5c1db448f70", 
        "mode": "0644", 
        "owner": "root", 
        "size": 805, 
        "src": "/root/.ansible/tmp/ansible-tmp-1530697387.46-183080296309039/source", 
        "state": "file", 
        "uid": 0
    }
    192.168.5.151 | SUCCESS => {
        "backup_file": "/etc/hosts.10615.2018-07-04@17:43:08~", 
        "changed": true, 
        "checksum": "221c515383928f333f15de0e7b68a49de47bf1d8", 
        "dest": "/etc/hosts", 
        "gid": 0, 
        "group": "root", 
        "md5sum": "39a534a177bbef2d011ba5c1db448f70", 
        "mode": "0644", 
        "owner": "root", 
        "size": 805, 
        "src": "/root/.ansible/tmp/ansible-tmp-1530697387.34-187115266458800/source", 
        "state": "file", 
        "uid": 0
    }
    192.168.5.162 | SUCCESS => {
        "backup_file": "/etc/hosts.4544.2018-07-04@05:43:09~", 
        "changed": true, 
        "checksum": "221c515383928f333f15de0e7b68a49de47bf1d8", 
        "dest": "/etc/hosts", 
        "gid": 0, 
        "group": "root", 
        "md5sum": "39a534a177bbef2d011ba5c1db448f70", 
        "mode": "0644", 
        "owner": "root", 
        "size": 805, 
        "src": "/root/.ansible/tmp/ansible-tmp-1530697388.5-127274012015792/source", 
        "state": "file", 
        "uid": 0
    }
    192.168.5.200 | SUCCESS => {
        "changed": false, 
        "checksum": "221c515383928f333f15de0e7b68a49de47bf1d8", 
        "gid": 0, 
        "group": "root", 
        "mode": "0644", 
        "owner": "root", 
        "path": "/etc/hosts", 
        "size": 805, 
        "state": "file", 
        "uid": 0
    }
    192.168.5.201 | SUCCESS => {
        "backup_file": "/etc/hosts.4501.2018-07-04@05:43:10~", 
        "changed": true, 
        "checksum": "221c515383928f333f15de0e7b68a49de47bf1d8", 
        "dest": "/etc/hosts", 
        "gid": 0, 
        "group": "root", 
        "md5sum": "39a534a177bbef2d011ba5c1db448f70", 
        "mode": "0644", 
        "owner": "root", 
        "size": 805, 
        "src": "/root/.ansible/tmp/ansible-tmp-1530697389.06-77460370855032/source", 
        "state": "file", 
        "uid": 0
    }

    其他所有主机是黄色的 success 而 200这台主机是绿色的,因为200这台的hosts文件就是我分发的这个

    内容相同不覆盖,其他主机的hosts内容不一致都被覆盖了 所以显示黄色

    我还加了一个参数backup=yes   

    检验一下,任选一台主机 hosts文件已被更改

    并且还备份了 一个原来的

     

    基础环境 就搞完了,下面就是在各台主机上 安装软件配置软件  

  • 相关阅读:
    Mac OS X 10.10(yosemite)更新后,cocoapods出错, 及cocoapods更新至0.34后, 错误情况整理
    如何删除已上线的IAP项
    Automator一键生成所需的iOS 图片icon
    django-simple-captcha 组件使用
    git 本地推送远程仓库报错: error: failed to push some refs to 'https://github.com/yangtuothink/mxonline.git'
    git 提交报错 : The file will have its original line endings in your working directory.
    Django 静态文件相关设置
    Xadmin 组件基础使用以及全局配置
    安装 xadmin 报错: Command "python setup.py egg_info" failed with error code 1 in C:UsersPythonAppDataLocalTemppip-install-1k1byg0pxadmin
    IntegrityError at /admin/users/userprofile/add/ (1452, 'Cannot add or update a child row: a foreign key constraint fails (`mxonline`.`django_admin_log`, CONSTRAINT `django_admin_log_user_id_c564eba6_
  • 原文地址:https://www.cnblogs.com/benjamin77/p/9263601.html
Copyright © 2011-2022 走看看