标签:
1.创建mysql的playbook结构
2.创建需要用到的vars
3.创建远程安装脚本
1 [root@ansible roles]# cat /etc/ansible/roles/mysql_install/templates/mysql_install.sh 2 #!/bin/bash 3 4 DATADIR=‘/data/mysql/data‘ 5 VERSION=‘{{mysql_version}}‘ 6 export LANG=zh_CN.UTF-8 7 8 #Source function library. 9 . /etc/init.d/functions 10 11 #camke install mysql5.5.X 12 install_mysql(){ 13 #read -p "please input a password for root: " PASSWD 14 PASSWD=‘ly36843‘ 15 if [ ! -d $DATADIR ];then 16 mkdir -p $DATADIR 17 fi 18 yum install cmake make gcc-c++ bison-devel ncurses-devel -y 19 id mysql &>/dev/null 20 if [ $? -ne 0 ];then 21 useradd mysql -s /sbin/nologin -M 22 fi 23 #useradd mysql -s /sbin/nologin -M 24 #change datadir owner to mysql 25 chown -R mysql.mysql $DATADIR 26 cd 27 #wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.38.tar.gz 28 tar xf $VERSION.tar.gz 29 cd $VERSION 30 cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/$VERSION 31 -DMYSQL_DATADIR=$DATADIR 32 -DMYSQL_UNIX_ADDR=$DATADIR/mysql.sock 33 -DDEFAULT_CHARSET=utf8 34 -DDEFAULT_COLLATION=utf8_general_ci 35 -DENABLED_LOCAL_INFILE=ON 36 -DWITH_INNOBASE_STORAGE_ENGINE=1 37 -DWITH_FEDERATED_STORAGE_ENGINE=1 38 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 39 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 40 -DWITHOUT_PARTITION_STORAGE_ENGINE=1 41 make && make install 42 if [ $? -ne 0 ];then 43 action "install mysql is failed!" /bin/false 44 exit $? 45 fi 46 sleep 2 47 #link 48 ln -s /usr/local/$VERSION/ /usr/local/mysql 49 ln -s /usr/local/mysql/bin/* /usr/bin/ 50 #copy config and start file 51 /bin/cp /usr/local/mysql/support-files/my-small.cnf /etc/my.cnf 52 cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld 53 chmod 700 /etc/init.d/mysqld 54 #init mysql 55 /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=$DATADIR --user=mysql 56 if [ $? -ne 0 ];then 57 action "install mysql is failed!" /bin/false 58 exit $? 59 fi 60 #check mysql 61 /etc/init.d/mysqld start 62 if [ $? -ne 0 ];then 63 action "mysql start is failed!" /bin/false 64 exit $? 65 fi 66 chkconfig --add mysqld 67 chkconfig mysqld on 68 /usr/local/mysql/bin/mysql -e "update mysql.user set password=password(‘$PASSWD‘) where host=‘localhost‘ and user=‘root‘;" 69 /usr/local/mysql/bin/mysql -e "update mysql.user set password=password(‘$PASSWD‘) where host=‘127.0.0.1‘ and user=‘root‘;" 70 /usr/local/mysql/bin/mysql -e "delete from mysql.user where password=‘‘;" 71 /usr/local/mysql/bin/mysql -e "flush privileges;" 72 #/usr/local/mysql/bin/mysql -e "select version();" >/dev/null 2>&1 73 if [ $? -eq 0 ];then 74 echo "+---------------------------+" 75 echo "+------mysql安装完成--------+" 76 echo "+---------------------------+" 77 fi 78 #/etc/init.d/mysqld stop 79 } 80 81 install_mysql
4.创建任务
复制文件
解压安装
创建包含文件
最后的playbook结构是
5.创建mysql的playbook配置文件
标签:
原文地址:http://www.cnblogs.com/51runsky/p/b8ad4e3343e6514e8de5446cb38a9a78.html