公司网站怎么自己做,91成长人版抖音安装,做微网站必须要有公众号吗,房产cms系统自动化运维
ansible----自动化运维工具
特点#xff1a;
部署简单#xff0c;使用ssh管理
管理端与被管理端不需要启动服务
配置简单、功能强大#xff0c;扩展性强 一、ansible环境搭建
准备四台机器 安装步骤
mo服务器#xff1a; #下载epel [rootmo ~]# yum -y i…自动化运维
ansible----自动化运维工具
特点
部署简单使用ssh管理
管理端与被管理端不需要启动服务
配置简单、功能强大扩展性强 一、ansible环境搭建
准备四台机器 安装步骤
mo服务器 #下载epel [rootmo ~]# yum -y install epel-release.noarch #安装ansible [rootmo ~]# yum -y install ansible #查看ansible版本 [rootmo ~]# ansible --version 进行免密登录 [rootmo ~]# ssh-copy-id -i 192.168.1.25 [rootmo ~]# ssh-copy-id -i 192.168.1.26 编辑配置文件 [rootmo ~]# vim /etc/ansible/hosts [group01] 192.168.1.25 192.168.1.26 [group02] 192.168.1.25 192.168.1.26 192.168.1.27 测试连接性 [rootmo ~]# ansible 192.168.1.25 -m ping 192.168.1.25 | SUCCESS { ansible_facts: { discovered_interpreter_python: /usr/bin/python }, changed: false, ping: pong } 设置别名分组 [rootmo ~]# vim /etc/ansible/hosts [group01] 192.168.1.25 192.168.1.26 other ansible_ssh_host192.168.1.27 ansible_ssh_port22 ansible_ssh_userroot ansible_ssh_pass1 [group02] 192.168.1.25 192.168.1.26 other 再次测试连通性
group01: [rootmo ~]# ansible group01 -m ping 192.168.1.26 | SUCCESS { ansible_facts: { discovered_interpreter_python: /usr/bin/python }, changed: false, ping: pong } 192.168.1.25 | SUCCESS { ansible_facts: { discovered_interpreter_python: /usr/bin/python }, changed: false, ping: pong } other | SUCCESS { ansible_facts: { discovered_interpreter_python: /usr/bin/python }, changed: false, ping: pong } group02: [rootmo ~]# ansible group02 -m ping 192.168.1.26 | SUCCESS { ansible_facts: { discovered_interpreter_python: /usr/bin/python }, changed: false, ping: pong } 192.168.1.25 | SUCCESS { ansible_facts: { discovered_interpreter_python: /usr/bin/python }, changed: false, ping: pong } other | SUCCESS { ansible_facts: { discovered_interpreter_python: /usr/bin/python }, changed: false, ping: pong } other: [rootmo ~]# ansible other -m ping other | SUCCESS { ansible_facts: { discovered_interpreter_python: /usr/bin/python }, changed: false, ping: pong } 更改group02的名字 [rootmo ~]# ansible group02 -m hostname -a namedd 二、file模块
file模块⽤于对⽂件相关的操作(创建, 删除, 软硬链接等)
1.创建目录 [rootmo ~]# ansible group01 -m file -a path/tmp/abc statedirectory 查看 2.创建文件 [rootmo ~]# ansible group02 -m file -a path/tmp/abc/def statetouch 查看 3.递归修改 [rootmo ~]# ansible group02 -m file -a path/tmp/abc recurseyes ownerbin groupdaemon mode1777 查看 [roots0 ~]# ll /tmp/abc/ 总用量 0-rwxrwxrwt 1 bin daemon 0 8月 16 14:08 def 4.修改文件 [rootmo ~]# ansible group02 -m file -a path/tmp/abc stateabsent [rootmo ~]# ansible group02 -m file -a path/tmp/aaaa statetouch ownerbin groupde1777 查看 [roots0 ~]# ls -l /tmp/ 总用量 0-rwxrwxrwt 1 bin daemon 0 8月 16 14:21 aaaa 5.删除文件 [rootmo ~]# ansible group02 -m file -a path/tmp/aaaa stateabsent 6.创建链接文件
创建软连接 [rootmo ~]# ansible group02 -m file -a src/etc/fstab path/tmp/xxx statelink 创建硬链接 [rootmo ~]# ansible group02 -m file -a src/etc/fstab path/tmp/xxx2 statehard 查看 [roots0 ~]# ll /tmp/ lrwxrwxrwx 1 root root 10 8月 16 14:31 xxx - /etc/fstab -rw-r--r--. 2 root root 502 5月 25 18:31 xxx2 7.获取文件统计信息 [rootmo ~]# ansible group02 -m stat -a path/etc/fstab 三、copy模块 copy模块⽤于对⽂件的远程拷⻉操作如把本地的⽂件拷⻉到远程 的机器上)
使⽤content参数直接往远程⽂件⾥写内容会覆盖原内容
使⽤force参数控制是否强制覆盖
使⽤backup参数控制是否备份⽂件
copy模块拷⻉时要注意拷⻉⽬录后⾯是否带/符号
没有/把表示拷贝目录有/表示拷贝目录下的文件 用于远程拷贝文件
给虚拟机传mysql包 [rootmo ~]# rz -E rz waiting to receive. 查看 [rootmo ~]# ls anaconda-ks.cfg mysql-5.7.44-linux-glibc2.12-x86_64.tar.gz 改名 [rootmo ~]# mv mysql-5.7.44-linux-glibc2.12-x86_64.tar.gz mysql57.tar.gz 复制
将当前目录下的mysql57.tar.gz文件复制到group02组内所有机器的用户主目录中 [rootmo ~]# ansible group02 -m copy -a src./mysql57.tar.gz dest~ 查看 [roots0 ~]# ls -lh 总用量 663M -rw-------. 1 root root 1.4K 5月 25 16:47 anaconda-ks.cfg -rw-r--r-- 1 root root 663M 8月 16 15:07 mysql57.tar.gz [roots1 ~]# ls -lh 总用量 663M -rw-------. 1 root root 1.4K 5月 25 16:47 anaconda-ks.cfg -rw-r--r-- 1 root root 663M 8月 16 15:07 mysql57.tar.gz [roots2 ~]# ls -lh 总用量 663M -rw-------. 1 root root 1.4K 5月 25 16:47 anaconda-ks.cfg -rw-r--r-- 1 root root 663M 8月 16 15:07 mysql57.tar.gz 写入内容 [rootmo ~]# ansible group02 -m copy -a contentwo shi dd chao ji wu di yu zhou bao long zhan shen dest~/tst 查看 [roots0 ~]# ls anaconda-ks.cfg mysql57.tar.gz tst [roots0 ~]# cat tst wo shi dd chao ji wu di yu zhou bao long zhan shen 四、user模块
user模块⽤于管理⽤户账号和⽤户属性。 创建aaa⽤户,默认为普通⽤户,创建家⽬录 ansible group1 -m user -a ‘nameaaa statepresent’ 创建bbb系统⽤户,并且登录shell环境为/sbin/nologin ansible group1 -m user -a ‘namebbb statepresent systemyes shell/sbin/nologin’ 创建ccc⽤户, 使⽤uid参数指定uid, 使⽤password参数传密码 echo 123456 | openssl passwd -1 -stdin $1$DpcyhW2G$Kb/y1f.lyLI4MpRlHU9oq0 下⼀句命令注意⼀下格式密码要⽤双引号引起来单引号的话验证时会密码不正确 ansible group1 -m user -a nameccc uid2000 statepresent password$1$DpcyhW2G$Kb/y1f.lyLI4MpRlHU9oq0 创建⼀个普通⽤户叫hadoop,并产⽣空密码密钥对 ansible group1 -m user -a namehadoop generate_ssh_keyyes 删除aaa⽤户,但家⽬录默认没有删除 ansible group1 -m user -a nameaaa stateabsent 删除bbb⽤户,使⽤removeyes参数让其删除⽤户的同时也删除家⽬录 ansible group1 -m user -a namebbb stateabsent removeyes 五、group模块
group模块⽤于管理⽤户组和⽤户组属性。
创建组 ansible group1 -m group -a namegroupa gid3000 statepresent 删除组如果有⽤户的gid为此组则删除不了) ansible group1 -m group -a namegroupa stateabsent 六、cron模块
cron模块⽤于管理周期性时间任务。 创建⼀个cron任务,不指定user的话,默认就是root
如果minute,hour,day,month,week不指定的话默认都为* ansible group1 -m cron -a nametest cron1 userroot jobtouch /tmp/111 minute*/2 删除cron任务 ansible group1 -m cron -a nametest cron1 stateabsent 七、yum模块
yum模块⽤于使⽤yum命令来实现软件包的安装与卸载。 使⽤yum安装⼀个软件前提:group1的机器上的yum配置都已经OK ansible group1 -m yum -a namevsftpd statepresent 使⽤yum安装httpd,httpd-devel软件,statelatest表示安装最新版本 ansible group1 -m yum -a namehttpd,httpd-devel statelatest 使⽤yum卸载httpd,httpd-devel软件 ansible group1 -m yum -a namehttpd,httpddevel stateabsent 八、service模块
service模块⽤于控制服务的启动,关闭,开机⾃启动等。 启动vsftpd服务并设为开机⾃动启动 ansible group1 -m service -a namevsftpd statestarted enabledon 关闭vsftpd服务并设为开机不⾃动启动 ansible group1 -m service -a namevsftpd statestopped enabledfalse 九、其他模块 hostname模块
hostname模块⽤于修改主机名注意: 它不能修改/etc/hosts⽂件) stat模块
stat模块类似linux的stat命令⽤于获取⽂件的状态信息。 template模块
template模块⾸先使⽤变量渲染jinja2模板⽂件成普通⽂件,然后再复制过去.⽽copy模块不⽀持.(jinja2是⼀个基于python的模板引擎)
template模块不能拷⻉⽬录 fetch模块
fetch模块与copy模块类似但作⽤相反。⽤于把远程机器的⽂件拷⻉到本地。
注意: fetch模块不能从远程拷⻉⽬录到本地 yum_repository模块
yum_repository模块⽤于配置yum仓库。 增加⼀个/etc/yum.repos.d/local.repo配置⽂件 ansible group1 -m yum_repository -a namelocal descriptionlocalyum baseurlfile:///mnt/ enabledyes gpgcheckno 注意此模块只帮助配置yum仓库,但如果仓库⾥没有软件包安装⼀ 样会失败。所以可以⼿动去挂载光驱到/mnt⽬录
# mount /dev/cdrom /mnt
删除/etc/yum.repos.d/local.repo配置⽂件 ansible group1 -m yum_repository -a namelocal stateabsent script模块
script模块⽤于在远程机器上执⾏本地脚本。 在master上准备⼀个脚本 vim /tmp/1.sh #!/bin/bash mkdir /tmp/haha touch /tmp/haha/{1..10} 在group1的远程机器⾥都执⾏master上的/tmp/1.sh脚本
(此脚本 不⽤给执⾏权限) ansible group1 -m script -a /tmp/1.sh command与shell模块
两个模块都是⽤于执⾏linux命令的,这对于命令熟悉的⼯程师来说⽤起来⾮常high。
shell模块与command模块差不多
(command模块不能执⾏⼀些类似$HOME,,等符号但shell可以)
注意: shell模块并不是百分之百任何命令都可以,⽐如vim或ll别名就不可以。