《MysqL数据库集群运维自动化工具ansible使用playbook安装MysqL》要点:
本文介绍了MysqL数据库集群运维自动化工具ansible使用playbook安装MysqL,希望对您有用。如果有疑问,可以联系我们。
MysqL学习上次介绍了如何使用ansible playbook安装zabbix客户端(/article/52158.htm),这次介绍一下如何使用playbook安装MysqL.
MysqL学习 MysqL_basedir: /data/MysqL/basedir 源码目录 MysqL_datadir: /data/MysqL/datadir 数据目录 MysqL_user: MysqL MysqL用户 MysqL_database_user: root 数据库用户 MysqL_passwd: 'E4yR3WnoluSFTCBAI' 数据库密码 MysqL_port: 3306 MysqL监听端口 MysqL_sock: /data/MysqL/datadir/MysqL.sock MysqL的sock MysqL_charset: utf8 MysqL字符集 MysqL_collation: utf8_general_ci MysqL排序方式 MysqL_version: Percona-Server-5.5.21-rel25.1.tar.gz MysqL版本
MysqL学习 10:24:06 # tree MysqL_* MysqL_delete ├── files ├── handlers ├── Meta │ └── main.yml ├── tasks │ ├── delete.yml │ └── main.yml ├── templates └── vars └── main.yml MysqL_install ├── files │ └── MysqL.tar.gz ├── handlers ├── Meta │ └── main.yml ├── tasks │ ├── copy.yml │ ├── delete.yml │ ├── install.yml │ └── main.yml ├── templates │ ├── install_MysqL.sh │ ├── my.cnf │ ├── MysqLd │ └── MysqL_security.sh └── vars └── main.yml 12 directories,15 files
MysqL学习 10:32:06 # cat MysqL_install.yml --- - hosts: "{{host}}" remote_user: "{{user}}" gather_facts: True roles: - common - MysqL_install
MysqL学习 10:32:44 # cat MysqL_delete.yml --- - hosts: "{{host}}" remote_user: "{{user}}" gather_facts: True roles: - MysqL_delete
MysqL学习由于在上篇安装zabbix客户端已经介绍了结构,所以现在不介绍了.
MysqL学习 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 real 2m1.596s user 0m8.815s sys 0m0.848s
MysqL学习2、安装后测试
MysqL学习登陆192.168.240.17的测试机查看MysqL安装情况
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: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 -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)
MysqL学习可以看到已经按照我的要求安装完成,下面在进行删除测试.
MysqL学习 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
MysqL学习 [root@ip-10-10-240-21 tmp]# ll /tmp/ total 16 -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]# ll /data/ total 4 drwxr-xr-x 3 root root 4096 Jul 10 22:11 webroot [root@ip-10-10-240-21 tmp]# ps -ef|grep MysqL root 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: cannot 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]#
MysqL学习如果大家想使用我的例子,可以从百度云的地址下载(文件大于50M,没办法放到附件或者51下载中心)地址是http://pan.baidu.com/s/1mgG8jY4,然后放到/etc/ansible目录里,下面是压缩包里的内容
MysqL学习 11:20:08 # unzip -v MysqL_install.zip Archive: MysqL_install.zip Length Method Size Cmpr Date Time CRC-32 Name -------- ------ ------- ---- ---------- ----- -------- ---- 113 Defl:N 89 21% 07-14-2014 10:32 aaed0763 MysqL_install.yml 99 Defl:N 82 17% 07-14-2014 10:32 70c2a028 MysqL_delete.yml 0 Stored 0 0% 07-03-2014 17:29 00000000 roles/common/ 0 Stored 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/main.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 roles/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 Stored 0 0% 06-24-2014 11:27 00000000 roles/MysqL_install/ 0 Stored 0 0% 07-08-2014 14:12 00000000 roles/MysqL_install/Meta/ 198 Defl:N 149 25% 07-08-2014 14:12 b03e00eb roles/MysqL_install/Meta/main.yml 0 Stored 0 0% 07-14-2014 09:27 00000000 roles/MysqL_install/tasks/ 201 Defl:N 153 24% 07-14-2014 09:27 51de730b roles/MysqL_install/tasks/delete.yml 65 Defl:N 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 00000000 roles/MysqL_install/templates/ 518 Defl:N 241 54% 07-14-2014 09:15 529052bf roles/MysqL_install/templates/install_MysqL.sh 10905 Defl:N 3765 66% 06-26-2014 14:06 e35e7b82 roles/MysqL_install/templates/MysqLd 2122 Defl:N 823 61% 07-14-2014 09:49 f91c74ab roles/MysqL_install/templates/my.cnf 794 Defl:N 275 65% 07-03-2014 13:15 560ee63e roles/MysqL_install/templates/MysqL_security.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_delete/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:39 dccd57b4 roles/MysqL_delete/tasks/delete.yml 22 Stored 22 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 roles/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% 41 files