Tag: Equals line chown Package date file Service Playbook Word
1.1 Synchronizing the MySQL package to the client server for pre-installation
Ps:mysql Install the package line to the/ansible/roles/mysql/files directory on the ansible server
vim/ansible/roles/mysql/tasks/main.yml- name:copy mysql_tar_gz to client copy:src=mysql- 5.6. tar.gz dest=/tmp/mysql-5.6. * . tar.gz- name:copy install_script to client copy:src=mysql_install.sh dest=/tmp/mysql_ install.sh owner=root group=root mode=755- name:install mysql /bin/bash/tmp/mysql_ install.sh
1.2 Creating a MySQL installation script
/ansible/roles/mysql/files/mysql_install.sh#!/bin/bash### #定义mysql数据库路径, and MySQL login password dbdir='/application/mysql/data'PASSWD='bingoclo123'# # # #判断数据目录是否存在如果不存在递归创建目录 [-D $DBDIR] | | mkdir $DBDIR-p### #安装mysql组件yum Install cmake make gcc-c++ Bison-devel Ncurses-devel-Yid MySQL&>/dev/NULL# # # #如果执行id MySQL output is 0 so that is to do the correct creation of MySQL userif[$?-ne0];then useradd MySQL-s/sbin/nologin-mfi### #赋予数据目录权限chown-R Mysql.mysql $DBDIR # # # #切换到tmp目录, unzip MySQL, compile and install MySQL to/application/MYSQLCD/tmp/Tar XF mysql-5.6. *. TAR.GZCD MySQL-5.6. *CMake.-dcmake_install_prefix=/application/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# # # #判断如果以上执行结果不等于0, description execution failed, exit! if[ $? !=0];then Echo"CMake error!"Exit1fi### #判断执行成功, keep going down make&&Make Installif[$?-ne0];then Echo"install MySQL is failed!"&&/bin/falseFisleep2# # #做软连接ln-s/application/mysql/bin/* /usr/bin/### #复制mysql配置文件cp-F/application/mysql/support-files/my-default.cnf/etc/my.cnf### #复制mysql启停脚本到init. DCP -f/application/mysql/support-files/mysql.server/etc/init.d/mysqld### #执行权chmod 700/etc/init.d/mysqld### #初始化mysql /application/mysql/scripts/mysql_install_db--basedir=/application/mysql--datadir= $DBDIR--user=mysql#### If MySQL initialization fails prompt install MySQL is failed! otherwise/etc/init.d/mysqld startif [$?-ne 0];then echo "Install MySQL is failed!" &&/bin/falsefi/etc/init.d/mysqld S tart### #如果mysql开启失败提示install MySQL is failed! Otherwise go down if [$?-ne 0];then echo "Install MySQL is failed!" &&/bin/falsefi### #开机自启chkconfig--add mysqldchkconfig Mysqld on/application/mysql/bin/mysql-e "Update mysql.user set Password=password (' $PASSWD ') where host= ' localhost ' and user= ' root '; /APPLICATION/MYSQL/BIN/MYSQL-E "Update mysql.user set Password=password (' $PASSWD ') where host= ' 127.0.0.1 ' and user= ' Root '; ' /application/mysql/bin/mysql-e "Delete from mysql.user where password= ';" /APPLICATION/MYSQL/BIN/MYSQL-E "flush privileges;" If [$?-eq 0];then echo "Ins_done" fi
1.3 Ps: Execute ansible Command 1.3.1 Because this operation is only for MySQL deployment, so comment out the other services
- hosts:bgo remote_user:root roles:# - nginx - mysql# - tomcat# - db~
1.3.2 Installation Commands
CD/ansibleansible-playbook web.yml--syntax-check #检查语法ansible-playbook web.yml # Perform
Ansible deploying MySQL in bulk