打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Ansible-安装配置

 

主机规划

主机名称操作系统版本内网IP外网IP(模拟)安装软件
ansi-managerCentOS7.5172.16.1.18010.0.0.180ansible
ansi-haproxy01CentOS7.5172.16.1.18110.0.0.181 
ansi-haproxy02CentOS7.5172.16.1.18210.0.0.182 
ansi-web01CentOS7.5172.16.1.18310.0.0.183 
ansi-web02CentOS7.5172.16.1.18410.0.0.184 
ansi-web03CentOS7.5172.16.1.18510.0.0.185 

在实际使用中并不需要对ansible配置进行修改,或者说只有需要的时候才修改ansible配置。

 

添加用户账号

说明:

1、 运维人员使用的登录账号;

2、 所有的业务都放在 /app/ 下「yun用户的家目录」,避免业务数据乱放;

3、 该用户也被 ansible 使用,因为几乎所有的生产环境都是禁止 root 远程登录的(因此该 yun 用户也进行了 sudo 提权)。

1 # 使用一个专门的用户,避免直接使用root用户2 # 添加用户、指定家目录并指定用户密码3 # sudo提权4 # 让其它普通用户可以进入该目录查看信息5 useradd -u 1050 -d /app yun && echo '123456' | /usr/bin/passwd --stdin yun6 echo "yun  ALL=(ALL)       NOPASSWD: ALL" >>  /etc/sudoers7 chmod 755 /app/

Ansible 部署流程

添加 epel 源「如果没有的话」

添加阿里云 epel 源

https://opsx.alibaba.com/mirror

Ansible 安装与版本信息查看

 1 [root@ansi-manager ~]# yum install -y ansible   2 [root@ansi-manager ~]# whereis ansible  # ansible 位置信息 3 ansible: /usr/bin/ansible /etc/ansible /usr/share/ansible /usr/share/man/man1/ansible.1.gz 4 [root@ansi-manager ~]# ansible --version  # 版本信息查看 5 ansible 2.8.1  # ansible 版本 6   config file = /etc/ansible/ansible.cfg  # 使用的配置文件 7   configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']  # 模块查找路径 8   ansible python module location = /usr/lib/python2.7/site-packages/ansible  # ansible Python 模块位置,使用 Python 2.7 9   executable location = /bin/ansible  # ansible 执行文件的位置10   python version = 2.7.5 (default, Apr 11 2018, 07:36:10) [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)]  # Python 版本信息11 [yun@ansi-manager ~]$ ll /usr/bin/ansible  /bin/ansible  # ansible 命令位置12 lrwxrwxrwx 1 root root 20 Jun 24 14:14 /bin/ansible -> /usr/bin/ansible-2.713 lrwxrwxrwx 1 root root 20 Jun 24 14:14 /usr/bin/ansible -> /usr/bin/ansible-2.7

Ansible 配置文件讲解

Ansible配置文件查找顺序

ansible 将从多个地方查找配置文件,顺序如下:

1、从环境变量 ANSIBLE_CONFIG 中查找,如果该环境变量有值的话;

2、当前目录的 ansible.cfg 文件;「每个项目都可以有一个该配置文件,这样可以更好的管理项目,移植时也更方便。」

3、当前用户家目录的 .ansible.cfg 文件;

4、/etc/ansible/ansible.cfg 文件。

可以使用 ansible –version 命令查看使用的配置文件。

在 /etc/ansible/ansible.cfg 配置文件中有该说明

Ansible 部分配置文件讲解

实际生产中可以无需做任何修改。

 1 [yun@ansi-manager ansible]$ pwd 2 /etc/ansible 3 [yun@ansi-manager ansible]$ vim ansible.cfg 4 #inventory      = /etc/ansible/hosts      # 受控端主机资源清单 5 #library        = /usr/share/my_modules/  # 所需依赖库路径 6 #remote_tmp     = ~/.ansible/tmp          # 远端机器,临时文件存放位置 7 #local_tmp      = ~/.ansible/tmp          # 本机临时文件存放位置 8 #forks          = 5                       # 默认并发数 9 #poll_interval  = 15                      # 默认轮询时间间隔(单位秒)10 #sudo_user      = root                    # 默认sudo后的用户11 #ask_sudo_pass = True                     # 使用sudo,是否需要输入密码12 #ask_pass      = True                     # 是否需要输入密码13 #transport      = smart                   # 传输方式14 #remote_port    = 22                      # 默认远程主机的端口号15 #module_lang    = C                       # 模块和系统之间通信的语言16 #module_set_locale = False17 ………………18 # uncomment this to disable SSH key host checking  取消注释以禁用SSH key主机检查 【默认是注释掉的,要检查主机指纹】19 host_key_checking = False                # 解开注释,即跳过检查主机指纹 【只有 root 用户执行时才有该取消指纹检测的权限】20 ………………21 # logging is off by default unless this path is defined22 # if so defined, consider logrotate23 #log_path = /var/log/ansible.log          # 开启ansible日志24 ………………25 [privilege_escalation]                    # 普通用户提权配置「使用地方:普通用户远程提权使用」26 #become=True27 #become_method=sudo28 #become_user=root29 #become_ask_pass=False

上述的 [privilege_escalation] 配置,可在 ansible -h 中查看如何使用。如下:

 1 [yun@ansi-manager ~]$ ansible -h  2 ……………… 3   Privilege Escalation Options:  # 权限提升选项 4     control how and which user you become as on target hosts 5  6     -b, --become        run operations with become (does not imply password 7                         prompting) 8     --become-method=BECOME_METHOD 9                         privilege escalation method to use (default=sudo), use10                         `ansible-doc -t become -l` to list valid choices.11     --become-user=BECOME_USER12                         run operations as this user (default=root)13     -K, --ask-become-pass14                         ask for privilege escalation password15 ………………

 


———END———
如果觉得不错就关注下呗(-^O^-) !

 

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Debian安装及输入法等简单配置
Ubuntu12.04系统下嵌入式linux环境的搭建
转贴:Ubuntu进入root权限命令
nagios监控postgresql
Ubuntu Server系统安全(入侵检测 后门检测 数据完整性检测)原文:http://www.2cto.com/Article/201311/257968.html
linux权限之su和sudo的差别
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服