ansible batch installation of MySQL data

Source: Internet
Author: User
Tags mkdir vars

1. Build the installation directory

Mkdir-p/ansible/roles/mysql/{defaults,files,handlers,meta,tasks,templates,vars}
    • Defaults default search Path

    • Tasks Store playbooks Path

    • Files store file and script, copy module file search path

    • Templates Template Storage Path

    • Handlers notify call part Playbook storage path

    • VARs roles Internal variable storage path

2. File directory structure

650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M00/06/03/wKiom1mv1piCG0nOAABrLM-F0IY251.jpg-wh_500x0-wm_ 3-wmp_4-s_189250178.jpg "title=" 2017-09-06_190510.jpg "alt=" Wkiom1mv1picg0noaabrlm-f0iy251.jpg-wh_50 "/>

3.playbooks & Shell

The/etc/ansible/roles/mysql/files/install_mysql.sh script content is:

#!/bin/bash
#
Dbdir= '/data/mysql/'
Passwd= ' fanshine123 '
[-D $DBDIR] | | mkdir $DBDIR-P
ID MySQL &>/dev/null
If [$?-ne 0];then
Useradd mysql-s/sbin/nologin-m
Fi
Chown-r Mysql.mysql $DBDIR
cd/tmp/
Tar XF mysql-5.6.13.tar.gz
CD mysql-5.6.13
CMake. -dcmake_install_prefix=/usr/local/mysql \
-dmysql_datadir= $DBDIR \
-dmysql_unix_addr= $DBDIR/mysql.sock \
-ddefault_charset=utf8 \
-dextra_charsets=all \
-denabled_local_infile=1 \
-dwith_readline=1 \
-DDEFAULT_COLLATION=UTF8_GENERAL_CI \
-dwith_embedded_server=1
If [$?! = 0];then
echo "Make error!"
Exit 1
Fi
Make && make install
If [$?-ne 0];then
echo "Install MySQL is failed!" &&/bin/false
Fi
Sleep 2
Ln-s/usr/local/mysql/bin/*/usr/bin/
Cp-f/usr/local/mysql/support-files/my-default.cnf/etc/my.cnf
Cp-f/usr/local/mysql/support-files/mysql.server/etc/init.d/mysqld
chmod 700/etc/init.d/mysqld
/usr/local/mysql/scripts/mysql_install_db--basedir=/usr/local/mysql--datadir= $DBDIR--user=mysql
If [$?-ne 0];then
echo "Install MySQL is failed!" &&/bin/false
Fi
/etc/init.d/mysqld start
If [$?-ne 0];then
echo "Install MySQL is failed!" &&/bin/false
Fi
Chkconfig--add mysqld
Chkconfig mysqld on
/USR/LOCAL/MYSQL/BIN/MYSQL-E "Update mysql.user set Password=password (' $PASSWD ') where host= ' localhost ' and user= ' root ‘;"
/USR/LOCAL/MYSQL/BIN/MYSQL-E "Update mysql.user set Password=password (' $PASSWD ') where host= ' 127.0.0.1 ' and user= ' root ‘;"
/usr/local/mysql/bin/mysql-e "Delete from mysql.user where user= ';"
/USR/LOCAL/MYSQL/BIN/MYSQL-E "flush privileges;"
If [$?-eq 0];then
echo "Ins_done"
Fi

The contents of the/etc/ansible/roles/mysql/tasks/main.yml file are:

-Name:copy MySQL to client
Copy:src=mysql-5.6.13.tar.gz dest=/tmp/mysql-5.6.13.tar.gz
-Name:copy install_script to client
copy:src=install_mysql.sh dest=/tmp/install_mysql.sh owner=root group=root mode=755
-Name:install MySQL
Shell:/bin/bash/tmp/install_mysql.sh

The contents of the/etc/ansible/mysql.yml file are:

-Hosts:webserver
Remote_user:root
Roles
-MySQL

4. Performing the installation

[Email protected] ansible]# Ansible-playbook mysql.yml--syntax-check--Check grammar
[[email protected] ansible]# Ansible-playbook mysql.yml--performing the installation

650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M02/06/03/wKiom1mv19-zzCs3AAFJOQ-zUNs072.jpg-wh_500x0-wm_ 3-wmp_4-s_1450250384.jpg "title=" 2017-09-06_191043.jpg "alt=" Wkiom1mv19-zzcs3aafjoq-zuns072.jpg-wh_50 "/>

ansible batch installation of MySQL data

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.