In the previous blog has been demonstrated, through scripting MySQL Universal binary installation, the following through the demonstration script to implement the source code compilation MARIADB Automation, in large-scale deployment of multiple mariadb, where the use of ansible to implement its automated deployment, Can greatly simplify the time of operations engineer.
First, the script is installed locally by automating the installation of MARIADB, in conjunction with the previous blog and the previous automation implementation of the MySQL Universal binary format installation.
Environment: Centos 6.6 mariadb-10.0.13.tar.gz NODE5 (hostname) 2 HDD: 1 block is System, 1 block is as MySQL data disk
Viewing volume group information
[Email protected] ~]# VGS
VG #PV #LV #SN Attr vsize vfree
VG_LVM 1 2 0 wz--n-98.30g 68.30g
[Email protected] ~]# VGS | awk ' {if (nr==2) {print '} ' splits the volume group name
Vg_lvm
Volume Group expansion
[Email protected] ~]# vgextend Vg_lvm/dev/sdb
Volume Group "VG_LVM" successfully extended
[Email protected] ~]# VGS
VG #PV #LV #SN Attr vsize vfree
VG_LVM 2 2 0 wz--n-118.30g 88.30g
[[email protected] ~]# vgreduce $ (VGs | awk ' {if (nr==2) {print $}} ')/dev/sdb
Removed "/dev/sdb" from volume Group "VG_LVM"
[Email protected] ~]# lvcreate-l 18g-n data vg_lvm/dev/sdb
Logical volume "Data" created
[[email protected] ~]# chmod +x mysql.sh Given its permissions
[Email protected] ~]# Vim mysql.sh script content is as follows:
#!/bin/bash
Useradd-r-s/sbin/nologin mysql >/dev/null
Vgextend $ (Vgs|awk ' {if (nr==2) {print $}} ')/dev/sdb >/dev/null
Lvcreate-l 18g-n Data vg_lvm/dev/sdb >/dev/null
Mkdir/mysql
Mkfs.ext4/dev/vg_lvm/data >/dev/null
Mount/dev/vg_lvm/data/mysql
Mkdir/mysql/data
Chown-r Mysql.mysql/mysql/data
Tar-xf/usr/local/src/mariadb-10.0.13.tar.gz-c/usr/local/
Yum groupinstall-y "Development tools" "Server Platform Development" >/dev/null
Echo-e "\033[42mgroupinstall is ok.\033[0m"
Yum install-y libxml2-devel cmake >/dev/null
Echo-e "\033[42minstall is ok.\033[0m"
cd/usr/local/mariadb-10.0.13/
CMake. -dmysql_datadir=/mysql/data-dwith_ssl=system-dwith_sphinx_storage_engine=1 >/dev/null
Echo-e "\033[42mcmake is ok.\033[0m"
Make && make install >/dev/null
Echo-e "\033[42mmake and make install is ok.\033[0m"
Cd/usr/local/mysql
echo "Export Path=/usr/local/mysql/bin: $PATH" >/etc/profile.d/mysql.sh
. /etc/profile.d/mysql.sh
Cp-f support-files/my-large.cnf/etc/my.cnf
Sed-i '/^\[mysqld\]/a datadir=/mysql/data '/etc/my.cnf
Cp/usr/local/mysql/support-files/mysql.server/etc/rc.d/init.d/mysqld
chmod +x/etc/rc.d/init.d/mysqld
Chkconfig--add mysqld
Chkconfig mysqld on
Chown-r root.mysql/usr/local/mysql/*
/usr/local/mysql/scripts/mysql_install_db--user=mysql--datadir=/mysql/data >/dev/null
Echo-e "033[42mmysql Initial is ok.\033[0m"
Service mysqld Start
Ss-tnlp|grep 3306
[[email protected] ~]#./mysql.sh Execute Script
.....
150410 5:52:01 [Note] innodb:starting shutdown ...
150410 5:52:03 [Note] Innodb:shutdown completed; Log sequence Number 1616707
033[42mmysql initial is OK. Initialization complete
Starting MySQL. success! Start OK
LISTEN 0::: 3306:::* Users: (("mysqld", 39585,21)) found listening on port 3306 , which means that automation is OK.
MARIADB source code compiled for configuration, you can customize its function according to the business requirements function, through the command line to pass a configuration parameter or through the mysql.sh file contains the configuration parameters of the file, the next time you want to use another function, directly modify the parameters of another file. In the execution of mysql.sh, in order to perform all OK, you can also first install the screen software on the host, through a screen command to secure the execution of the brake script.
The following is an automated compilation installation using Ansible MARIADB
Hosts/etc/ansible/hosts File Contents
[DBServer]
IP, or HOSTNAME.
IP, or HOSTNAME.
IP, or HOSTNAME.
。。。
Args.sh as the mariadb parameter file, can be changed according to requirements
#!/bin/bash
mariadb= "-dmysql_datadir=/mysql/data-dwith_ssl=system-dwith_sphinx_storage_engine=1"
mysql.sh
#!/bin/bash
. /root/args.sh
Useradd-r-s/sbin/nologin mysql >/dev/null
Vgextend $ (Vgs|awk ' {if (nr==2) {print $}} ')/dev/sdb >/dev/null
Lvcreate-l 18g-n Data vg_lvm/dev/sdb >/dev/null
Mkdir/mysql
Mkfs.ext4/dev/vg_lvm/data >/dev/null
Mount/dev/vg_lvm/data/mysql
Mkdir/mysql/data
Chown-r Mysql.mysql/mysql/data
Yum groupinstall-y "Development tools" "Server Platform Development" >/dev/null
Echo-e "\033[42mgroupinstall is ok.\033[0m"
Yum install-y libxml2-devel cmake >/dev/null
Echo-e "\033[42minstall is ok.\033[0m"
cd/usr/local/mariadb-10.0.13/
CMake. $ (mariadbarg) >/dev/null
Echo-e "\033[42mcmake is ok.\033[0m"
Make && make install >/dev/null
Echo-e "\033[42mmake and make install is ok.\033[0m"
Cd/usr/local/mysql
echo "Export Path=/usr/local/mysql/bin: $PATH" >/etc/profile.d/mysql.sh
. /etc/profile.d/mysql.sh
Cp-f support-files/my-large.cnf/etc/my.cnf
Sed-i '/^\[mysqld\]/a datadir=/mysql/data '/etc/my.cnf
Cp/usr/local/mysql/support-files/mysql.server/etc/rc.d/init.d/mysqld
chmod +x/etc/rc.d/init.d/mysqld
Chkconfig--add mysqld
Chkconfig mysqld on
Chown-r root.mysql/usr/local/mysql/*
/usr/local/mysql/scripts/mysql_install_db--user=mysql--datadir=/mysql/data >/dev/null
Echo-e "033[42mmysql Initial is ok.\033[0m"
Service mysqld Start
Ss-tnlp|grep 3306
The contents of the Mysql.yml Playbook file are as follows: Unarchive module is a copy and decompression file, script is to execute the current shell script to the remote host
---
#file: Mysql.yml
-Hosts:dbserver
Remote_user:root
Tasks
-Name:remote Copy Decompress
unarchive:src=/usr/local/src/mariadb-10.0.13.tar.gz dest Dest=/usr/local/copy=yes
-Name:execute mariadb Install script
Script:/root/mysql.sql
unarchive:src=/usr/local/src/mariadb-10.0.13.tar.gz dest Dest=/usr/local/copy=yes means: Copy local file/usr/local/src/ mariadb-10.0.13.tar.gz to remote decompression to the/usr/local directory.
OK, here is all OK, if there are any questions in the experiment, welcome to discuss together
This article is from the "Happy is good" blog, please be sure to keep this source http://wdllife.blog.51cto.com/6615958/1633826
Shell script and Ansible practice MARIADB source code compilation automatic installation