Last described how to install the Zabbix client (http://www.jb51.net/article/52158.htm) using Ansible playbook, this time describes how to use playbook to install MySQL.
Here is the information for installing MySQL:
Mysql_basedir:/data/mysql/basedir Source directory
mysql_datadir:/data/mysql/datadir Data Directory
mysql_user:mysql MySQL user
mysql_database_user:root database user
mysql_passwd: ' e4yr3wnolusftcbai ' database password
mysql_ port:3306 MySQL listening port
mysql_sock:/data/mysql/datadir/mysql.sock mysql sock
mysql_charset: UTF8 MySQL Character set
mysql_collation:utf8_general_ci mysql sort
mysql_version: percona-server-5.5.21-rel25.1.tar.gz MySQL Version
The following is the playbook structure for installing MySQL
10:24:06 # tree mysql_*
mysql_delete
├──files
├──handlers
├──meta
│└──main.yml ├──tasks< C7/>│├──delete.yml
│└──main.yml
├──templates
└──vars
└──main.yml
mysql_install Files
│└──mysql.tar.gz
├──handlers
├──meta
│└──main.yml
├──tasks
│├──copy.yml< C20/>│├──delete.yml
│├──install.yml
│└──main.yml
├──templates
│├──install_mysql.sh
│ ├──MY.CNF
│├──mysqld
│└──mysql_security.sh
└──vars
└──main.yml
, files
The Playbook MySQL installation is
10:32:06 # cat Mysql_install.yml
---
-hosts: "{{host}}"
Remote_user: "{{user}}"
gather_facts: True
Roles:
-common
-Mysql_install
Playbook's MySQL assistance is
10:32:44 # cat Mysql_delete.yml
---
-hosts: "{{host}}"
Remote_user: "{{user}}"
gather_facts: True
roles:
-Mysql_delete
The
is not introduced now because the Zabbix client has introduced the structure in the previous installment.
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.1 68.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 real 2m1.596s user 0m8.815s sys 0m0.848s
2, after the installation test
Login 192.168.240.17 test machine to view MySQL installation
[root@ip-10-10-240-21 tmp]# ll total lrwxrwxrwx 1 root 22:27 mysql.sock-> SOCK-RW-------1 root 256 06:07 tmp.0plkgcq81n-rw-------1 root root 197 June 9 05:35 yum_save_tx-2014-07-09 -09-35ibcbio.yumtx-rw-rw-r--1 Zabbix Zabbix-21:39 zabbix_agentd.log-rw-rw-r--1 Zabbix Zabbix 5 June 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 grep mysql [00:00:00 root@ip-10-10-240-21 tmp]# 8 drwxr-xr-x MySQL mysql 4096 June 03:59 basedir drwxr-xr-x 4 mysql mysql 4096 June 22:28 DataDir [root@ip-10-10-240 -21 tmp]# ll/etc/init.d/mysqld-rwxr-xr-x 1 root 10905 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:off 1:off 2:on 3:on 4:on 5:on 6:off [root@ip-10-10-240-21 tmp]# mysql-h 192.168.240.17-u root-pe4 Yr3wnolusftcbai ERROR 1045 (28000): Access denied for user ' root ' @ ' 192.168.240.17 ' (using Password:yes) [root@ip-10-10-24 0-21 tmp]# mysql-h 10.10.240.21-u Root-pe4yr3wnolusftcbai 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), Oracle and/or its Affiliates. All Rights ReserVed. Oracle is a registered trademark to Oracle Corporation and/or its affiliates.
The other names may is 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> with MySQL Reading table information for completion of table and Column names You can turn out 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)
You can see that the installation has been completed as per my requirements and the following is a test for deletion.
3, delete
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 Real 0m25.248s User 0m0.632s sys 0m0.102s
4, after the deletion test
[root@ip-10-10-240-21 tmp]# ll/tmp/total
-rw-------1 root root 256 June 06:07 tmp.0plkgcq81n
------ -1 Root 197 June 9 05:35 yum_save_tx-2014-07-09-09-35ibcbio.yumtx
-rw-rw-r--1 Zabbix Zabbix 21:39 Bix_agentd.log
-rw-rw-r--1 Zabbix Zabbix 5 June 21:39 zabbix_agentd.pid
[root@ip-10-10-240-21 tmp]# ll/data/< C7/>total 4
drwxr-xr-x 3 root root 4096 June 22:11 Webroot
[root@ip-10-10-240-21 tmp]# ps-ef|grep mysql
ro OT 22955 20233 0 22:50 pts/0 00:00:00 grep mysql
[root@ip-10-10-240-21-tmp]# ll/etc/init.d/mysql Ls:cann
OT access/etc/init.d/mysql:no such file or directory
[root@ip-10-10-240-21 tmp]# chkconfig--list|grep MySQL
[Root@ip-10-10-240-21 tmp]#
You can see that all deletes are complete.
If you want to use my example, you can download the address from the Baidu cloud (files larger than 50M, no way to put to the attachment or 51 Download Center) address is http://pan.baidu.com/s/1mgG8jY4, and then put into the/etc/ansible directory, Here's what's in the zip bag.
11:20:08 # unzip-v Mysql_install.zip Archive:mysql_install.zip Length method Size cmpr The Date time CRC-32 Name-------- --------------------------------------------113 Defl:n 21% 07-14-2014 10:32 aaed0763 mysql_install.yml 99 Defl:n 17% 07-14-2014 10:32 70c2a028 mysql_delete.yml 0 Stored 0 0% 07-03-2014 17:29 00000000 roles/common/0 Sto Red 0 0% 06-30-2014 15:58 00000000 roles/common/meta/267 defl:n 178 33% 06-30-2014 15:58 31ee20ec roles/common/meta/m Ain.yml 0 Stored 0 0% 07-11-2014 09:31 00000000 roles/common/tasks/586 defl:n 268 54% 07-08-2014 10:18 1c0af2a1 rol Es/common/tasks/main.yml 0 Stored 0 0% 06-19-2014 13:43 00000000 roles/common/handlers/58 defl:n 48 17% 06-19-2014 13:43 8d058053 roles/common/handlers/main.yml 0 Stored 0 0% 06-19-2014 13:30 00000000 roles/common/vars/0 Stored 0 0% 06-19-2014 13:30 00000000 roles/common/templates/0 Stored 0 0% 06-19-2014 13:30 00000000 roles/common/files/0 St ORed 0 0% 06-24-2014 11: 00000000 roles/mysql_install/0 Stored 0 0% 07-08-2014 14:12 00000000 roles/mysql_install/meta/198 Defl:N 149 2 5% 07-08-2014 14:12 b03e00eb roles/mysql_install/meta/main.yml 0 Stored 0 0% 07-14-2014 09:27 00000000 Roles/mysql_inst all/tasks/201 defl:n 153 24% 07-14-2014 09:27 51de730b roles/mysql_install/tasks/delete.yml 41 37% 07-14- 2014 09:27 a3197ca7 roles/mysql_install/tasks/main.yml 1281 defl:n 329 74% 07-14-2014 09:27 73d60454 roles/mysql_install /tasks/copy.yml 1162 defl:n 375 68% 07-14-2014 09:27 e5a7341c roles/mysql_install/tasks/install.yml 0 Stored 0 0% 06-
19-2014 13:30 00000000 roles/mysql_install/handlers/0 Stored 0 0% 07-14-2014 09:51 00000000 roles/mysql_install/vars/ 313 DEFL:N 177 44% 07-14-2014 09:51 bf4476a7 roles/mysql_install/vars/main.yml 0 Stored 0 0% 07-14-2014 11:11 000000 roles/mysql_install/templates/518 defl:n 241 54% 07-14-2014 09:15 529052bf roles/mysql_install/templates/install_my sql.sh 10905 Defl:n 3766% 06-26-2014 14:06 e35e7b82 roles/mysql_install/templates/mysqld 2122 defl:n 823 61% 07-14-2014 09:49 f91c74ab role S/MYSQL_INSTALL/TEMPLATES/MY.CNF 794 defl:n 275 65% 07-03-2014 13:15 560ee63e ROLES/MYSQL_INSTALL/TEMPLATES/MYSQL_SECU rity.sh 0 Stored 0 0% 06-26-2014 13:59 00000000 roles/mysql_install/files/61805835 defl:n 60413846 2% 06-26-2014 16:18 f61e317d roles/mysql_install/files/mysql.tar.gz 0 Stored 0 0% 06-24-2014 11:27 00000000 roles/mysql_delete/0 Stored 0 0% 07-08-2014 14:12 00000000 roles/mysql_delete/meta/197 defl:n 147 25% 07-08-2014 14:12 fe6b0ef8 Roles/mysql_dele Te/meta/main.yml 0 Stored 0 0% 07-14-2014 09:39 00000000 roles/mysql_delete/tasks/692 defl:n 245 65% 07-14-2014 09: DCCD57B4 roles/mysql_delete/tasks/delete.yml Stored 0% 06-27-2014 13:30 728ce4aa roles/mysql_delete/tasks/main . yml 0 Stored 0 0% 06-19-2014 13:30 00000000 roles/mysql_delete/handlers/0 Stored 0 0% 07-03-2014 13:16 00000000 Ro
les/mysql_delete/vars/313 DEFL:N 177 44% 07-14-2014 10:56 bf4476a7 roles/mysql_delete/vars/main.yml 0 Stored 0 0% 06-27-2014 13:30 00000000 roles/mysql_delete/templates/0 Stored 0 0% 06-27-2014 13:30 00000000 roles/mysql_delete/files/------------------
-------61825741 60421430 2% files