In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
This article brings you an introduction to the installation and configuration of Ansible and the command line management module. This article not only introduces the concept of Ansible, but also introduces the installation and deployment of Ansible and the command line management model. I hope you can get something through this article.
About Ansible Ansible can manage Linux of Linux,Debian system of Redhat system and Windows host at the same time. The management node only connects to the remote host when executing the script, and there is no special synchronization mechanism, so exceptions such as power outages generally do not affect ansbile.
Ansible is a new automatic operation and maintenance tool. Based on Python development, it integrates the advantages of many operation and maintenance tools (puppet, cfengine, chef, func, fabric), and realizes the functions of batch system configuration, batch program deployment, batch running commands and so on. Ansible works based on modules and does not have the ability to deploy in batches. What really has batch deployment is the module that ansible runs, and Ansible only provides a framework. It mainly includes:
1. Connection plug-in connection plugins: responsible for communicating with the monitored end
2. Host inventory: the host for the specified operation, which is the host for monitoring defined in the configuration file.
3. Various modules core module, command module, custom module
4. Complete the functions such as recording log mail with the help of plug-in
5. Playbook: when the script performs multiple tasks, it is not necessary to let the node run multiple tasks at one time.
Ansible architecture: ssh protocol is used by default to connect other hosts.
Ansible environment installation deployment server role IP address Ansible management side 192.168.142.120Ansible managed side 02192.168.142.122 install Epel source yum install-y epel-release install Ansible service yum install ansible-y view Ansible version ansible-- version install tree service yum install tree-y tree structure display folder tree / etc/ansible//etc/ansible/ ├── ansible.cfg # ansible The main warehouse of the file ├── hosts # ansible Used to store information about remote hosts that need to be managed └── roles switch cd / etc/ansible configuration host list under Ansible working directory vim hosts [webserver] 192.168.142.121 [MySQL] 192.168.142.122 configure key pair verify ssh-keygen-t rsa key pair transfer ssh-copy-id root@192.168.142.121ssh-copy-id root@192.168.142.122Ansible command line module command module
Command format:
Ansible [mainframe] [- m module] [- an args] # list all installed modules Note: press Q to exit ansible-doc-lager yum to list yum module description information and operation actions ansible-doc-s yum to view the other party's system time # specify ip execution dateansible 192.168.142.121-m command-a 'date'# specify category execution dateansible webserver-m command-a' date'# interaction-free execution dateansible mysql- M command-a 'date'# all hosts hosts execute the date command ansible all-m command-a' date'# without the-m module By default, the command module ansible all-a'ls / 'cron module is run in two states (state): present means to add (can be omitted), and absent means to remove # View cron module information ansible-doc-s cron# create scheduled task ansible webserver-m cron-a' minute= "* / 1" job= "/ bin/echo heihei" name= "test cron job" # View scheduled task ansible webserver-a 'crontab-scheduled task # remove scheduled task If the planned task is not named, Name=None can ansible webserver-m cron-a 'name= "test cron job" state=absent' user module user module requests useradd, userdel, usermod three instructions # View user module information ansible-doc-s user# create user test01ansible mysql-m user-a' name= "test01"'# View user information ansible mysql-m command-a 'tail / etc/passwd'# delete user test01ansible mysql-m user-a 'name= "test01" state=absent'group module group module requests groupadd, groupdel Groupmod three instructions # View group module information ansible-doc-s group# create group ansible mysql-m group-a 'name=mysql gid=306 system=yes'ansible mysql-a' tail / etc/group'# create user and add to group ansible mysql-m user-a 'name=test01 uid=306 system=yes group=mysql'# view user information ansible mysql-a' tail / etc/passwd'ansible mysql-a'id test01' copy module # view copy module information ansible-doc-s copy# copy file ansible mysql -m copy-a 'src=/etc/fstab dest=/opt/fstab.back owner=root mode=640'# view the opt directory ansible mysql-a'ls-l / opt'# view the fstab.back file ansible mysql-a'cat / opt/fstab.back'# will hello heihei! Write / opt/fstab.backansible mysql-m copy-a 'content= "hello heihei!" dest=/opt/fstab.back'# then view the fstab.back file ansible mysql-a' cat / opt/fstab.back' file module # View file module information ansible-doc-s file# create user ansible mysql-m user-a 'name=mysql system=yes'# create group ansible mysql-m user-a 'name=mysql system=yes'# modify the file's master group permissions, etc. Ansible mysql-m file-a' Owner=mysql group=mysql mode=644 path=/opt/fstab.back'# set / opt/fstab.link to / opt/fstab.back linked file ansible mysql-m file-a 'path=/opt/fstab.link src=/opt/fstab.back state=link'# delete a file ansible mysql-m file-a "path=/opt/fstab.back state=absent" # create a file ansible mysql-m file-a "path=/opt/test state=touch" ping module # View ping module Information ansible-doc-s ping# tests whether the managed host is online ansible all-m ping- service module # View service module information ansible-doc-s service# installation httpd service yum install-y httpd# view web server httpd running status ansible webserver-a'systemctl status httpd' # start httpd service ansible webserver-m service-a 'enabled=true name=httpd state=started'# check whether systemctl status httpdshell module is enabled # view shell module information ansible- Doc-s shell# create user use non-interactive mode to set password for user ansible mysql-m shell-a 'echo abc123 | passwd-- stdin mysql' script module # View script module information ansible-doc-s script# circular script vim test.shroud echo "hello ansible from script" > / opt/script.txt# gives execute permission chmod + x test.sh# execute script ansible mysql-m script-a' test.sh'# in other hosts View cat / opt/script.txtyum module # View yum module information ansible-doc-s yum#yum install zshansible mysql-m yum-a 'name=zsh'rpm-Q zsh# uninstall zshansible mysql-m yum-a' name=zsh state=absent'rpm-Q zshsetup module # view setup module information ansible-doc-s setup# get facts information of mysql group host ansible mysql-m setup
After reading the above, do you have any further understanding of the automated operation and maintenance tool Ansible? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.