10:26:00 # time ansible-playbook mysql_install.yml --extra-vars "host=192.168.240.17 user=root" --private-key=/root/test.pem
PLAY [192.168.240.17] *********************************************************
GATHERING FACTS ***************************************************************
ok: [192.168.240.17]
TASK: [common | Install initializtion require software] ***********************
changed: [192.168.240.17]
TASK: [mysql_install | Copy Mysql Software To Redhat Client] ******************
changed: [192.168.240.17]
TASK: [mysql_install | Create Mysql User In Redhat Client] ********************
changed: [192.168.240.17]
TASK: [mysql_install | Copy Mysql Start Script To Redhat Client] **************
changed: [192.168.240.17]
TASK: [mysql_install | Copy Install Mysql Script To Redhat Client] ***********
changed: [192.168.240.17]
TASK: [mysql_install | Copy Mysql Config To Redhat Client] ********************
changed: [192.168.240.17]
TASK: [mysql_install | Copy Mysql Security Script To Redhat Client] ***********
changed: [192.168.240.17]
TASK: [mysql_install | Create Mysql Install Dir] ******************************
ok: [192.168.240.17]
TASK: [mysql_install | Uncompression Mysql Software To Redhat Client] *********
changed: [192.168.240.17]
TASK: [mysql_install | Modify Mysql Dir Permission In Redhat Client] **********
ok: [192.168.240.17] => (item=/data/mysql/datadir)
ok: [192.168.240.17] => (item=/data/mysql/basedir)
TASK: [mysql_install | Install Mysql Script In Redhat Client] *****************
changed: [192.168.240.17]
TASK: [mysql_install | Start Myql Security Script In Redhat Client] ***********
changed: [192.168.240.17]
TASK: [mysql_install | Add Boot Start Mysql Service In Redhat Client] *********
changed: [192.168.240.17]
TASK: [mysql_install | Delete Mysql compression Software In Redhat Client] ****
changed: [192.168.240.17]
PLAY RECAP ********************************************************************
192.168.240.17 : ok=15 changed=12 unreachable=0 failed=0
real2m1.596s
user0m8.815s
sys0m0.848s
2、安装后测试
登陆192.168.240.17的测试机查看mysql安装情况
[root@ip-10-10-240-21 tmp]# ll
total 16
lrwxrwxrwx 1 root root 30 Jul 13 22:27 mysql.sock -> /data/mysql/datadir/mysql.sock
-rw------- 1 root root 256 Jul 10 06:07 tmp.0PLkgCq81n
-rw------- 1 root root 197 Jul 9 05:35 yum_save_tx-2014-07-09-09-35ibcBiO.yumtx
-rw-rw-r-- 1 zabbix zabbix 320 Jul 10 21:39 zabbix_agentd.log
-rw-rw-r-- 1 zabbix zabbix 5 Jul 10 21:39 zabbix_agentd.pid
[root@ip-10-10-240-21 tmp]# ps -ef|grep mysql
root 21333 1 0 22:27 ? 00:00:00 /bin/sh /data/mysql/basedir/bin/mysqld_safe --defaults-file=/data/mysql/datadir/my.cnf --datadir=/data/mysql/datadir --pid-file=/data/mysql/datadir/mysql.pid
mysql 22156 21333 2 22:27 ? 00:00:08 /data/mysql/basedir/bin/mysqld --defaults-file=/data/mysql/datadir/my.cnf --basedir=/data/mysql/basedir --datadir=/data/mysql/datadir --plugin-dir=/data/mysql/basedir/lib/plugin --user=mysql --log-error=/data/mysql/datadir/mysql-error.log --open-files-limit=10240 --pid-file=/data/mysql/datadir/mysql.pid --socket=/data/mysql/datadir/mysql.sock --port=3306
root 22440 20233 0 22:33 pts/0 00:00:00 grep mysql
[root@ip-10-10-240-21 tmp]# ll /data/mysql/
total 8
drwxr-xr-x 13 mysql mysql 4096 Jun 26 03:59 basedir
drwxr-xr-x 4 mysql mysql 4096 Jul 13 22:28 datadir
[root@ip-10-10-240-21 tmp]# ll /etc/init.d/mysqld
-rwxr-xr-x 1 root root 10905 Jul 13 22:27 /etc/init.d/mysqld
[root@ip-10-10-240-21 tmp]# /etc/init.d/mysqld status
MySQL (Percona Server) running (22156) [ OK ]
[root@ip-10-10-240-21 tmp]# chkconfig --list|grep mysql
mysqld 0:off1:off2:on3:on4:on5:on6:off
[root@ip-10-10-240-21 tmp]# mysql -h 192.168.240.17 -u root -pE4yR3WnoluSFTCBAI
ERROR 1045 (28000): Access denied for user 'root'@'192.168.240.17' (using password: YES)
[root@ip-10-10-240-21 tmp]# mysql -h 10.10.240.21 -u root -pE4yR3WnoluSFTCBAI
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.5.21-log Source distribution
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
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 |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
mysql> use mysql
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> select host,user,password from user;
+--------------+--------+-------------------------------------------+
| host | user | password |
+--------------+--------+-------------------------------------------+
| 10.10.240.21 | root | *BE78618CBAFFF409CE17D81579C1678B94439BE1 |
| % | zabbix | *DEEF4D7D88CD046ECA02A80393B7780A63E7E789 |
+--------------+--------+-------------------------------------------+
2 rows in set (0.00 sec)
可以看到已经按照我的要求安装完成,下面在进行删除测试。
3、删除
10:49:18 # time ansible-playbook mysql_delete.yml --extra-vars "host=192.168.240.17 user=root" --private-key=/root/test.pem
PLAY [192.168.240.17] *********************************************************
GATHERING FACTS ***************************************************************
ok: [192.168.240.17]
TASK: [mysql_delete | Stop Mysql Service] *************************************
changed: [192.168.240.17]
TASK: [mysql_delete | Delete Mysql Boot Start Script] *************************
changed: [192.168.240.17]
TASK: [mysql_delete | Delete Mysql Dir And Socket] ****************************
changed: [192.168.240.17]
TASK: [mysql_delete | Delete Mysql User] **************************************
changed: [192.168.240.17]
TASK: [mysql_delete | Delete Mysql Service Start Script] **********************
changed: [192.168.240.17]
PLAY RECAP ********************************************************************
192.168.240.17 : ok=6 changed=5 unreachable=0 failed=0
real0m25.248s
user0m0.632s
sys0m0.102s