[[email protected] 21:45:03~]# mysql -uroot -p123456 -h192.168.64.11 -P8066
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.29-mycat-1.6.7.4-release-20200105164103 MyCat Server (OpenCloudDB)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> show databases;
+----------+
| DATABASE |
+----------+
| TESTDB |
+----------+
1 row in set (0.002 sec)
MySQL [(none)]> use TESTDB;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MySQL [TESTDB]> show tables;
+-------------------+
| Tables_in_hellodb |
+-------------------+
| classes |
| coc |
| courses |
| scores |
| students |
| teachers |
| toc |
+-------------------+
7 rows in set (0.003 sec)
MySQL [TESTDB]>
[[email protected]_192.168.64.10 13:03:27~]# cat /etc/hosts
192.168.64.10 mha
192.168.64.11 master
192.168.64.12 slave1
192.168.64.13 slave2
[[email protected]_192.168.64.10 13:03:30~]# 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:JnhuOb7fyIenPTc7gDPWeOjowuh7JKibhrPahkJR/wU [email protected]
The key's randomart image is:
+---[RSA 2048]----+
| |
| . E |
| . . . |
| . o . |
| .. . + S= |
|... .o =B + |
|+. = =+ = . |
|*+o +o.oo++ + |
|O*+o o+o=+oo.+ |
+----[SHA256]-----+
[[email protected]_192.168.64.10 13:04:31~]# scp -r .ssh master:/root/
The authenticity of host 'master (192.168.64.11)' can't be established.
ECDSA key fingerprint is SHA256:ZWVQ5th7iynhNPKZXujWK5xHRER/eSMTPlSAa5n2n1k.
ECDSA key fingerprint is MD5:2a:b9:ce:23:c7:86:74:c5:9a:75:31:20:bf:80:9e:47.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'master,192.168.64.11' (ECDSA) to the list of known hosts.
[email protected]'s password:
id_rsa 100% 1675 1.1MB/s 00:00
id_rsa.pub 100% 390 440.3KB/s 00:00
known_hosts 100% 361 372.8KB/s 00:00
authorized_keys 100% 390 393.8KB/s 00:00
[[email protected]_192.168.64.10 13:04:47~]# scp -r .ssh slave1:/root/
The authenticity of host 'slave1 (192.168.64.12)' can't be established.
ECDSA key fingerprint is SHA256:ZWVQ5th7iynhNPKZXujWK5xHRER/eSMTPlSAa5n2n1k.
ECDSA key fingerprint is MD5:2a:b9:ce:23:c7:86:74:c5:9a:75:31:20:bf:80:9e:47.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'slave1,192.168.64.12' (ECDSA) to the list of known hosts.
[email protected]'s password:
id_rsa 100% 1675 920.2KB/s 00:00
id_rsa.pub 100% 390 412.3KB/s 00:00
known_hosts 100% 543 987.3KB/s 00:00
authorized_keys 100% 390 741.8KB/s 00:00
[[email protected]_192.168.64.10 13:04:56~]# scp -r .ssh slave2:/root/
The authenticity of host 'slave2 (192.168.64.13)' can't be established.
ECDSA key fingerprint is SHA256:ZWVQ5th7iynhNPKZXujWK5xHRER/eSMTPlSAa5n2n1k.
ECDSA key fingerprint is MD5:2a:b9:ce:23:c7:86:74:c5:9a:75:31:20:bf:80:9e:47.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'slave2,192.168.64.13' (ECDSA) to the list of known hosts.
[email protected]'s password:
id_rsa 100% 1675 864.5KB/s 00:00
id_rsa.pub 100% 390 168.5KB/s 00:00
known_hosts 100% 725 1.0MB/s 00:00
authorized_keys 100% 390 782.2KB/s 00:00
[[email protected]_192.168.64.10 13:05:03~]#
[[email protected]_192.168.64.10 19:30:13~]# cat /usr/local/bin/master_ip_failover
#!/usr/bin/env perl
# Copyright (C) 2011 DeNA Co.,Ltd.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
## Note: This is a sample script and is not complete. Modify the script based on your environment.
use strict;
use warnings FATAL => 'all';
use Getopt::Long;
use MHA::DBHelper;
my (
$command, $ssh_user, $orig_master_host,
$orig_master_ip, $orig_master_port, $new_master_host,
$new_master_ip, $new_master_port, $new_master_user,
$new_master_password
);
my $vip = '192.168.64.100/24'; # 設定virtual IP
my $gateway = '192.168.64.2'; # 網卡gateway IP
my $interface = 'ens32'; # 指定VIP所在網卡
my $key = "1";
my $ssh_start_vip = "/sbin/ifconfig $interface:$key Svip;/sbin/arping -I $interface -c 3 -s $vip $gateway >/dev/null 2>&1";
my $ssh_stop_vip = "/sbin/ifconfig $interface:$key down";
GetOptions(
'command=s' => \$command,
'ssh_user=s' => \$ssh_user,
'orig_master_host=s' => \$orig_master_host,
'orig_master_ip=s' => \$orig_master_ip,
'orig_master_port=i' => \$orig_master_port,
'new_master_host=s' => \$new_master_host,
'new_master_ip=s' => \$new_master_ip,
'new_master_port=i' => \$new_master_port,
'new_master_user=s' => \$new_master_user,
'new_master_password=s' => \$new_master_password,
);
exit &main();
sub main {
if ( $command eq "stop" || $command eq "stopssh" ) {
# $orig_master_host, $orig_master_ip, $orig_master_port are passed.
# If you manage master ip address at global catalog database,
# invalidate orig_master_ip here.
my $exit_code = 1;
eval {
# updating global catalog, etc
$exit_code = 0;
};
if ([email protected]) {
warn "Got Error: [email protected]\n";
exit $exit_code;
}
exit $exit_code;
}
elsif ( $command eq "start" ) {
# all arguments are passed.
# If you manage master ip address at global catalog database,
# activate new_master_ip here.
# You can also grant write access (create user, set read_only=0, etc) here.
my $exit_code = 10;
eval {
print "Enabling the VIP - $vip on the new master - $new_master_host \n";
&start_vip();
&stop_vip();
$exit_code = 0;
};
if ([email protected]) {
warn [email protected];
exit $exit_code;
}
exit $exit_code;
}
elsif ( $command eq "status" ) {
print "Checking the Status of the script.. OK \n";
`ssh $ssh_user\@$orig_master_host \" $ssh_start_vip \"`;
exit 0;
}
else {
&usage();
exit 1;
}
}
sub start_vip() {
`ssh $ssh_user\@$new_master_host \" $ssh_start_vip \"`;
}
# A simple system call that disable the VIP on the old_master
sub stop_vip() {
`ssh $ssh_user\@$orig_master_host \" $ssh_stop_vip \"`;
}
sub usage {
print
"Usage: master_ip_failover --command=start|stop|stopssh|status --orig_master_host=host --orig_master_ip=ip --orig_master_port=port --new_master_host=host --new_master_ip=ip --new_master_port=port\n";
}
[[email protected]_192.168.64.10 21:22:41~]# chmod +x /usr/local/bin/master_ip_failover
7、安裝郵件服務(隻在mha安裝)
[[email protected]_192.168.64.10 22:23:41~]# yum -y install s-nail
[[email protected]_192.168.64.10 22:27:57~]# cat /etc/mail.rc
set from [email protected]
set smtp=smtp.qq.com
set [email protected]
set smtp-auth-password=123456789 # 授權碼,不是QQ密碼
# 測試
[[email protected]_192.168.64.10 22:31:23~]# sh /usr/local/bin/sendmail.sh
2--MyCAT中間件和ansible基礎三、Ansible介紹
8、在master、slave1、slave2安裝mysql5.7
yum -y install numactl gcc gcc-c++
groupadd mysql
useradd -r -s /sbin/nologin -g mysql mysql
tar zxf mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz
mkdir -p /data/software
mv mysql-5.7.27-linux-glibc2.12-x86_64 /data/software/mysql
cd /data/software/mysql
mkdir tmp run log data
touch log/mysql.log
chown mysql:mysql ../mysql/ -R
cat > /etc/my.cnf <<EOF
根據master、slave1、slave2來配置,詳細請看下面
EOF
source /etc/profile
chkconfig --add mysql
chkconfig --level 345 mysql on
service mysql start
source /etc/profile
mysql_pass=$(awk -F 'localhost: ' '$2!="" {print $2}' /data/software/mysql/log/mysql.log)
export MYSQL_PWD=${mysql_pass}
grant_sql="
set password=password('123456');
flush privileges;"
mysql -uroot -e "${grant_sql}" --connect-expired-password
[[email protected]_192.168.64.11 23:03:12~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.3.31-MariaDB-log MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show master status;
+-------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------+----------+--------------+------------------+
| master-bin.000001 | 329 | | |
+-------------------+----------+--------------+------------------+
1 row in set (0.001 sec)
MariaDB [(none)]> grant all on *.* to [email protected]'%' identified by "123456";
Query OK, 0 rows affected (0.001 sec)
MariaDB [hellodb]> grant all on *.* to [email protected]'%' identified by "123456";
Query OK, 0 rows affected (0.000 sec)
MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.000 sec)
MariaDB [(none)]> source hellodb_innodb.sql;
14、slave1、slave2執行配置從節點操作
CHANGE MASTER To
MASTER_HOST='192.168.64.11',
MASTER_USER='slave',
MASTER_PASSwORD='123456',
MASTER_LOG_FILE='master-bin.000001',
MASTER_LOG_POS=329;
[[email protected]_192.168.64.12 23:03:24~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.3.31-MariaDB-log MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> CHANGE MASTER To
-> MASTER_HOST='192.168.64.11',
-> MASTER_USER='slave',
-> MASTER_PASSwORD='123456',
-> MASTER_LOG_FILE='master-bin.000001',
-> MASTER_LOG_POS=329;
Query OK, 0 rows affected (0.006 sec)
MariaDB [(none)]> start slave;
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.64.11
Master_User: slave
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master-bin.000001
Read_Master_Log_Pos: 9551
Relay_Log_File: slave1-relay-bin.000002
Relay_Log_Pos: 9778
Relay_Master_Log_File: master-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| hellodb |
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.000 sec)
MariaDB [(none)]> use hellodb;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [hellodb]> show tables;
+-------------------+
| Tables_in_hellodb |
+-------------------+
| classes |
| coc |
| courses |
| scores |
| students |
| teachers |
| toc |
+-------------------+
7 rows in set (0.000 sec)
MariaDB [hellodb]>
15、檢查ssh配置連通是否正常,
提示 All SSH connection tests passed successfully. 則是正常的:
[[email protected]_192.168.64.10 23:41:49~]# masterha_check_ssh --conf=/etc/mastermha/app1.cnf
Sun Aug 22 23:41:52 2021 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Sun Aug 22 23:41:52 2021 - [info] Reading application default configuration from /etc/mastermha/app1.cnf..
Sun Aug 22 23:41:52 2021 - [info] Reading server configuration from /etc/mastermha/app1.cnf..
Sun Aug 22 23:41:52 2021 - [info] Starting SSH connection tests..
Sun Aug 22 23:41:53 2021 - [debug]
Sun Aug 22 23:41:52 2021 - [debug] Connecting via SSH from [email protected](192.168.64.11:22) to [email protected](192.168.64.12:22)..
Sun Aug 22 23:41:52 2021 - [debug] ok.
Sun Aug 22 23:41:52 2021 - [debug] Connecting via SSH from [email protected](192.168.64.11:22) to [email protected](192.168.64.13:22)..
Sun Aug 22 23:41:52 2021 - [debug] ok.
Sun Aug 22 23:41:53 2021 - [debug]
Sun Aug 22 23:41:52 2021 - [debug] Connecting via SSH from [email protected](192.168.64.12:22) to [email protected](192.168.64.11:22)..
Sun Aug 22 23:41:52 2021 - [debug] ok.
Sun Aug 22 23:41:52 2021 - [debug] Connecting via SSH from [email protected](192.168.64.12:22) to [email protected](192.168.64.13:22)..
Sun Aug 22 23:41:53 2021 - [debug] ok.
Sun Aug 22 23:41:54 2021 - [debug]
Sun Aug 22 23:41:53 2021 - [debug] Connecting via SSH from [email protected](192.168.64.13:22) to [email protected](192.168.64.11:22)..
Sun Aug 22 23:41:53 2021 - [debug] ok.
Sun Aug 22 23:41:53 2021 - [debug] Connecting via SSH from [email protected](192.168.64.13:22) to [email protected](192.168.64.12:22)..
Sun Aug 22 23:41:53 2021 - [debug] ok.
Sun Aug 22 23:41:54 2021 - [info] All SSH connection tests passed successfully.
16、檢查MySQL配置連通是否正常
最後提示 MySQL Replication Health is OK. 則是正常的,如果提示 NOT OK! 則不正常。
[[email protected]_192.168.64.10 21:57:09/etc/mastermha]# masterha_check_repl --conf=/etc/mastermha/app1.cnf
Tue Aug 24 21:57:11 2021 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Tue Aug 24 21:57:11 2021 - [info] Reading application default configuration from /etc/mastermha/app1.cnf..
Tue Aug 24 21:57:11 2021 - [info] Reading server configuration from /etc/mastermha/app1.cnf..
Tue Aug 24 21:57:11 2021 - [info] MHA::MasterMonitor version 0.58.
Tue Aug 24 21:57:12 2021 - [info] GTID failover mode = 0
Tue Aug 24 21:57:12 2021 - [info] Dead Servers:
Tue Aug 24 21:57:12 2021 - [info] Alive Servers:
Tue Aug 24 21:57:12 2021 - [info] 192.168.64.11(192.168.64.11:3306)
Tue Aug 24 21:57:12 2021 - [info] 192.168.64.12(192.168.64.12:3306)
Tue Aug 24 21:57:12 2021 - [info] 192.168.64.13(192.168.64.13:3306)
Tue Aug 24 21:57:12 2021 - [info] Alive Slaves:
Tue Aug 24 21:57:12 2021 - [info] 192.168.64.12(192.168.64.12:3306) Version=5.7.27-log (oldest major version between slaves) log-bin:enabled
Tue Aug 24 21:57:12 2021 - [info] Replicating from 192.168.64.11(192.168.64.11:3306)
Tue Aug 24 21:57:12 2021 - [info] Primary candidate for the new Master (candidate_master is set)
Tue Aug 24 21:57:12 2021 - [info] 192.168.64.13(192.168.64.13:3306) Version=5.7.27-log (oldest major version between slaves) log-bin:enabled
Tue Aug 24 21:57:12 2021 - [info] Replicating from 192.168.64.11(192.168.64.11:3306)
Tue Aug 24 21:57:12 2021 - [info] Current Alive Master: 192.168.64.11(192.168.64.11:3306)
Tue Aug 24 21:57:12 2021 - [info] Checking slave configurations..
Tue Aug 24 21:57:12 2021 - [info] Checking replication filtering settings..
Tue Aug 24 21:57:12 2021 - [info] binlog_do_db= , binlog_ignore_db=
Tue Aug 24 21:57:12 2021 - [info] Replication filtering check ok.
Tue Aug 24 21:57:12 2021 - [info] GTID (with auto-pos) is not supported
Tue Aug 24 21:57:12 2021 - [info] Starting SSH connection tests..
Tue Aug 24 21:57:15 2021 - [info] All SSH connection tests passed successfully.
Tue Aug 24 21:57:15 2021 - [info] Checking MHA Node version..
Tue Aug 24 21:57:15 2021 - [info] Version check ok.
Tue Aug 24 21:57:15 2021 - [info] Checking SSH publickey authentication settings on the current master..
Tue Aug 24 21:57:15 2021 - [info] HealthCheck: SSH to 192.168.64.11 is reachable.
Tue Aug 24 21:57:15 2021 - [info] Master MHA Node version is 0.58.
Tue Aug 24 21:57:15 2021 - [info] Checking recovery script configurations on 192.168.64.11(192.168.64.11:3306)..
Tue Aug 24 21:57:15 2021 - [info] Executing command: save_binary_logs --command=test --start_pos=4 --binlog_dir=/data/software/mysql/data --output_file=/var/tmp/save_binary_logs_test --manager_version=0.58 --start_file=mysql-bin.000002
Tue Aug 24 21:57:15 2021 - [info] Connecting to [email protected](192.168.64.11:22)..
Creating /var/tmp if not exists.. ok.
Checking output directory is accessible or not..
ok.
Binlog found at /data/software/mysql/data, up to mysql-bin.000002
Tue Aug 24 21:57:15 2021 - [info] Binlog setting check done.
Tue Aug 24 21:57:15 2021 - [info] Checking SSH publickey authentication and checking recovery script configurations on all alive slave servers..
Tue Aug 24 21:57:15 2021 - [info] Executing command : apply_diff_relay_logs --command=test --slave_user='mhauser' --slave_host=192.168.64.12 --slave_ip=192.168.64.12 --slave_port=3306 --workdir=/var/tmp --target_version=5.7.27-log --manager_version=0.58 --relay_log_info=/data/software/mysql/data/relay-log.info --relay_dir=/data/software/mysql/data/ --slave_pass=xxx
Tue Aug 24 21:57:15 2021 - [info] Connecting to [email protected](192.168.64.12:22)..
Checking slave recovery environment settings..
Opening /data/software/mysql/data/relay-log.info ... ok.
Relay log found at /data/software/mysql/data, up to slave1-relay-bin.000002
Temporary relay log file is /data/software/mysql/data/slave1-relay-bin.000002
Checking if super_read_only is defined and turned on.. not present or turned off, ignoring.
Testing mysql connection and privileges..
mysql: [Warning] Using a password on the command line interface can be insecure.
done.
Testing mysqlbinlog output.. done.
Cleaning up test file(s).. done.
Tue Aug 24 21:57:16 2021 - [info] Executing command : apply_diff_relay_logs --command=test --slave_user='mhauser' --slave_host=192.168.64.13 --slave_ip=192.168.64.13 --slave_port=3306 --workdir=/var/tmp --target_version=5.7.27-log --manager_version=0.58 --relay_log_info=/data/software/mysql/data/relay-log.info --relay_dir=/data/software/mysql/data/ --slave_pass=xxx
Tue Aug 24 21:57:16 2021 - [info] Connecting to [email protected](192.168.64.13:22)..
Checking slave recovery environment settings..
Opening /data/software/mysql/data/relay-log.info ... ok.
Relay log found at /data/software/mysql/data, up to slave2-relay-bin.000002
Temporary relay log file is /data/software/mysql/data/slave2-relay-bin.000002
Checking if super_read_only is defined and turned on.. not present or turned off, ignoring.
Testing mysql connection and privileges..
mysql: [Warning] Using a password on the command line interface can be insecure.
done.
Testing mysqlbinlog output.. done.
Cleaning up test file(s).. done.
Tue Aug 24 21:57:16 2021 - [info] Slaves settings check done.
Tue Aug 24 21:57:16 2021 - [info]
192.168.64.11(192.168.64.11:3306) (current master)
+--192.168.64.12(192.168.64.12:3306)
+--192.168.64.13(192.168.64.13:3306)
Tue Aug 24 21:57:16 2021 - [info] Checking replication health on 192.168.64.12..
Tue Aug 24 21:57:16 2021 - [info] ok.
Tue Aug 24 21:57:16 2021 - [info] Checking replication health on 192.168.64.13..
Tue Aug 24 21:57:16 2021 - [info] ok.
Tue Aug 24 21:57:16 2021 - [info] Checking master_ip_failover_script status:
Tue Aug 24 21:57:16 2021 - [info] /usr/local/bin/master_ip_failover --command=status --ssh_user=root --orig_master_host=192.168.64.11 --orig_master_ip=192.168.64.11 --orig_master_port=3306
Checking the Status of the script.. OK
Svip: Unknown host
ifconfig: `--help' gives usage information.
Tue Aug 24 21:57:16 2021 - [info] OK.
Tue Aug 24 21:57:16 2021 - [warning] shutdown_script is not defined.
Tue Aug 24 21:57:16 2021 - [info] Got exit code 0 (Not master dead).
MySQL Replication Health is OK.
[[email protected]_192.168.64.11 22:46:20~]# init 6
Connection closing...Socket close.
Connection closed by foreign host.
Disconnected from remote host(master) at 22:46:23.
Type `help' to learn how to use Xshell prompt.
[H:\~]$
檢視MHA日志
tail -f /data/mastermha/app1/manager.log
略略略。。。。
----- Failover Report -----
app1: MySQL Master failover 192.168.64.11(192.168.64.11:3306) to 192.168.64.12(192.168.64.12:3306) succeeded
Master 192.168.64.11(192.168.64.11:3306) is down!
Check MHA Manager logs at mha:/data/mastermha/app1/manager.log for details.
Started automated(non-interactive) failover.
Invalidated master IP address on 192.168.64.11(192.168.64.11:3306)
The latest slave 192.168.64.12(192.168.64.12:3306) has all relay logs for recovery.
Selected 192.168.64.12(192.168.64.12:3306) as a new master.
192.168.64.12(192.168.64.12:3306): OK: Applying all logs succeeded.
192.168.64.12(192.168.64.12:3306): OK: Activated master IP address.
192.168.64.13(192.168.64.13:3306): This host has the latest relay log events.
Generating relay diff files from the latest slave succeeded.
192.168.64.13(192.168.64.13:3306): OK: Applying all logs succeeded. Slave started, replicating from 192.168.64.12(192.168.64.12:3306)
192.168.64.12(192.168.64.12:3306): Resetting slave info succeeded.
Master failover to 192.168.64.12(192.168.64.12:3306) completed successfully.
Tue Aug 24 22:46:51 2021 - [info] Sending mail..
安裝:
[[email protected] 22:09:12~]# ansible all -m yum -a 'name=httpd state=present'
删除:
[[email protected] 22:23:06~]# ansible all -m yum -a 'name=httpd state=absent'
service子產品
功能:管理軟體服務
範例:
安裝httpd服務:
[[email protected] 22:26:05~]# ansible all -m yum -a 'name=httpd state=present'
啟動httpd服務并設定開機自啟
[[email protected] 22:26:12~]# ansible all -m service -a 'name=httpd state=started enabled=yes'
group子產品
功能:管理組
範例:
添加nginx組
[[email protected] 23:02:20~]# ansible all -m group -a 'name=nginx gid=1200 system=yes'
删除組
[[email protected] 23:02:31~]# ansible all -m group -a 'name=nginx state=absent'
user子產品
功能:管理使用者
範例:
先添加nginx組
[[email protected] 23:03:05~]# ansible all -m group -a 'name=nginx gid=1200 system=yes'
添加nginx使用者
[[email protected] 23:03:08~]# ansible all -m user -a 'name=nginx comment=nginx uid=1200 group=nginx groups="root,daemon" shell=/sbin/nologin system=yes create_home=no home=/data/nginx non_unique=yes'
檢視建立的nginx使用者
[[email protected] 23:05:10~]# ansible all -a 'getent passwd nginx'
删除使用者,順便nginx家目錄也删除
[[email protected] 23:05:20~]# ansible all -m user -a 'name=nginx state=absent remove=yes'