In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the knowledge of "how to use ansible, an automated operation and maintenance tool under Linux". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1. What kind of situations require batch deployment
1. Installation of operating system
Common collber,red hat satelite (redhat) systems are dedicated.
2. Configuration of operating system
The common one is cfengine,puppet,chef,func. Puppet is the most popular among them.
3. Deployment of batch programs
4. View status information of batch commands
II. Introduction to ansible
The architecture of ansible is roughly as follows
Ansible is a new operation and maintenance tool based on Python, which combines the advantages of many established operation and maintenance tools to achieve batch operating system configuration, batch program deployment, batch operation commands and other functions.
Common working modes of operation and maintenance tools
1. Agent mode: based on ssl. The agent works on the monitored side. Like puppet.
2. Agentless mode: the implementation based on ssh service works on the monitored side. The monitoring end is the client of ssh.
Ansible is idempotent when working in agentless mode. Ansible only needs to tell the expected status of the monitor side on the control side to achieve batch deployment.
Noun interpretation
Idempotency does not repeat the same instructions. For example, the software will not be installed repeatedly.
The expected status only needs to tell the monitored end the expected status.
Ansible is based on module work, and ansible itself does not have the ability to deploy in batches. What really has batch deployment is that ansible, the module that ansible runs, only provides a framework. The architecture includes
The connection plug-in connection plugins is responsible for communicating with the monitored side.
Host Inventory: the host for the specified operation. It is the host for monitoring defined in the configuration file.
Various modules core module command module custom module
Complete functions such as logging messages with the help of plug-ins
PlayBooks: when the script performs multiple tasks. It is not necessary to allow a node to run multiple tasks at a time
III. Basic usage
When managing a cluster, ansible needs to configure the cluster hosts list to facilitate cluster operation.
The code is as follows:
$cat / etc/ansible/hosts
[local]
# configure password to log in. You need to install sshpass on ansible.
192.168.213.135 ansible_ssh_user=root ansible_ssh_pass=root
[zabbix]
# key login
172.17.0.2:49154 ansible_ssh_user=root
172.17.0.4:49155 ansible_ssh_user=root
[vpn]
172.17.0.10
Test whether the connection login is OK
The code is as follows:
$ansible local-m ping
192.168.213.135 | success > > {
"changed": false
"ping": "pong"
}
The common use of ansible is the ansible host-pattern-m module-a command, host-pattern is similar to a simplified regular expression, and the module can be queried through the ansible-doc-l command. Here is how to use some common modules:
Install the software:
The code is as follows:
Ansible local-m apt-a 'name=gcc state=present'
Or
The code is as follows:
Ansible local-m yum-a "name=nmap state=installed"
Execute the command:
The code is as follows:
Ansible local-m shell-a 'uptime'
Copy the file:
The code is as follows:
Ansible local-m copy-a "src=/tmp/server dest=/tmp/server"
File attributes:
The code is as follows:
Ansible local-m file-a "dest=/tmp/server mode=755 owner=root group=root"
*
Playbook
A playbook is a list of one or more "play". The main function of play is to disguise hosts that have been merged into a group as roles defined in advance through task in ansible.
A simple playbook configuration is as follows:
The code is as follows:
-hosts: local
Remote_user: root
Tasks:
-name: echo hi
Shell: echo "hi"
Ansible also supports setting handlers,handlers to be a handler that can be called after the server changes after the execution of tasks, which can be used as follows:
The code is as follows:
# playbook.yml
-
-hosts: specified in local # hosts
Remote_user: root # if you are the same as the current user, you do not need to specify
Tasks:
-name: whoami
Copy: src=~/hosts dest=~/hosts.dest # local copy to remote
Notify: # if a change is sent to the ~ / hosts.dest file after copy execution, execute
-clear copy # call handler
Handlers:
-name: clear copy
Shell:'mv ~ / hosts.dest hosts.del' # pretend to delete
This is the end of the introduction of "how to use ansible, an automated operation and maintenance tool under Linux". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.