ansible搭建
ansible配置步骤
1.创建用户
2.用户提权
3.用户免密
4.cp ansible配置文件
5.配置主机清单
6.修改ansible 用户路径下的配置文件
1.创建用户(都要做)
[root@localhost ~]# useradd hum
[root@localhost ~]# passwd hum
Changing password for user hum.
New password:
BAD PASSWORD: The password is a palindrome
Retype new password:
passwd: all authentication tokens updated successfully.
2.用户提权(都要做)
[root@localhost ~]# cat /etc/sudoers.d/hum
hum ALL=(ALL) NOPASSWD:ALL
3.用户免密
[root@localhost ~]# su hum
[hum@localhost root]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/hum/.ssh/id_rsa):
Created directory '/home/hum/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/hum/.ssh/id_rsa.
Your public key has been saved in /home/hum/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:emW7KWD/2eSSFA1IRpmZMXEBt4g8bkr1A+nBN/vGQWE hum@localhost.localdomain
The key's randomart image is:
+---[RSA 3072]----+
| oOXE. |
| o +**.o |
| X + oo |
| + * +. . |
| . + S +. |
| . oo. *.o |
| ...o..=.. |
| .o.oB |
| o=.o |
+----[SHA256]-----+
[hum@localhost ~]$ ll -a
total 12
drwx------. 4 hum hum 90 Dec 6 09:25 .
drwxr-xr-x. 4 root root 28 Dec 5 16:05 ..
-rw-r--r--. 1 hum hum 18 Dec 4 2020 .bash_logout
-rw-r--r--. 1 hum hum 141 Dec 4 2020 .bash_profile
-rw-r--r--. 1 hum hum 376 Dec 4 2020 .bashrc
drwxr-xr-x. 4 hum hum 39 Nov 19 21:56 .mozilla
drwx------. 2 hum hum 38 Dec 6 09:25 .ssh
[hum@localhost ~]$ ssh-copy-id hum@192.168.10.20
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/hum/.ssh/id_rsa.pub"
The authenticity of host '192.168.10.20 (192.168.10.20)' can't be established.
ECDSA key fingerprint is SHA256:LC3ur7vjJjDH/59gWsQu/kreK4GdZwhlh+M3SJ6/S+s.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
hum@192.168.10.20's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'hum@192.168.10.20'"
and check to make sure that only the key(s) you wanted were added.
验证:
#远程连接不用输密码
[hum@control root]$ ssh hum@node1
Activate the web console with: systemctl enable --now cockpit.socket
This system is not registered to Red Hat Insights. See https://cloud.redhat.com/
To register this system, run: insights-client --register
Last login: Wed Dec 6 09:35:43 2023 from 192.168.10.10
[hum@node1 ~]$ exit
logout
Connection to node1 closed.
#sudo 命令不用输入root密码
[hum@control root]$ ls
ls: cannot open directory '.': Permission denied
[hum@control root]$ sudo ls
anaconda-ks.cfg Music
Desktop Pictures
Documents Public
Downloads Templates
initial-setup-ks.cfg Videos
4.cp ansible配置文件
[hum@control ~]$ cp -r /etc/ansible/ .
[hum@control ~]$ ll
total 0
drwxr-xr-x. 3 hum hum 51 Dec 6 09:41 ansible
5.配置主机清单
[hum@control ansible]$ vim hosts
[hum@control ansible]$ sort hosts
node1
6.修改ansible 用户路径下的配置文件
[hum@control ansible]$ cat ansible.cfg
[defaults]
inventory = /home/hum/ansible/hosts#定义默认使用的主机清单
ask_pass = false#ansible在操作远程主机时,获取远程主机上的用户身份,是否提示密码验证,默认为True。如果使用密钥认证的话,建议将其设置为False
remote_user = hum#用户在操作远程主机时,使用远程主机上的哪个身份,默认是root
log_path = /var/log/ansible.log
[privilege_escalation]
become=True
become_method=sudo
become_user=root
become_ask_pass=False
[ssh_connection]
ssh_args = -C -o ControlMaster=auto -o ControlPersist=60s
host_key_checking = false
实验成功:
[hum@control ansible]$ ansible node1 -m shell -a "whoami"
[WARNING]: log file at /var/log/ansible.log is not writeable and we cannot create it, aborting
node1 | CHANGED | rc=0 >>
root
ansible搭建的更多相关文章
- 用Vagrant和Ansible搭建持续交付平台
这是一个关于Vagrant的学习系列,包含如下文章: Vagrant入门 创建自己的Vagrant box 用Vagrant搭建Jenkins构建环境 用Vagrant和Ansible搭建持续交付平台 ...
- 【Linux运维】Centos7上借助ansible搭建LVS+Keepalived
安装ansible 安装ansible: [root@localhost ~]# /etc/hosts 192.168.19.129 web129.yanglt.com web129 192.168. ...
- ansible搭建mysql主主模式
ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet.cfengine.chef.func.fabric)等优点,实现了批量系统配置.批量程序部署.批量运行命 ...
- Linux实战教学笔记25:自动化运维工具之ansible (一)
第二十五节 ansible之文件的批量分发 标签(空格分隔): Linux实战教学笔记-陈思齐 ---本教学笔记是本人学习和工作生涯中的摘记整理而成,此为初稿(尚有诸多不完善之处),为原创作品,允许转 ...
- ssh密钥分发与ansible
笔者Q:972581034 交流群:605799367.有任何疑问可与笔者或加群交流 当我们公司的服务器达到几十台或几百台或更高的时候,利用批量管理工具管理系统是我们要做的 常用的批量管理工具有ans ...
- 使用ansible安装lnmp
主机互信 生成密钥对,并将公钥发送给其他需要操作的主机 ssh-keygen -t rsa cd /root/.ssh ssh-copy-id -i id_rsa.pub root@192.168.1 ...
- Ansible 利用playbook批量部署Nginx
我这里直接部署的,环境已经搭建好,如果不知道的小伙伴可以看上一遍ansible搭建,都写好了,这里是根据前面环境部署的 192.168.30.21 ansible 192.168.30.25 ...
- 第二十六章 ansible主要模块介绍
一.Ansible模块回顾 1.command模块 [root@m01 ~]# ansible web01 -m command -a 'free -m' 2.shell模块 #支持管道符这种特殊符号 ...
- 从0到1使用Kubernetes系列(三):使用Ansible安装Kubernetes集群
前两期的文章介绍了Kubernetes基本概念和架构,用Kubeadm+Ansible搭建Kubernetes集群所需要的工具及其作用.本篇介绍怎么使用Ansible安装Kubernetes集群. 启 ...
- 【容器云】传统金融企业的 Docker 实践
基于 Docker 的容器云-Padis 目前市面上基于容器云的产品有很多,对于平安而言,则是基于 Docker 的 Padis 平台.所谓 Padis,全称是 PingAn Distribution ...
随机推荐
- 我用这10招,能减少了80%的BUG
前言 对于大部分程序员来说,主要的工作时间是在开发和修复BUG. 有可能修改了一个BUG,会导致几个新BUG的产生,不断循环. 那么,有没有办法能够减少BUG,保证代码质量,提升工作效率? 答案是肯定 ...
- 牛客网-SQL专项训练13
①某软件公司正在升级一套水务管理系统.该系统用于县市级供排水企业.供水厂.排水厂中水务数据的管理工作.系统经重新整合后,开发人员决定不再使用一张备份数据表waterinfo001表,需永久删除.选出符 ...
- POJ4151:电影节
4151:电影节 总时间限制: 1000ms 内存限制: 65536kB 描述 大学生电影节在北大举办! 这天,在北大各地放了多部电影,给定每部电影的放映时间区间,区间重叠的电影不可能同时看(端点 ...
- 全面提升易用性:OpenClusterManagement 0.7 版本发布
简介:千呼万唤始出来,三月末 OpenClusterManagement 社区正式发布了 v0.7 版本.在新的版本有一系列新的功能特性欢迎感兴趣的读者体验探索,同时在这个版本中社区维护者对目前已有 ...
- 一文详解 Nacos 高可用特性
简介: 我今天介绍的 Nacos 高可用,是 Nacos 为了提升系统稳定性而采取的一系列手段.Nacos 的高可用不仅仅存在于服务端,同时也存在于客户端,以及一些与可用性相关的功能特性中,这些点组装 ...
- Apache RocketMQ + Hudi 快速构建 Lakehouse
简介:基于RocketMQ和Hudi零代码构建Lakehouse架构,以及RocketMQ Connector & RocketMQ Stream助力ETL数据分析,为大家提供快速构建Lak ...
- [Gin] 运行模式检测和设置 (mode.go)
// 设置方式 gin.SetMode(gin.ReleaseMode) // 检测方式 if gin.Mode() == gin.DebugMode { } 更多相关信息,建议直接去看源代码. Re ...
- 从右边开始寻找整数的第k位
从右边开始寻找整数的第k位 Implement match_k, which takes in an integer k and returns a function that takes in a ...
- WPF 给类库设置设计时使用的资源字典
在开发 WPF 类库时,由于类库里面没有存在 App.xaml.cs 文件,而在对单个 XAML 进行开发时,设计器将会因为找不到资源文件的存在,而拿不到资源.本文告诉大家简单的方法,给设计器设置仅在 ...
- MSBuild 输出日志可视化工具 MSBuild Structured Log Viewer 简介
感谢 Vatsan Madhavan 小伙伴推荐的 MSBuild 输出日志可视化工具,这个工具可以使用漂亮的 WPF 界面预览 MSBuild 复杂的输出内容 这是一个完全开源的工具,请看 Kiri ...