1、主从复制及主主复制的实现
1-1 主从复制
1-1-1 主节点配置
修改配置文件,配置二进制日志路径
#创建二进制日志保存路径
[root@mysql1 data]# mkdir -p mysql/logbin
[root@mysql1 data]# chown -R mysql.mysql mysql
#添加server-id log-bin
[root@mysql1 data]# vim /etc/my.cnf
[mysqld]
server-id=169
log-bin=/data/mysql/logbin/mysql-bin
validate_password.policy=LOW
#参数validate_password.policy用来降低密码复杂度要求
#配置完毕后重启服务生效
[root@mysql1 data]# systemctl restart mysqld
备份数据库到 all.sql
#备份数据库 mysql8 用 --source-data 替代 --master-data,否则后续备机上恢复会报错
#mysqldump -A -F --master-data=1 --single-transaction -p > all.sql
[root@mysql1 data]# mysqldump -A -F --source-data=1 --single-transaction -p > all.sql
Enter password:
[root@mysql1 data]# ll all.sql -h
-rw-r--r-- 1 root root 1.2M Mar 23 01:15 all.sq
[root@mysql1 data]# scp all.sql 10.0.0.163:/data
创建复制授权的账户
#创建备份账户
01:21:19(root@localhost) [hellodb]> create user repluser@'10.0.0.%' identified by '1234qwer';
01:23:02(root@localhost) [hellodb]> grant replication slave on *.* to repluser@'10.0.0.%';
1-1-2 从节点配置
修改配置文件,配置二进制日志路径
[root@mysql3 data]# vim /etc/my.cnf
[mysqld]
server-id=163
log-bin=/data/mysql/logbin/mysql-bin
read-only
#启用read-only,避免非授权用户修改
#创建二进制日志目录
[root@mysql3 data]# mkdir -p mysql/logbin
[root@mysql3 data]# chown -R mysql.mysql mysql
#重启mysql服务
[root@mysql3 data]# systemctl restart mysqld
在刚才备份的文件里面添加复制线程,指定复制主节点信息,二进制位置不变
CHANGE MASTER TO
MASTER_HOST='10.0.0.169',
MASTER_USER='repluser',
MASTER_PASSWORD='1234qwer',
MASTER_PORT=3306,
MASTER_LOG_FILE='mysql-bin.000003',
MASTER_LOG_POS=157;
登录数据库导入数据库备份脚本 all.sql
#登录数据库后临时关闭log-bin,导入备份后再开启
09:48:14(root@localhost) [hellodb]> set sql_log_bin=0;
09:49:36(root@localhost) [hellodb]> source /data/all.sql;
09:50:23(root@localhost) [hellodb]> set sql_log_bin=1;
确认主从复制状态
#查看主从复制状态,启动主从复制
10:31:43(root@localhost) [hellodb]> show slave status\G;
10:31:47(root@localhost) [hellodb]> start slave;
10:31:57(root@localhost) [hellodb]> show slave status\G;
#注意,mysql8主从命令有变化 'SHOW SLAVE STATUS' is deprecated
#and will be removed in a future release. Please use SHOW REPLICA STATUS instead
1-2 主主复制实现关键步骤
1-2-1 主节点1配置
修改配置文件,配置二进制日志路径
#创建二进制日志保存路径
[root@mysql1 data]# mkdir -p mysql/logbin
[root@mysql1 data]# chown -R mysql.mysql mysql
#添加server-id log-bin
[root@mysql1 data]# vim /etc/my.cnf
[mysqld]
server-id=169
log-bin=/data/mysql/logbin/mysql-bin
#validate_password.policy=LOW #降低密码复杂度要求,本例中不需要
#重启服务配置生效
[root@mysql1 data]# systemctl restart mysqld
配置复制授权账户
#配置复制权限账户
17:45:04(root@localhost) [(none)]> create user repluser@'10.0.0.%' identified by 'Replication@123';
17:45:20(root@localhost) [(none)]> grant replication slave on *.* to repluser@'10.0.0.%';
记录二进制位置信息
#记录数据库二进制位置
18:36:03(root@localhost) [(none)]> show master logs;
+------------------+-----------+-----------+
| Log_name | File_size | Encrypted |
+------------------+-----------+-----------+
| mysql-bin.000001 | 733 | No |
| mysql-bin.000002 | 454 | No |
+------------------+-----------+-----------+
2 rows in set (0.00 sec)
#或者执行命令 show master status 同样可查看;
转移到主节点2配置复制信息,完成后继续后续配置步骤
MySQL8默认加密传输,获取公钥信息,避免加密传输报错
#方法一:获取公钥先,本例推荐使用该方式
mysql -u repluser -pReplication@123 -h10.0.0.161 -P3306 --get-server-public-key
#方法二:修改加密模块
#alter user repluser@'10.0.0.%' identified with mysql_native_password by '1234qwer';
配置复制线程信息,必须要先查看主节点2的二进制日志位置
CHANGE MASTER TO
MASTER_HOST='10.0.0.161',
MASTER_USER='repluser',
MASTER_PASSWORD='Replication@123',
MASTER_PORT=3306,
MASTER_LOG_FILE='mysql-bin.000003',
MASTER_LOG_POS=157;
启用复制线程并查看状态
#查看主从复制状态,启动主从复制
18:52:44(root@localhost) [(none)]> show slave status\G;
18:53:17(root@localhost) [(none)]> start slave;
18:53:21(root@localhost) [(none)]> show slave status\G;
1-2-2 主节点2配置
修改配置文件,配置二进制日志路径
#创建二进制日志保存路径
[root@mysql2 data]# mkdir -p mysql/logbin
[root@mysql2 data]# chown -R mysql.mysql mysql
#添加server-id log-bin
[root@mysql2 data]# vim /etc/my.cnf
[mysqld]
server-id=161
log-bin=/data/mysql/logbin/mysql-bin
#validate_password.policy=LOW #降低密码复杂度要求,本例中不需要
#重启服务配置生效
[root@mysql2 data]# systemctl restart mysqld
MySQL8默认加密传输,获取公钥信息,避免加密传输报错
#方法一:获取公钥先,本例推荐使用该方式
mysql -u repluser -pReplication@123 -h10.0.0.169 -P3306 --get-server-public-key
重新登录数据库,配置复制授权账户(后续提供给主节点1使用)
#配置复制权限账户
17:45:04(root@localhost) [(none)]> create user repluser@'10.0.0.%' identified by 'Replication@123';
17:45:20(root@localhost) [(none)]> grant replication slave on *.* to repluser@'10.0.0.%';
配置复制线程信息,必须要先查看主节点1的二进制日志位置
CHANGE MASTER TO
MASTER_HOST='10.0.0.169',
MASTER_USER='repluser',
MASTER_PASSWORD='Replication@123',
MASTER_PORT=3306,
MASTER_LOG_FILE='mysql-bin.000001',
MASTER_LOG_POS=713;
启用复制线程并查看状态
#查看主从复制状态,启动主从复制
18:52:44(root@localhost) [(none)]> show slave status\G;
18:53:17(root@localhost) [hellodb]> start slave;
18:53:21(root@localhost) [(none)]> show slave status\G;
记录二进制位置信息,提供给主节点1配置使用
#记录数据库二进制位置
18:55:41(root@localhost) [(none)]> show master logs;
+------------------+-----------+-----------+
| Log_name | File_size | Encrypted |
+------------------+-----------+-----------+
| mysql-bin.000001 | 180 | No |
| mysql-bin.000002 | 180 | No |
| mysql-bin.000003 | 157 | No |
+------------------+-----------+-----------+
3 rows in set (0.00 sec)
#或者执行命令 show master status 同样可查看;
2、xtrabackup实现全量+增量+binlog恢复库
2.1 安装percona-xtrabackup工具
#安装percona-xtrabackup
[root@mysql1 data]# yum localinstall -y percona-xtrabackup-80-8.0.27-19.1.el7.x86_64.rpm
[root@mysql1 data]# rpm -ql percona-xtrabackup-80-8.0.27-19.1.el7
/usr/bin/xbcloud
/usr/bin/xbcloud_osenv
/usr/bin/xbcrypt
/usr/bin/xbstream
/usr/bin/xtrabackup
/usr/include/kmip.h
/usr/include/kmippp.h
/usr/lib/libkmip.a
/usr/lib/libkmippp.a
/usr/lib/private/libprotobuf-lite.so.3.11.4
/usr/lib/private/libprotobuf.so.3.11.4
/usr/lib64/xtrabackup/plugin/component_keyring_file.so
/usr/lib64/xtrabackup/plugin/component_keyring_kmip.so
/usr/lib64/xtrabackup/plugin/keyring_file.so
/usr/lib64/xtrabackup/plugin/keyring_vault.so
/usr/share/doc/percona-xtrabackup-80-8.0.27
/usr/share/doc/percona-xtrabackup-80-8.0.27/LICENSE
/usr/share/man/man1/xbcrypt.1.gz
/usr/share/man/man1/xbstream.1.gz
/usr/share/man/man1/xtrabackup.1.gz
[root@mysql1 data]#
2.2 数据备份及恢复
2.2.1 完全备份
#完全备份
[root@mysql1 data]# xtrabackup -uroot -pPASSWORD --backup --target-dir=/data/backup/base
#查看信息
[root@mysql1 data]# cat backup/base/xtrabackup_info
uuid = 6ca00d4a-b281-11ec-9f78-000c29e0fefc
name =
tool_name = xtrabackup
tool_command = -uroot -pPASSWORD --backup --target-dir=/data/backup/base
tool_version = 8.0.27-19
ibbackup_version = 8.0.27-19
server_version = 8.0.23
start_time = 2022-04-02 20:35:45
end_time = 2022-04-02 20:35:48
lock_time = 1
binlog_pos = filename 'binlog.000003', position '156'
innodb_from_lsn = 0
innodb_to_lsn = 18071643
partial = N
incremental = N
format = file
compressed = N
encrypted = N
2.2.2 增量备份
#第一次修改数据
#第一次增量备份
[root@mysql1 data]# xtrabackup -uroot -pPASSWORD --backup --target-dir=/data/backup/inc1 --incremental-basedir=/data/backup/base
#查看信息
[root@mysql1 data]# cat backup/inc1/xtrabackup_info
uuid = 73eb4b73-b2a2-11ec-9f78-000c29e0fefc
name =
tool_name = xtrabackup
tool_command = -uroot -pPASSWORD --backup --target-dir=/data/backup/inc1 --incremental-basedir=/data/backup/base
tool_version = 8.0.27-19
ibbackup_version = 8.0.27-19
server_version = 8.0.23
start_time = 2022-04-03 00:32:11
end_time = 2022-04-03 00:32:14
lock_time = 1
binlog_pos = filename 'binlog.000004', position '156'
innodb_from_lsn = 18071643
innodb_to_lsn = 18212018
partial = N
incremental = Y
format = file
compressed = N
encrypted = N
#第二次修改
#第二次增量备份
xtrabackup -uroot -pPASSWORD --backup --target-dir=/data/backup/inc2 --incremental-basedir=/data/backup/inc1
[root@mysql1 data]# xtrabackup -uroot -pPASSWORD --backup --target-dir=/data/backup/inc2 --incremental-basedir=/data/backup/inc1
[root@mysql1 data]# cat backup/inc2/xtrabackup_info
uuid = 25449125-b2a3-11ec-9f78-000c29e0fefc
name =
tool_name = xtrabackup
tool_command = -uroot -pPASSWORD --backup --target-dir=/data/backup/inc2 --incremental-basedir=/data/backup/inc1
tool_version = 8.0.27-19
ibbackup_version = 8.0.27-19
server_version = 8.0.23
start_time = 2022-04-03 00:37:09
end_time = 2022-04-03 00:37:11
lock_time = 0
binlog_pos = filename 'binlog.000005', position '156'
innodb_from_lsn = 18212018
innodb_to_lsn = 18212554
partial = N
incremental = Y
format = file
compressed = N
encrypted = N
2.2.3 数据还原
#复制备份数据到目标主机
[root@mysql1 data]# scp -r /data/backup/* 10.0.0.171:/data/backup/
#备份过程生成三个备份目录 /data/backup/{base,inc1,inc2}
[root@mysql2 backup]# ls
base inc1 inc2
#停止目标主机MySQL服务,清空数据目录
[root@mysql2 backup]# systemctl stop mysqld
[root@mysql2 backup]# rm -rf /var/lib/mysql/*
#预准备完成备份,此选项--apply-log-only 阻止回滚未完成的事务
[root@mysql2 backup]# xtrabackup --prepare --apply-log-only --target-dir=/data/backup/base
#合并第1次增量备份到完全备份
[root@mysql2 backup]# xtrabackup --prepare --apply-log-only --target-dir=/data/backup/base --incremental-dir=/data/backup/inc1
#合并第2次增量备份到完全备份:最后一次还原不需要加选项--apply-log-only
[root@mysql2 backup]# xtrabackup --prepare --target-dir=/data/backup/base --incremental-dir=/data/backup/inc2
#复制到数据库目录,注意数据库目录必须为空,MySQL服务不能启动
[root@mysql2 backup]# xtrabackup --copy-back --target-dir=/data/backup/base
#还原数据目录属性
#chown -R mysql:mysql /var/lib/mysql
[root@mysql2 backup]# chown -R mysql.mysql /var/lib/mysql
#启动服务
[root@mysql2 backup]# systemctl start mysqld
3、MyCAT实现MySQL读写分离
3-1 主机环境规划
系统:centos7
Client:10.0.0.161
mycat-agent:10.0.0.162
mysql-master:10.0.0.169
mysql-slave:10.0.0.163
3-2 主从配置
注意:此例子主从复制简要实现满足测试mycat即可,不做严格备份要求
#添加server-id,同时出于测试便捷需要,降低密码策略要求
[root@mysql-m1 data]# vim /etc/my.cnf
[mysqld]
server-id=169
validate_password.policy=low
validate_password.length=6
#重启服务配置生效
[root@mysql-m1 data]# systemctl restart mysqld
#创建备份账户
00:48:48(root@localhost) [(none)]> create user repluser@'10.0.0.%' identified by '1234qwer';
00:48:58(root@localhost) [(none)]> grant replication slave on *.* to repluser@'10.0.0.%';
00:52:34(root@localhost) [(none)]> alter user repluser@'10.0.0.%' identified with mysql_native_password by '1234qwer'
01:00:20(root@localhost) [(none)]> FLUSH PRIVILEGES;
01:00:35(root@localhost) [(none)]> show master logs;
#从服务器实现
[root@mysql-s1 data]# vim /etc/my.cnf
[mysqld]
server-id=163
validate_password.policy=low
validate_password.length=6
#重启mysql服务
[root@mysql-s1 data]# systemctl restart mysqld
#登录从数据库开启复制
01:04:59(root@localhost) [(none)]> CHANGE MASTER TO
-> MASTER_HOST='10.0.0.169',
-> MASTER_USER='repluser',
-> MASTER_PASSWORD='1234qwer',
-> MASTER_PORT=3306,
-> MASTER_LOG_FILE='mysql-bin.000003',
-> MASTER_LOG_POS=1337;
Query OK, 0 rows affected, 9 warnings (0.01 sec)
#查看复制状态
01:05:40(root@localhost) [(none)]> START SLAVE;
01:05:50(root@localhost) [(none)]> SHOW SLAVE STATUS\G
3-3 Mycat代理安装并启动
#安装Java
[root@mycat-agent ~]# yum install java
[root@mycat-agent ~]# java -version
openjdk version "1.8.0_322"
OpenJDK Runtime Environment (build 1.8.0_322-b06)
OpenJDK 64-Bit Server VM (build 25.322-b06, mixed mode)
#下载mycat并安装
[root@mycat-agent ~]# wget http://dl.mycat.org.cn/1.6.7.6/20220221174943/Mycat-server-1.6.7.6-release-20220221174943-linux.tar.gz
[root@mycat-agent ~]# mkdir /apps
[root@mycat-agent ~]# tar -zxvf Mycat-server-1.6.7.6-release-20220221174943-linux.tar.gz -C /apps/
[root@mycat-agent ~]# ls /apps/
mycat
#配置环境变量
[root@mycat-agent ~]# echo 'PATH=$PATH:/apps/mycat/bin' > /etc/profile.d/mycat.sh
[root@mycat-agent ~]# source /etc/profile.d/mycat.sh
[root@mycat-agent ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/apps/mycat/bin
#启动mycat
[root@mycat-agent apps]# file mycat/bin/mycat
mycat/bin/mycat: POSIX shell script, ASCII text executable
[root@mycat-agent apps]# mycat start
Starting Mycat-server...
#能查看到8066端口即可说明mycat已正常启动
[root@mycat-agent apps]# ss -ntlp
#查看日志
[root@mycat-agent apps]# cat /apps/mycat/logs/wrapper.log
STATUS | wrapper | 2022/04/05 11:38:01 | --> Wrapper Started as Daemon
STATUS | wrapper | 2022/04/05 11:38:02 | Launching a JVM...
INFO | jvm 1 | 2022/04/05 11:38:02 | Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.org
INFO | jvm 1 | 2022/04/05 11:38:02 | Copyright 1999-2006 Tanuki Software, Inc. All Rights Reserved.
INFO | jvm 1 | 2022/04/05 11:38:02 |
INFO | jvm 1 | 2022/04/05 11:38:03 | MyCAT Server startup successfully. see logs in logs/mycat.log
#客户端登录测试,初始默认密码123456,默认端口8066
[root@client-test ~]# mysql -h10.0.0.162 -P8066 -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.29-mycat-1.6.7.6-release-20220221174943 MyCat Server (OpenCloudDB)
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+----------+
| DATABASE |
+----------+
| TESTDB |
+----------+
3-4 Mycat代理服务器上修改server.xml文件,配置Mycat连接信息
#修改端口
#原文
<!--
<property name="serverPort">8066</property>
<property name="managerPort">9066</property>
<property name="idleTimeout">300000</property>
<property name="authTimeout">15000</property>
<property name="bindIp">0.0.0.0</property>
<property name="dataNodeIdleCheckPeriod">300000</property> 5 * 60 * 1000L; //连接空闲检查
<property name="frontWriteQueueSize">4096</property> <property name="processors">32</property> -->
#修改后 注意去掉连接空闲检查的文字描述
<property name="serverPort">3306</property>
<property name="managerPort">9066</property>
<property name="idleTimeout">300000</property>
<property name="authTimeout">15000</property>
<property name="bindIp">0.0.0.0</property>
<property name="dataNodeIdleCheckPeriod">300000</property>
<property name="frontWriteQueueSize">4096</property> <property name="processors">32</property>
#可以修改默认密码,本次测试保持不变
#原文
<user name="root" defaultAccount="true">
<property name="password">123456</property>
<property name="schemas">TESTDB</property>
<property name="defaultSchema">TESTDB</property>
3-5 修改schema.xml实现读写分离配置
#将原文件备份,修改后的最终内容如下
[root@mycat-agent conf]# cat schema.xml
<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
<schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100" randomDataNode="dn1" dataNode="dn1">
</schema>
<dataNode name="dn1" dataHost="localhost1" database="hellodb" />
<dataHost name="localhost1" maxCon="1000" minCon="10" balance="1"
writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
<heartbeat>select user()</heartbeat>
<!-- can have multi write hosts -->
<writeHost host="hostM1" url="10.0.0.169:3306" user="root" password="123456">
<readHost host="hostS1" url="10.0.0.163:3306" user="root" password="123456" />
</writeHost>
<!-- <writeHost host="hostM2" url="localhost:3316" user="root" password="123456"/> -->
</dataHost>
</mycat:schema>
#修改完毕后重启服务生效
[root@mycat-agent conf]# mycat restart
[root@mycat-agent conf]# cat /apps/mycat/logs/wrapper.log
...
INFO | jvm 1 | 2022/04/05 12:41:54 | MyCAT Server startup successfully. see logs in logs/mycat.log
3-6 创建用户用于对Mycat授权使用
12:45:09(root@localhost) [(none)]> create user root@'10.0.0.%' identified by '123456';
#补充步骤,必须修改认证方式为mysql_native_password,然后重启mysql服务,否则mycat报错
22:25:35(root@localhost) [(none)]> alter user root@'10.0.0.%' identified with mysql_native_password by '123456';
12:45:47(root@localhost) [(none)]> GRANT ALL ON *.* TO root@'10.0.0.%';
12:47:40(root@localhost) [(none)]> flush privileges;
#在从服务器上查看同步信息
#show grants for root@'10.0.0.%';
12:48:50(root@localhost) [(none)]> select user, host from mysql.user;
+------------------+-----------+
| user | host |
+------------------+-----------+
| repluser | 10.0.0.% |
| root | 10.0.0.% |
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+------------------+-----------+
6 rows in set (0.00 sec)
3-7 连接Mycat代理服务器测试
#连接Mycat服务器
[root@client-test ~]# mysql -h10.0.0.162 -p123456 TESTDB
22:56:19(root@10.0.0.162) [TESTDB]> show tables;
+-------------------+
| Tables_in_hellodb |
+-------------------+
| classes |
| coc |
| courses |
| scores |
| students |
| teachers |
| toc |
+-------------------+
7 rows in set (0.00 sec)
01:39:45(root@10.0.0.162) [TESTDB]> INSERT INTO coc values(null, @@server_id, 4);
Query OK, 1 row affected (0.06 sec)
#验证写功能在169
01:40:57(root@10.0.0.162) [TESTDB]> select * from coc;
+----+---------+----------+
| ID | ClassID | CourseID |
+----+---------+----------+
| 1 | 1 | 2 |
| 2 | 1 | 5 |
| 3 | 2 | 2 |
| 4 | 2 | 6 |
| 5 | 3 | 1 |
| 6 | 3 | 7 |
| 7 | 4 | 5 |
| 8 | 4 | 2 |
| 9 | 5 | 1 |
| 10 | 5 | 9 |
| 11 | 6 | 3 |
| 12 | 6 | 4 |
| 13 | 7 | 4 |
| 14 | 7 | 3 |
| 15 | 169 | 4 |
+----+---------+----------+
15 rows in set (0.00 sec)
#验证查询功能在163
01:41:12(root@10.0.0.162) [TESTDB]> select @@server_id;
+-------------+
| @@server_id |
+-------------+
| 163 |
+-------------+
1 row in set (0.00 sec)
4、ansible常用模块介绍
模块帮助文档查询
ansible-doc 模块名称
Archive模块
功能:打包压缩保存在被管理节点
注意:压缩的源数据和目标压缩包都是在远端节点
常用命令选项:
path # 节点上被压缩文件的绝对路径
dest # 目标压缩包。
format # 压缩包格式,选项包括 bz2, gz, tar, xz, zip,默认gz
范例:
[root@ansible-160 data]# ansible 10.0.0.161 -m archive -a 'path=/usr/src/local/nginx-1.21.6 dest=/root/nginx.tar.bz2 format=bz2 owner=thomas mode=755'
#查看压缩包内容
[root@web-161 ~]# tar -tjvf nginx.tar.bz2
Command 模块
功能:在远程节点主机执行命令,此为默认模块,可省略 -m 选项
注意:
1、该模块命令不通过shell来处理,所以比如$HOME和操作如"<",">","|",";","&" 不会生效,如需使用需要通过shell模块实现这些功能。
2、此模块不具有幂等性。
常用命令选项:
chdir # 在执行命令之前,先切换到该目录
creates # 一个文件名,当这个文件存在,则该命令不执行,可以用来做判断。
removes # 一个文件名,这个文件不存在,则该命令不执行
范例:
#chdir效果
[root@ansible-160 ~]# ansible 10.0.0.161 -m command -a 'chdir=/root ls -l'
10.0.0.161 | CHANGED | rc=0 >>
total 4
-rw-------. 1 root root 1593 Dec 20 05:08 anaconda-ks.cfg
[root@ansible-160 ~]#
#creates 因为ccc.txt文件存在,所以不执行命令
[root@ansible-160 ~]# ansible 10.0.0.161 -m command -a 'creates=/data/ccc.txt ls -l /etc'
10.0.0.161 | SUCCESS | rc=0 >>
skipped, since /data/ccc.txt exists
#removes 因为ccc.txt存在,所以执行命令
[root@ansible-160 ~]# ansible 10.0.0.161 -m command -a 'removes=/data/ccc.txt ls -l /data'
10.0.0.161 | CHANGED | rc=0 >>
total 0
-rw-r--r--. 1 root root 0 Apr 10 00:39 ccc.txt
Copy 模块
功能:从ansible服务器主控端复制文件到远程主机
注意:src如果文件夹后面没有路径的符号,则是连同文件夹本身一同复制过去到指定路径下
常用命令选项:
src # 本地文件路径
dest # 目标节点路径
mode # 复制过去后文件的所属权限
范例:
#复制/data/ccc.txt到目标节点/data/ccc.txt,启用backup选项,修改文件属主和组,设置权限为755
[root@ansible-160 data]# ansible 10.0.0.161 -m copy -a 'src=/data/ccc.txt dest=/data/ccc.txt backup=yes owner=thomas group=thomas mode=755'
10.0.0.161 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"backup_file": "/data/ccc.txt.1351.2022-04-10@17:38:58~",
"changed": true,
"checksum": "a8fdc205a9f19cc1c7507a60c4f01b13d11d7fd0",
"dest": "/data/ccc.txt",
"gid": 1000,
"group": "thomas",
"md5sum": "ba1f2511fc30423bdbb183fe33f3dd0f",
"mode": "0755",
"owner": "thomas",
"size": 4,
"src": "/root/.ansible/tmp/ansible-tmp-1649583538.28-3120-75754727148612/source",
"state": "file",
"uid": 1000
}
[root@ansible-160 data]# ansible 10.0.0.161 -m shell -a 'ls -l /data/'
10.0.0.161 | CHANGED | rc=0 >>
total 4
-rwxr-xr-x 1 thomas thomas 4 Apr 10 17:38 ccc.txt
-rw-r--r-- 1 root root 0 Apr 10 17:38 ccc.txt.1351.2022-04-10@17:38:58~
Cron 模块
功能::管理计划任务
支持时间:minute,hour,day,month,weekday
范例:
#创建计划任务 间隔5分钟同步下时间
ansible websrvs -m cron -a "minute=*/5 job='/usr/sbin/ntpdate 10.10.10.10 &>/dev/null' name=Synctime"
#禁用计划任务
ansible websrvs -m cron -a "minute=*/5 job='/usr/sbin/ntpdate 10.10.10.10 &>/dev/null' name=Synctime disabled=yes"
#启用计划任务
ansible websrvs -m cron -a "minute=*/5 job='/usr/sbin/ntpdate 10.10.10.10 &>/dev/null' name=Synctime disabled=no"
#删除任务
ansible websrvs -m cron -a "name=Synctime state=absent"
Fetch 模块
功能::从远程主机提取文件至ansible的主控端,与copy相反
注意:仅支持文件,不支持目录
常用命令选项:
src # 远程节点文件路径
dest # 本地目标节点路径,注意,假设dest=/backup,则实际保存路径为 /backup/远程节点主机名/远程节点文件路径
validate_checksum # 核实提取文件到ansible主控端后与远端节点原始文件的摘要一致性,默认yes
范例:
[root@ansible-160 data]# ansible appsrvs -m fetch -a 'src=/var/log/messages dest=/data/backup validate_checksum=no'
10.0.0.160 | CHANGED => {
"changed": true,
"checksum": "2323b82d3ad5df8105aed7277ace5e0d3d013c24",
"dest": "/data/backup/10.0.0.160/var/log/messages",
"md5sum": "9a18d3d4d08fcc02bab10543f94a9815",
"remote_checksum": "5631361c72a952b76459eb7d278905f0097a8081",
"remote_md5sum": null
}
10.0.0.169 | CHANGED => {
"changed": true,
"checksum": "b9402be94b60821b6883379ba01a4f60abc95f3f",
"dest": "/data/backup/10.0.0.169/var/log/messages",
"md5sum": "1d9d259306c25226adaba549fc1d8a20",
"remote_checksum": "b9402be94b60821b6883379ba01a4f60abc95f3f",
"remote_md5sum": null
}
10.0.0.161 | CHANGED => {
"changed": true,
"checksum": "a7d26546b837d612a7c79b1b0aed3bc0937f6ea9",
"dest": "/data/backup/10.0.0.161/var/log/messages",
"md5sum": "b1f61219f0842ea448e98475e62d8d35",
"remote_checksum": "a7d26546b837d612a7c79b1b0aed3bc0937f6ea9",
"remote_md5sum": null
}
[root@ansible-160 data]# tree backup/
backup/
├── 10.0.0.160
│ └── var
│ └── log
│ └── messages
├── 10.0.0.161
│ └── var
│ └── log
│ └── messages
└── 10.0.0.169
└── var
└── log
└── messages
9 directories, 3 files
File 模块
功能:设置文件和属性,创建软链接等
注意:Windows节点使用win_file模块管理
范例:
#创建目录
[root@ansible-160 data]# ansible 10.0.0.161 -m file -a 'path=/data/dir1 state=directory'
#创建文件
[root@ansible-160 data]# ansible 10.0.0.161 -m file -a 'path=/data/dir1/file1 state=touch'
#创建软链接 /data/file1-link 指向 /data/dir1/file1
[root@ansible-160 data]# ansible 10.0.0.161 -m file -a 'src=/data/dir1/file1 path=/data/file1-link state=link'
#删除文件
[root@ansible-160 data]# ansible 10.0.0.161 -m file -a 'path=/data/file1-link state=absent'
#修改目录属性,目录下面的文件属性没改变
[root@ansible-160 data]# ansible 10.0.0.161 -m file -a 'path=/data/dir1 state=directory owner=thomas group=thomas'
#修改目录及其子目录的属性
[root@ansible-160 data]# ansible 10.0.0.161 -m file -a 'path=/data/dir1 state=directory owner=thomas group=thomas recurse=yes'
Get_url 模块
功能:用于将文件从http、https或ftp下载到远程管理节点主机上
注意:远程管理节点必须具备访问该资源的权限
常用命令选项:
url # 下载文件的URL,支持HTTP,HTTPS,FTP
dest # 下载到目标路径(绝对路径),如果目标是一个目录,就用服务器上面文件的名称,如果目标设置了名称就用目标设置的名称
owner # 指定所属主
group # 指定所属组
checksum # 对目标文件在下载后计算摘要,以确保其完整性
示例:checksum="sha256:D98291AC[...]B6DC7B97" 或者 checksum="sha256:http://example.com/path/sha256sum.txt"
url_username # 用于HTTP基本认证的用户名、
url_password # 用于HTTP基本认证的密码
范例:
[root@ansible-160 data]# ansible 10.0.0.161 -m get_url -a 'url=http://nginx.org/download/nginx-1.21.6.tar.gz dest=/data/'
10.0.0.161 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"checksum_dest": null,
"checksum_src": "3e6d39a714f6716861286630a5f9df3044668d5a",
"dest": "/data/nginx-1.21.6.tar.gz",
"elapsed": 1,
"gid": 0,
"group": "root",
"md5sum": "e7a9b0388d8812ba6063de4e7e7969be",
"mode": "0644",
"msg": "OK (1073364 bytes)",
"owner": "root",
"size": 1073364,
"src": "/root/.ansible/tmp/ansible-tmp-1649585949.15-3430-169000840838239/tmprsvx8dr9",
"state": "file",
"status_code": 200,
"uid": 0,
"url": "http://nginx.org/download/nginx-1.21.6.tar.gz"
}
[root@ansible-160 data]# ansible 10.0.0.161 -m shell -a 'ls -l /data/nginx*'
10.0.0.161 | CHANGED | rc=0 >>
-rw-r--r-- 1 root root 1073364 Apr 10 18:19 /data/nginx-1.21.6.tar.gz
Hostname模块
功能:管理主机名
范例:
#修改主机10.0.0.162主机名
[root@ansible-160 data]# ansible 10.0.0.162 -m hostname -a 'name=dbs-162'
10.0.0.162 | CHANGED => {
"ansible_facts": {
"ansible_domain": "",
"ansible_fqdn": "dbs-162",
"ansible_hostname": "dbs-162",
"ansible_nodename": "dbs-162",
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"name": "dbs-162"
}
Ping 模块
功能:连通性测试,判断ansible是否能通过ssh来管理远程主机节点
注意:这个不是常见的ICMP ping,成功结果是返回 “pong”,Windows主机使用 win_ping 模块,网络测试使用 net_ping
范例:
[root@ansible-160 ~]# ansible 10.0.0.161 -m ping
10.0.0.161 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
Reboot 模块
功能:重启服务器
范例:
#重启web服务器组机器
ansible websrvs -m reboot
Replace 模块
功能:类似于sed命令,基于正则进行匹配和替换,推荐使用
范例:
[root@centos-160 ~]# ansible 10.0.0.161 -m replace -a 'path=/data/passwd regexp="^root(.*)" replace="test\1"'
10.0.0.161 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"msg": "1 replacements made"
}
Scripts 模块
功能:在远程节点主机上运行ansible本地服务器上的脚本(无需执行权限)
注意:此模块不具有幂等性
范例:
[root@ansible-160 data]# ansible 10.0.0.161 -m script -a '/data/hostname.sh'
10.0.0.161 | CHANGED => {
"changed": true,
"rc": 0,
"stderr": "Shared connection to 10.0.0.161 closed.\r\n",
"stderr_lines": [
"Shared connection to 10.0.0.161 closed."
],
"stdout": "10.0.0.161 \r\n",
"stdout_lines": [
"10.0.0.161 "
]
}
Shell 模块
功能:在远程节点主机执行命令,与command类似。
注意:该模块等同于通过shell来执行命令,支持管道符等操作,如"<",">","|",";","&"。
常用命令选项:
creates # 一个文件名,当这个文件存在,则该命令不执行,可以用来做判断。
removes # 一个文件名,这个文件不存在,则该命令不执行
范例:
#支持command所不支持的管道符功能
[root@ansible-160 ~]# ansible 10.0.0.161 -m shell -a 'ls /etc | wc -l'
10.0.0.161 | CHANGED | rc=0 >>
177
#creates 因为ccc.txt文件存在,所以不执行命令,与command模块里面的效果一样
[root@ansible-160 ~]# ansible 10.0.0.161 -m shell -a 'creates=/data/ccc.txt ls /etc | wc -l'
10.0.0.161 | SUCCESS | rc=0 >>
skipped, since /data/ccc.txt exist
Service 模块
功能:管理服务。
常用命令选项:
name # 服务名称
enabled # 设置yes表示服务开机启动
state # reloaded 重载配置、restarted 重启服务、started 启动服务、stopped 停止服务
范例:
#开启并设置自启动httpd服务
ansible websrvs -m service -a 'name=httpd state=started enabled=yes'
Setup 模块
功能:用于收集被管理节点的系统信息
范例:
#显示全部信息
[root@centos-160 ~]# ansible 10.0.0.161 -m setup
#过滤信息 查看内存
[root@centos-160 ~]# ansible 10.0.0.161 -m setup -a 'filter=*mem*'
10.0.0.161 | SUCCESS => {
"ansible_facts": {
"ansible_memfree_mb": 1707,
"ansible_memory_mb": {
"nocache": {
"free": 1788,
"used": 192
},
"real": {
"free": 1707,
"total": 1980,
"used": 273
},
"swap": {
"cached": 0,
"free": 2047,
"total": 2047,
"used": 0
}
},
"ansible_memtotal_mb": 1980,
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false
}
Stat 模块
功能:检查文件或文件系统的状态。
注意:对于Windows目标主机,用win_stat模块。
常用命令选项:
path # 文件/对象的完整路径(必须)。
范例:
[root@ansible-160 data]# ansible 10.0.0.161 -m stat -a 'path=/data/nginx-1.21.6.tar.gz'
10.0.0.161 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"stat": {
"atime": 1649585951.668993,
"attr_flags": "",
"attributes": [],
"block_size": 4096,
"blocks": 2104,
"charset": "binary",
"checksum": "3e6d39a714f6716861286630a5f9df3044668d5a",
"ctime": 1649585951.6659932,
"dev": 2053,
"device_type": 0,
"executable": false,
"exists": true,
"gid": 0,
"gr_name": "root",
"inode": 72,
"isblk": false,
"ischr": false,
"isdir": false,
"isfifo": false,
"isgid": false,
"islnk": false,
"isreg": true,
"issock": false,
"isuid": false,
"mimetype": "application/x-gzip",
"mode": "0644",
"mtime": 1649585951.6599934,
"nlink": 1,
"path": "/data/nginx-1.21.6.tar.gz",
"pw_name": "root",
"readable": true,
"rgrp": true,
"roth": true,
"rusr": true,
"size": 1073364,
"uid": 0,
"version": "2114519207",
"wgrp": false,
"woth": false,
"writeable": true,
"wusr": true,
"xgrp": false,
"xoth": false,
"xusr": false
}
}
Unarchive 模块
功能:解压缩包。
注意:对于Windows目标主机,用win_unzip模块。
常用命令选项:
copy # 默认yes,即文件从ansible主控端复制到目标节点并解压缩。如果设置为no,则从指定的远端主机节点寻找解压缩的源文件。
remote_src # 与copy选项互斥。默认no,设置为yes表示文件在远端节点主机。
src # 源路径,可以是ansible主机上的路径,也可以是远程主机(被管理端或者第三方主机)上的路径,如果是远程主机上的路径,则需要设置copy=no或remote_src=yes。
dest # 远程主机上的目标路径
mode #设置解压缩后的文件权限
范例:
#将ansible本地压缩包解压至目标节点指定路径,并设置权限为755
[root@ansible-160 data]# ansible 10.0.0.161 -m unarchive -a 'src=/data/nginx-1.20.2.tar.gz dest=/usr/src/local mode=755'
10.0.0.161 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"dest": "/usr/src/local",
"extract_results": {
"cmd": [
"/usr/bin/gtar",
"--extract",
"-C",
"/usr/src/local",
"-z",
"-f",
"/root/.ansible/tmp/ansible-tmp-1649600578.5-4436-202199801069746/source"
],
"err": "",
"out": "",
"rc": 0
},
"gid": 0,
"group": "root",
"handler": "TgzArchive",
"mode": "0755",
"owner": "root",
"size": 26,
"src": "/root/.ansible/tmp/ansible-tmp-1649600578.5-4436-202199801069746/source",
"state": "directory",
"uid": 0
}
#从http远程下载并解压至指定路径,此时需要设置remote_src=yes
[root@ansible-160 data]# ansible 10.0.0.161 -m unarchive -a 'src=http://nginx.org/download/nginx-1.20.2.tar.gz dest=/usr/src/local remote_src=yes mode=755'
#指定从远程节点上面的压缩包解压至指定路径,此时需要设置remote_src=yes 或 copy=no
[root@ansible-160 data]# ansible 10.0.0.161 -m unarchive -a 'src=/data/nginx-1.21.6.tar.gz dest=/usr/src/local copy=no mode=755'
User 模块 和 Group 模块
User模块
功能:管理用户账号。
注意:Windows节点用 win_user 模块管理。
常用命令选项:
name # 用户名称。
uid # 指定用户id号。
group # 指定用户所属组(primary group)。
home # 指定家目录路径。
shell # 指定用户shell。
system # 默认为no,指定yes时设置为系统用户,注意无法修改已经创建的用户属性。
state # 默认present,设置为absent时删除用户,搭配 remove=yes 可同时删除家目录信息。
范例:
#创建用户 注意,create_home=no 时指定的家目录参数无法创建
[root@centos-160 ~]# ansible 10.0.0.161 -m user -a 'name=sys001 comment=sys001 system=yes uid=88 group=sys001 groups="root, daemon" shell=/sbin/nologin create_home=no home=/data/sys001 non_unique=yes'
10.0.0.161 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"comment": "sys001",
"create_home": false,
"group": 88,
"groups": "root, daemon",
"home": "/data/sys001",
"name": "sys001",
"shell": "/sbin/nologin",
"state": "present",
"system": true,
"uid": 88
}
#删除用户及家目录等数据
[root@centos-160 ~]# ansible 10.0.0.161 -m user -a 'name=sys001 state=absent remove=yes'
10.0.0.161 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"force": false,
"name": "sys001",
"remove": true,
"state": "absent",
"stderr": "userdel: sys001 mail spool (/var/spool/mail/sys001) not found\nuserdel: sys001 home directory (/data/sys001) not found\n",
"stderr_lines": [
"userdel: sys001 mail spool (/var/spool/mail/sys001) not found",
"userdel: sys001 home directory (/data/sys001) not found"
]
}
#创建带有密码的用户
#创建密码,明文=123456
[root@centos-160 ~]# ansible localhost -m debug -a "msg={{'123456' | password_hash('sha512', 'salt')}}"
localhost | SUCCESS => {
"msg": "$6$salt$MktMKPZJ6t59GfxcJU20DwcwQzfMvOlHFVZiOVD71w.igcOo1R7vBYR65JquIQ/7siC7VRpmteKvZmfSkNc69."
}
#创建用户test001,密码为123456
[root@centos-160 ~]# ansible 10.0.0.161 -m user -a 'name=test001 password="$6$salt$MktMKPZJ6t59GfxcJU20DwcwQzfMvOlHFVZiOVD71w.igcOo1R7vBYR65JquIQ/7siC7VRpmteKvZmfSkNc69."'
10.0.0.161 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"comment": "",
"create_home": true,
"group": 1001,
"home": "/home/test001",
"name": "test001",
"password": "NOT_LOGGING_PASSWORD",
"shell": "/bin/bash",
"state": "present",
"system": false,
"uid": 1001
}
#创建用户私钥
[root@centos-160 ~]# ansible 10.0.0.161 -m user -a 'name=test001 generate_ssh_key=yes ssh_key_bits=4096'
10.0.0.161 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"append": false,
"changed": true,
"comment": "",
"group": 1001,
"home": "/home/test001",
"move_home": false,
"name": "test001",
"shell": "/bin/bash",
"ssh_fingerprint": "4096 SHA256:9ytYEE0FS2LHHPK1WpEYe5uTDAet5GTfCZpk4ianVxM ansible-generated on centos-161 (RSA)",
"ssh_key_file": "/home/test001/.ssh/id_rsa",
"ssh_public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC3/yHc7vJxApvS8vu+iBh4mgVDSotHrJ8RlffIWtSq/thpqMDOgQ1ddQYjTjM25XQ7ebmlTK0akKVSQ47FkXfq8pYN0lmU1Z2ksGYd2ov6/NlSeNU2+8OOuM3pAcHtbFEL9M93k261NHR9UgqKwNyZ1qgJTqKIydZWwQkVfEXQ9dd1U4gejjlOJJNlRxeFN7Z0mm4/QhfhARbc3xX06dADkLvJcLmLBM9dCeArAw0OPPQsBJDniLSavURni2Hr+kzwCwMCc90SMYYFGiyeg2jOYODBrMYStmn5i7I53JCxqC1YYg8vb9kmtUqDSlBbhW5uchl74NaCN2hSgozDThD0Asugf5bGoqx3WcO1SnXvCpRKx3SAaXxaBVmI/OqnSuNq2bVRHSBHHOGr6Dd2x+B+OgUvPbDtm7SoHINBXYXD2aGQL6OlfOdVjlqhe2AC/1vykZH+6OlKj+ZbnFF6Wuf4lwFCJjE2FjKDQIouXgtPDwhPKMLA7xNt/ieNIH+tJPZn1MeBeRQX58KwhF3zdHA4w+tacKpej2c8lT5ZmgHSKknfr1cgBNQ2fN84xRhP1iUMqLUIlhfaMwOTNEWCj0HUPWHUveGDk2xlARsaay5IoiMRCy7MQJ6yFcK7WUNskefHAUTlAc8A6AR7C+zHiw83r8BSpKqeMoNwtjcw7jL3Rw== ansible-generated on centos-161",
"state": "present",
"uid": 1001
}
Goup模块
功能:添加或删除组
常用命令选项:
name # 组名称。
gid # 指定组id号。
state # 默认present,值为absent表示删除指定组。
system # 默认no,值为yes表示为系统组。
范例:
#创建组
[root@centos-160 ~]# ansible 10.0.0.161 -m group -a 'name=sys001 system=yes gid=88'
10.0.0.161 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"gid": 88,
"name": "sys001",
"state": "present",
"system": true
}
#删除组
[root@centos-160 ~]# ansible 10.0.0.161 -m group -a 'name=sys001 state=absent'
10.0.0.161 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"name": "sys001",
"state": "absent"
}
Yum 模块 Apt模块
Yum 模块
功能:yum软件包管理。
注意:只支持 RHEL,CentOS,Fedora,不支持Ubuntu其他版本。
常用命令选项:
name # 所安装软件包的名称。
state # present/installed -- 安装选项,absent/removed -- 删除选项,latest -- 安装最新版本。
update_cache # 强制更新yum缓存。
disablerepo # 临时禁用yum仓库,只用于安装或更新时。
enablerepo # 临时使用的yum仓库,只用于安装或更新时。
范例:
#指定节点安装httpd
[root@ansible-160 ~]# ansible 10.0.0.161 -m shell -a 'command_warnings=False rpm -q httpd'
10.0.0.161 | FAILED | rc=1 >>
package httpd is not installednon-zero return code
[root@ansible-160 ~]# ansible 10.0.0.161 -m yum -a 'name=httpd state=present'
10.0.0.161 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"changes": {
"installed": [
"httpd"
]
}
[root@ansible-160 ~]# ansible 10.0.0.161 -m shell -a 'command_warnings=False rpm -q httpd'
10.0.0.161 | CHANGED | rc=0 >>
httpd-2.4.6-97.el7.centos.5.x86_64
#删除节点指定软件
[root@ansible-160 ~]# ansible 10.0.0.161 -m yum -a 'name=httpd state=absent'
10.0.0.161 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"changes": {
"removed": [
"httpd"
]
}
[root@ansible-160 ~]# ansible 10.0.0.161 -m shell -a 'command_warnings=False rpm -q httpd'
10.0.0.161 | FAILED | rc=1 >>
package httpd is not installednon-zero return code
#查看包,相当于 yum list --show-duplicates <package> 命令
[root@ansible-160 ~]# ansible 10.0.0.161 -m yum -a 'list=tree'
10.0.0.161 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"results": [
{
"arch": "x86_64",
"envra": "0:tree-1.6.0-10.el7.x86_64",
"epoch": "0",
"name": "tree",
"release": "10.el7",
"repo": "base",
"version": "1.6.0",
"yumstate": "available"
},
{
"arch": "x86_64",
"envra": "0:tree-1.6.0-10.el7.x86_64",
"epoch": "0",
"name": "tree",
"release": "10.el7",
"repo": "installed",
"version": "1.6.0",
"yumstate": "installed"
}
]
}
Apt 模块
功能:apt软件包管理。
注意:Debian/Ubuuntu 系统软件包管理。
常用命令选项:
name # 所安装软件包的名称。
state # 默认present,值为absent是代表删除软件包,搭配 purge=yes 同时删除配置文件。