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 ...
随机推荐
- 调用App Store Connect Api
对iOS的证书.描述文件.账号.设备等管理,之前都去苹果开发者中心操作,官网上操作也比较繁杂,想搞一些自动化之类的,更是麻烦,有时候官网都打不开-- 其实苹果还提供里一套API接口,创建证书.创建账号 ...
- k8s集群部署1.28.2版本(无坑)
Kubernetes-1.28.2 集群介绍及搭建 一.Kubernetes 概述 1.什么是Kubernetes? K8S 的全称为 Kubernetes.用于自动部署.扩展和管理"容器化 ...
- 牛客网-SQL专项练习2
①从学生信息表(student)中提取姓名(name)列值为NULL的记录,SQL语句为: 解析:注意不是只查name值,而是查name值为空的所有信息 SQL语句为: SELECT * FROM s ...
- 云原生消息队列Pulsar浅析
简介: 云原生消息队列Pulsar浅析 一.前言 Pulsar是一个多租户,高性能的服务间消息解决方案.最初由Yahoo开发,现在由Apache Software Foundation负责.Pulsa ...
- 小白也能懂的 Nacos 服务模型介绍
简介: 理解了 Nacos 的服务模型,也有利于我们了解 Nacos 背后的工作原理,从而确保我们正确地使用 Nacos. 作者:岛风 前言 按照目前市场上的主流使用场景,Nacos 被分成了两块功能 ...
- dotnet 6 创建进程 Process.Start 时设置 UseShellExecute 在 Windows 下对性能的影响
本文将告诉大家,在 dotnet 6 或 dotnet 7 版本里,启动新的进程时,在 StartInfo 设置 UseShellExecute 为 true 和 false 时,对性能的影响 在 d ...
- WPF 简单聊聊如何使用 DrawGlyphRun 绘制文本
在 WPF 里面,提供的使用底层的方法绘制文本是通过 DrawGlyphRun 的方式,此方法适合用在需要对文本进行精细控制的定制化控件上.此方法特别底层而让调用方法比较复杂,本文告诉大家一些简单的使 ...
- Istio微服务入门---通过istio部署微服务实现灰度发布(15)
一.Istio简介 1.1 Istio介绍 官方文档:https://istio.io/docs/concepts/what-is-istio/ 中文官方文档:https://istio.io/zh/ ...
- gprMax电磁波正演模拟方法
文章首发于:https://blog.zhaoxuan.site/archives/37.html: 第一时间获取最新文章请关注博客个人站:https://blog.zhaoxuan.site. 目录 ...
- ruby和glang的md5和sha1加密对比
ruby和glang的md5和sha1加密对比 package main import ( "crypto/md5" "crypto/sha1" "f ...