Ansible 实战案例--ansible 2.8.0 环境部署


ansible环境准备

角色IP
ansible-server192.168.5.3
node01192.168.5.4
node02192.168.5.5
node03192.168.5.6
node04192.168.5.7
  • 配置主机hosts问文件
    注 :批量操作所有主机
[root@ansible-server ~]# vim /etc/hosts +
192.168.5.3 ansible-server
192.168.5.4 node01
192.168.5.5 node02
192.168.5.6 node03
192.168.5.7 node04
  • 配置免密钥互信
[root@ansible-server ~]# su - student
[student@ansible-server ~]$ ssh-keygen -f ~/.ssh/id_rsa -P '' -q
[student@ansible-server ~]$ ssh-copy-id student@node01
[student@ansible-server ~]$ ssh-copy-id student@node02
[student@ansible-server ~]$ ssh-copy-id student@node03
[student@ansible-server ~]$ ssh-copy-id student@node04

ansible 安装

注:此次环境使用centos-8.2操作系统

#安装ansible 2.8.0
[root@ansible-server ~]# dnf install ansible-2.8.0-1.el8ae.noarch.rpm  sshpass-1.06-3.el8ae.x86_64.rpm -y
#查看anisble软件是否安装成功
[root@ansible-server ~]# yum list installed platform-python
Installed Packages
platform-python.x86_64                               3.6.8-23.el8                               @anaconda
#查看ansible安装版本
[root@ansible-server ~]# ansible --version
ansible 2.8.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.6/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.6.8 (default, Apr 16 2020, 01:36:27) [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)]

编辑ansible配置文件

dnf 方式安装ansible,默认会生成ansible配置文件
本次案例,我们自定义编辑配置文件,完成ansible的基本配置

  • 编辑ansible配置文件
#编辑ansible配置文件
[root@ansible-server ~]# su - student 
[student@ansible-server ~]$ mkdir ansible/
[student@ansible-server ~]$ cd ansible/
[student@ansible-server ansible]$ vim ansible.cfg
[defaults]
inventory = ./inventory
remote_user = user
ask_pass = false
roles_path = roles

[privilege_escalation]
become=True
become_method=sudo
become_user=root
become_ask_pass=False


#编辑清单文件
[student@ansible-server ansible]$ vim inventory
[dev]
node01
[test]
node02
[prod]
node03
node04
[balancers]
node02
[webserver:children]
prod


#创建校色文件目录
[student@ansible-server ansible]$ mkdir roles/

测试连通性

[student@ansible-server ansible]$ ansible all -m ping -o
node02 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": false,"ping": "pong"}
node04 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": false,"ping": "pong"}
node03 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": false,"ping": "pong"}
node01 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": false,"ping": "pong"}

[student@ansible-server ansible]$ ansible localhost -m ping -o
localhost | SUCCESS => {"changed": false,"ping": "pong"}

总结

提示:ansible 管理端支持三种方式连接被管理端:

  • local
  • ssh
  • zeromq
    注:ansible 默认有localhost 连接,这种连接不包含在all和ungrouped组中,采用local方式连接

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用Ansible部署Fluent Bit的步骤: 1. 安装Ansible部署Fluent Bit之前,需要在管理节点上安装Ansible。可以使用以下命令在Debian/Ubuntu系统上安装Ansible: ``` $ sudo apt update $ sudo apt install ansible ``` 在CentOS/RHEL系统上安装Ansible: ``` $ sudo yum install epel-release $ sudo yum install ansible ``` 2. 创建Ansible playbook 创建一个Ansible playbook来安装和配置Fluent Bit。在此过程中,您需要指定Fluent Bit的配置文件和输入源。 以下是一个示例playbook: ``` - hosts: fluentbit_servers become: yes tasks: - name: Install Fluent Bit apt: name: fluent-bit state: present - name: Configure Fluent Bit copy: src: /path/to/fluent-bit.conf dest: /etc/fluent-bit/fluent-bit.conf - name: Start Fluent Bit service: name: fluent-bit state: started ``` 在此playbook中,'fluentbit_servers'是您要在其上部署Fluent Bit的服务器的名称或IP地址。还要将'/path/to/fluent-bit.conf'替换为Fluent Bit配置文件的实际路径。 3. 运行Ansible playbook 运行上述playbook以安装和配置Fluent Bit: ``` $ ansible-playbook fluentbit.yml ``` 在运行此命令之前,请确保已将Fluent Bit配置文件复制到正确的位置,并且在服务器上已安装了Fluent Bit软件包。 4. 验证Fluent Bit 一旦Fluent Bit已安装和配置,您可以使用以下命令检查它是否正在运行: ``` $ sudo systemctl status fluent-bit ``` 此命令应显示Fluent Bit服务的状态信息。如果一切正常,您应该看到“active (running)”状态。 此外,您还可以使用以下命令检查Fluent Bit是否正在接收和处理数据: ``` $ sudo tail -f /var/log/syslog | grep fluent-bit ``` 此命令应显示Fluent Bit正在处理的日志消息。 这就是使用Ansible部署Fluent Bit的步骤。请记住,在实际环境中,您需要根据自己的需求和环境进行自定义配置。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值