Linux automated transport dimensional plane ansible deployment

Source: Internet
Author: User
Tags yum repolist

Objective

The development direction of operations, centralization, automation, standardization, virtualization, distributed.
This article shows a tool for automating the development of operations: Ansible. Ansible has many advantages, only need ssh and Python can be used, do not need the client, powerful, module rich, easy to get started low threshold, based on Python development, easier to do two times development.

Operation Use Environment:

Structural topology diagram

Install software and other preparation work

Can be source installed, or Yum installation

The following is a personal use of the Ansible software, extracted can be used as a Yum source directly
Link: Https://pan.baidu.com/s/1hFly3DnPS01ih60kSh5CIQ Password: 6ge6
Guest Host:

[[email protected] ~]# unzip ansible.zip                             //解压[[email protected] ~]# mkdir -p  /var/ftp/yum/myyum       //主要是创建yum源目录,用ftp共享给其他主机使用,但是前提要有ftp服务,也可以使用http服务共享yum[[email protected] ~]# mv  ansible/\*  /var/ftp/yum/myyum   //把解压的文件拷贝到ftp共享的目录下

Host: Manager10

  [[email protected] ~]# yum-config-manager--add ftp://192.168.1.1/yum/myyum//Add new yum[[email                          Protected] ~]# Yum Clean all//clear Yum cache [[email protected] ~]# yum repolist Source ID Source Name Status 192.168.1.1_yum_myyum_ added from:ftp://192.168.1.1/yum/my Yum/16192.168.1.1_yum_rh7dvd_ added From:ftp://192.168.1.1/yum/rh7dvd/4,620repolist:4,636[[em             Ail protected] ~]# yum-y install ansible//Yum installation ansible[[email protected] ~]# RPM-QC ansible See what the profile has, practical skills, and do not know the profile software can also query the configuration file with this command/etc/ansible/ansible.cfg/etc/ansible/hosts[[email protected] ~]# VI M/etc/hosts//Set native DNS resolution 192.168.1.10 MANAGER10//IP address and domain name are separated by spaces 192.168.1.20 nginx201 92.168.1.30 web30192.168.1.40 web40192.168.1.50 db50192.168.1.60 db60[[email protected] ~]# ssh-keygen-t RSA//Create Key pair, followed by  

Note: You need to close SELinux and FIREWALLD

Configuration file

Configuration file:
/etc/ansible/ansible.cfg
/etc/ansible/hosts
You can modify the configuration file as follows.

[[email protected] ~]# vim /etc/ansible/hosts [web]                //定义web组web30  //组成员,可以使用域名或者ip地址,我把主机名和域名写成一样,方便记忆使用web40[db]                                     //定义db组db50db60[app:children]            //定义父组app,及指定子组webdb[app:vars]        //父组app下所有成员,配置信息,包括登陆用户和密码ansible_ssh_user="root"ansible_ssh_pass="123456"[nginx]  nginx20  ansible_ssh_user="root" ansible_ssh_pass="123456" //定义nginx主 ,配置内容分别表示:组成名名,登陆用户名,登陆密码。 还可以制定登陆端口ansible_ssh_port="22"[[email protected] ~]# vim /etc/ansible/ansible.cfg      //ansible 配置文件host_key_checking = False                 //61行的注释去掉,不读取/root/.ssh/known_hosts 文件,就不用首次登陆输入yes
Use of Ansible

Ansible configuration is complete, do not need to start the service, can be used directly.
The color of the prompt after the command is executed, if no content modification is successful, the color displayed is green, if the content is modified and the successful display color is orange.

[[email protected] ~]# ansible all --list-hosts     hosts (5):    web30    web40    db50    db60    nginx20//查看所有可以配置的主机,或者可以直接查看web,db。出现下面内容,没有报错就是没有问题。

Using modules
Ansible command format
Ansible host Group-m module-a ' commands and parameters '
Viewing module help information using the Ansible-doc module name
Ansible-doc-l List all Modules

[[email protected] ~]# ansible all -m ping     //使用ping模块,查看是否在线web40 | SUCCESS => {                               //出现seccess就是成功了    "changed": false,                                   //没有修改内容    "ping": "pong"                                       //ping和pong是一对}[[email protected] ~]# ansible all  -m authorized_key -a "user=root exclusive=true manage_dir=true key=‘$(< /root/.ssh/id_rsa.pub)‘" -k// 给所有主机部署密钥, -m module 模块    -a agrs 模块的参数    -k   ask需要输入密码

Common modules:
Shell, Copy,yum,service

[[email protected] ~]# ansible web-m shell-a "MKDIR/ROOT/AAAA"//Create WEB30 directory under WEB40 and/ROOT/AAAA under Web Group [[Email&nbs] P;protected] ~]# ansible web-m shell-a "ls/root"//verify creation [[email protected] ~]# ansible web-m shell-a "Ls/ro OT "[[email protected] ~]# ansible web-m copy-a" Src=/root/test.txt dest=/root/"//Copy Local file to remote host, copy folder, src If there is"/" End Copy directory contents, and rsync similar [[[email protected] ~]# ansible web-m yum-a "name=" httpd "state=installed"//install HTTPD, delete is removed [[email protected] ~]# ansible web-m service-a "name=" httpd "enabled=" yes "state=" Started ""//Turn on httpd service, power on start [[     Email protected] ~]# yum-y install NMAP//Installation scanning software nmap[[email protected] ~]# nmap-ss 192.168.1.30,40 Using Nmap half-open scan Nmap Scan report for WEB30 (192.168.1.30) Host is up (0.000090s latency).        Not shown:998 closed ports//default scan first 10,000 ports port State service22/tcp open SSH//ssh Open 80/tcp open http   Web Turn on Mac address:74:52:86:86:02:01 (Unknown)

In fact, to now ansible automated operation and maintenance platform deployment basically completed, followed by ansible flexible use.

Encouragement: I hear and I forget. I see and I remember. I do and I understand!

Linux automated transport dimensional plane ansible deployment

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.