Public cloud / private cloud host initialization

Scene Description

Now many companies are self-built private cloud, public cloud environment or rent public cloud vendors, EPC, the business side at the time of application to get the resources, the default is a virtual operating system is already installed, not all environments , installed operating systems are customizable, usually the default standard version, a lot of packages and batch management, monitoring tool is not installed, only the business side to get the resources to carry out their own installation.

And at this time, batch installation in many host management, monitoring tools work, back to the hands of the business side of this scene, and no cloud environment, on the same line of business from the beginning of the purchase of the server, the only difference is if it is your own batch install the operating system, you can pre-install these packages, and cloud environments, only themselves to install.

During this time, just to deal with the wave of such an environment, within the enterprise private cloud, applied for 140 virtual machines, before developing a formal approach, the need for these virtual machines at treatment, monitoring and management of software installation. In order to reduce the workload a little, most times way is up for processing each login, choose here is the batch to be processed, can reduce the workload is reduced a little bit, just to complete it.

Resources

  • 140 sets of customized version of CentOS 7, and indeed the community edition and minimize installation is not much difference,
  • Addresses are continuous from 192.168.1.3-192.168.1.142,
  • Password are the same for all hosts, 123456, and this is one of the best, if not the same password for every host, it can really be a life it was. Nor is it can not be done, just do it more trouble

Program planning

Environment based on the above, the main idea of ​​implementation steps are as follows:

  • I managed to find a host, preferably a head or a tail, a first proposal is, as Paul missing hereinafter also need to expand the host range and addresses
  • With a host of management, all other hosts, do the ssh password-free login, ssh-key
  • Mass execution ssh remote login, execute commands, mainly include DNS resolution added, yum repository modify zabbix and salt-minion installation,

Specific implementation process

SSH-KEY-free login password

Since the IP addresses of all hosts is continuous, and the password is the same, where you can choose to use the automatic answering expect the resulting ssh-key, transmitted directly to the host that needs to be managed. Of course, also need to write two scripts, one expect of a script, a shell script is cyclic. details as follows:

  1. SSH-KEY generated

    Default ssh-keygen -t dsa key pair is generated, all the way default

  2. expect auto-answer file

    Autoresponder script writing, mainly during the SSH-COPY-ID when automatic answer

    set IP [lindex $argv 0]
    spawn ssh-copy-id -i /root/.ssh/id_dsa.pub root@$IP
    expect {
            "*yes/no" {send "yes\r";exp_continue}
            "password:"     {send "123456\r"}
    }
    interact
    exit
    

    In this script automated response, you need a variable IP, because all host user name and password are the same, so the password is not set to a variable, otherwise, the password is set to a variable, and then auto-answer.

  3. Loop shell script

    Write a shell script execution cycle, especially simple

    #/bin/bash
    for ip in {3..142}
     do
            IP="192.168.1.$ip"
            echo "$IP"
            expect expect.exp $IP
    done 
    

    This is to execute the cycle

  4. Execute the script, you can complete copies of public keys of all hosts, then in management and on, there will be a known_hosts file, which is to receive the host list all of the public key.

YUM warehouse configuration and DNS

Here's DNS configuration, mainly write about parsing zabbix_server and salt, and writes directly to the / etc / hosts file to, or use of the above script, but the script to expect a change on it. details as follows:

#/bin/bash
for ip in {4..134}
 do
        IP="10.253.11.$ip"
        echo "$IP"
        ssh root@$IP " echo '192.168.1.3 salt'>>/etc/hosts && mkdir /etc/yum.repos.d/bak && mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak"
done 

Add a hosts file, then the system will natively comes repo files, delete all, or move to a different directory.

yum repository configuration, as are within the network environment, only a yum repository to build their own, using the system image, mount to the system, the system image copied to a directory, then install a httpd service, use the local http service as a yum repository source, all other hosts, are the basis for the software installed with the yum repository.

[base]
name=base
#baseurl=file:///mnt
baseurl=http://192.168.1.3:8123/iso
enable=1
gpgcheck=0

Then base.repo document, distributed to all hosts, here or in the form of cycle to execute the command.

#/bin/bash
for ip in {4..134}
 do
        IP="10.253.11.$ip"
        echo "$IP"
        scp /etc/yum.repos.d/base.repo root@$IP:/etc/yum.repos.d/ 
done 

After copy the past, all the other hosts, you can use the yum source

zabbix-agent and the installation of salt-minion

Use of recycled script, batch installation zabbix-agent and salt-minion, first and foremost must first download and install these two software packages, find a machine can access the Internet, use download a way that will install the rpm package downloaded, and then yum source copy to the warehouse. Then createrepo way to update the local yum repository. Here there is a problem after the update finished, the site's directory permissions will change, other hosts can not access the resources, so brutal use chmod 777 -Rf. After updating permissions, restart the httpd service. The use of scripting, agent directly installed two just fine.

#/bin/bash
for ip in {4..134}
 do
        IP="10.253.11.$ip"
        echo "$IP"
        ssh root@$IP 'yum install zabbix-agent salt-minion -y && echo $IP >/etc/salt/minion_id && systemctl start salt-minion' 
done 

After starting, you can use salt-master to control all of the machine.

Guess you like

Origin www.cnblogs.com/bobo137950263/p/11358356.html