Ansible安装部署

Ansible安装部署
4台虚拟机 ,全部开启防火墙
server 192.168.8.130
node1 192.168.8.131
node2 192.168.8.132
node3 192.168.8.133
1.server部署

[root@server ~]# cd /etc/yum.repos.d/
[root@server yum.repos.d]# rm -rf *
[root@server yum.repos.d]# dnf -y install centos-release-ansible-29-1-
2.el8.noarch
[root@server yum.repos.d]# ls /etc/yum.repos.d/ |grep ansible
CentOS-SIG-ansible-29.repo
[root@server yum.repos.d]# dnf -y install ansible
[root@servere yum.repos.d]# ls
CentOS-Base.repo CentOS-SIG-ansible-29.repo
//查看ansible版本
[root@server yum.repos.d]# ansible --version
ansible 2.9.27
  config file = /home/student/ansible/ansible.cfg
  configured module search path = ['/home/student/.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, Dec  3 2020, 18:11:24) [GCC 8.4.1 20200928 (Red Hat 8.4.1-1)]

2.配置/etc/hosts

在ansible节点vim /etc/hosts
[root@ansible yum . repos .d]# cd
[root@ansible ~]# vim /etc/hosts
(末行添加)
192.168.8.130 server.example.com server
192.168.8.131 node1.example.com node1
192.168.8.132 node2.example.com node2
192.168.8.133 node3.example.com node3

3.配置ssh的基于密钥认证

在ansible节点执行ssh-keygen命令,一直回车
[root@ansible ~]# ssh-keygen
[student@server ansible]$ ssh-copy-id -i ~/.ssh/id_rsa.pub student@node1
/usr/bin/ssh-copy-id: INFO: Source o
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是ansible安装部署步骤: 1. 准备工作 确保你的操作系统是Linux,并且已经安装了Python 2.6或者Python 2.7版本。如果你使用的是Python 3.x版本,那么需要安装Python 2.x的版本。 2. 安装依赖 在安装ansible之前,需要先安装一些依赖包。在Ubuntu/Debian系统上,可以使用以下命令安装: ``` sudo apt-get update sudo apt-get install software-properties-common sudo apt-add-repository ppa:ansible/ansible sudo apt-get update sudo apt-get install ansible ``` 如果你使用的是CentOS/RHEL系统,可以使用以下命令安装: ``` sudo yum install epel-release sudo yum install ansible ``` 3. 配置主机 在使用ansible之前,需要先配置主机。可以在/etc/ansible/hosts文件中添加主机信息,例如: ``` [web] 192.168.1.100 192.168.1.101 [db] 192.168.1.102 ``` 以上配置定义了两个组,web组包括两个主机,db组包括一个主机。 4. 测试安装 安装完成后,可以使用以下命令测试是否安装成功: ``` ansible --version ``` 如果安装成功,会输出ansible的版本信息。 5. 编写playbook 在使用ansible部署应用程序时,需要编写playbook。playbook是一种YAML格式的文件,可以定义一系列任务和步骤。例如: ``` --- - hosts: web tasks: - name: install apache yum: name=httpd state=latest - name: start apache service: name=httpd state=started ``` 以上playbook定义了在web组中安装最新版本的apache,并且启动apache服务。 6. 运行playbook 完成playbook编写后,可以使用以下命令运行: ``` ansible-playbook playbook.yml ``` 以上命令会执行playbook.yml中定义的任务和步骤。 以上就是ansible安装部署步骤,希望对你有所帮助。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值