IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 系统运维 -> ansible架构部署 -> 正文阅读

[系统运维]ansible架构部署

linux ansible架构

ansible部署

安装yum源 安装ansible

[root@ansible ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@ansible ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@ansible ~]# dnf -y install centos-release-ansible-29-1-2.el8.noarch 
[root@ansible ~]# dnf -y install ansible

查看ansible版本

[root@ansible ~]# ansible --version
ansible 2.9.27
  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, Jan 19 2022, 23:28:49) [GCC 8.5.0 20210514 (Red Hat 8.5.0-7)]

配置/etc/hosts

[root@ansible ~]# vim /etc/hosts
192.168.78.138 ansible.example.com ansible
192.168.78.139 node1.example.com node1
192.168.78.144 node2.example.com node2
192.168.78.145 node3.example.com node3

配置ssh的基于密钥认证

在ansible节点执行ssh-keygen命令,一直回车

[root@ansible ~]# ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:1nUMRZerEhMCkYm+2099aMI31+fM7zn54Qmg0+rhMbg root@ansible.example.com
The key's randomart image is:
+---[RSA 3072]----+
|      .o=   .oo o|
|     . o . . o o |
|    .     . o o .|
|     .   . + . . |
|      . S ..o .  |
|     . .o +.o..  |
|      o. X B.+ oo|
|     . .+ X + o*=|
|       Eo=     =@|
+----[SHA256]-----+

[root@ansible ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@node1
[root@ansible ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@node2
[root@ansible ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@node3

将ansible本地的/etc/hosts文件发送给受控主机

在ansible节点使用如下命令

[root@ansible ~]# for  i  in   node{1..3}
> do scp /etc/hosts root@$i:/etc/hosts
> done
hosts                                                   100%  318    99.3KB/s   00:00    
hosts                                                   100%  318   155.8KB/s   00:00    
hosts                                                   100%  318   169.6KB/s   00:00    

在ansible主机和所有受控主机中创建student用户,并设置密码为123

[root@ansible ~]# useradd student
[root@ansible ~]# echo 123|passwd --stdin student 
Changing password for user student.
passwd: all authentication tokens updated successfully.

使用student用户创建基于密钥认证

在ansible节点执行ssh-keygen命令,一直回车

[student@ansible ~]$ ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/home/student/.ssh/id_rsa): 
Created directory '/home/student/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/student/.ssh/id_rsa.
Your public key has been saved in /home/student/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:0OQgv2G/4Le+gApa/NCTZ80ed8sn959ryWMyk+jNEp8 student@ansible.example.com
The key's randomart image is:
+---[RSA 3072]----+
|    . . .        |
|     o =         |
|      = o        |
|     . =         |
|      o S        |
| . . + + . .     |
|. + = = * . = + .|
|.o + + + + =+Eo*.|
|. . .  .=...+**+*|
+----[SHA256]-----+

[student@ansible ~]$ ssh-copy-id  -i  ~/.ssh/id_rsa.pub  root@node1
[student@ansible ~]$ ssh-copy-id  -i  ~/.ssh/id_rsa.pub  root@node2
[student@ansible ~]$ ssh-copy-id  -i  ~/.ssh/id_rsa.pub  root@node3

[student@ansible ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub student@node1
[student@ansible ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub student@node2
[student@ansible ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub student@node3

使用普通用户student进行测试 ansible all -m ping

[student@ansible ~]$ mkdir ansible
[student@ansible ~]$ cd ansible/
[student@ansible ansible]$ ls
[student@ansible ansible]$ cp /etc/ansible/ansible.cfg .
[student@ansible ansible]$ vim ansible.cfg 
inventory      = /home/student/ansible/inventory
[student@ansible ansible]$ vim inventory
node1
node2
node3

[student@ansible ansible]$ ansible all -m ping
node3 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}
node2 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}
node1 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}
  系统运维 最新文章
配置小型公司网络WLAN基本业务(AC通过三层
如何在交付运维过程中建立风险底线意识,提
快速传输大文件,怎么通过网络传大文件给对
从游戏服务端角度分析移动同步(状态同步)
MySQL使用MyCat实现分库分表
如何用DWDM射频光纤技术实现200公里外的站点
国内顺畅下载k8s.gcr.io的镜像
自动化测试appium
ctfshow ssrf
Linux操作系统学习之实用指令(Centos7/8均
上一篇文章      下一篇文章      查看所有文章
加:2022-10-22 21:56:36  更:2022-10-22 21:59:21 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年9日历 -2024/9/19 9:51:32-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码