Java Distributed System Deployment Learning (i) ansible experience

Source: Internet
Author: User
Ansible Getting Started experience

What does Ansible do? Why does it need to be used in a distributed system?
If I have a Java service a now, you can deploy only one server when the volume of traffic is small and availability requirements are not high. When service A to launch online, you can log in directly to the server to publish work. But because of the growth in business volume and the need for availability I'm going to do a cluster of service A, if it's three or more, and it's going to be a boring and inefficient thing to do once in a while as before.
Ansible is the solution to this problem, we can deploy Ansible to a server (often referred to as a springboard) dedicated to the management of other production servers, on the springboard through the ansible to operate other servers (such as the Kai-stop service, etc.), and thus achieve the purpose of unified management.
Ansible Chinese Handbook

After the document has been installed Ansible, run the ansible command on the document may have permissions problems, this place I think the document is not very clear, but also very simple, but in the talk about password-free run ansible command to confirm a few points: python2.6 above has been successfully installed Ansible has been successfully installed

The managed machine address is configured to complete, i.e.

$ echo "Managed host address, can have multiple" > ~/ansible_hosts
$ export ansible_hosts=~/ansible_hosts

command to specify username password to run successfully (enter the password of the managed machine correctly)

Ansible all-m ping-u Root--ask-pass

Build the master's public key, ansible in the manual "Ssh-agent", if you do not know, you can look at this blog post ssh-agent usage

ssh-keygen-t RSA [-C "Comment"]

Append the master's public key to the ~/.ssh/authorized_keys file of the controlled machine

The command has been run at this point in the master console.

Ansible all-m Ping [-u root]

Note: If the current user name of the main control machine is the same as the user name of the controlled machine, you can omit the "-u root" in the above command, because the ansible default is linked by the current user name of the host computer. ansible configuration file

The previous section has been able to successfully run the ansible command, but the more annoying thing is that every command will pop up a warning, look at the warning content that the previous section "3" in the manner of configuring the managed host is obsolete, we need to use the new configuration, that is, configuration files.
The order in which ansible read the configuration files since 1.5 is:

-Ansible_config (an environment variable)-
 ansible.cfg (in the current directory)-
 . Ansible.cfg (in the home directory)-
 /etc/ansible/ansible.cfg

/etc/ansible/ansible.cfg is the last fallback configuration. We are here to configure the hosts.
In the Ansible project, the ansible/examples/directory has a sample configuration file, can be directly copy to their/etc/ansible/directory, need to copy two files, namely Ansible.cfg and hosts. Ansible.cfg belong to the general configuration file, hosts are only used to configure the controlled host, that is, inventory files.
Open Ansible.cfg You can see the configuration options, the configuration in the sample file is commented, we only need to release the required configuration options, and then modify the parameters.
It takes only two steps to configure the managed host next
1. Open Inventory annotation

Inventory      =/etc/ansible/hosts

2. Configure the controlled host to the/etc/ansible/hosts.
You can then see that the warning has disappeared by executing the command in the previous section, "6."
This is the configuration of the ansible, and other configurations can be turned on when needed.
For example, "Remote_user" configuration, you can specify the default use of remote login users.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.