一看必会系列:ansible 自动部署mysql多实例

来源:本站原创 Linux, mysql_mariadb 超过414 views围观 0条评论

 

 

目录

/etc/ansible/roles/m_mysql/
├── files
│   ├── m_mysql3355_adduser.sh
│   ├── m_mysql3355_setup.sh
│   ├── m_mysql3356_adduser.sh
│   ├── m_mysql3356_setup.sh
│   ├── mysql-5.5.34.tar.gz
│   └── mysql-5.6.34.tar.gz
└── tasks
    ├── main.yaml

 

—–testmysql.yaml

– name: test
  hosts: test
  remote_user: root
  roles:
    – m_mysql

 

——m_mysql\tasks\main.yaml

– name: cp tar5.5
  copy: src=mysql-5.5.34.tar.gz dest=/tmp
– name: cp tar5.6
  copy: src=mysql-5.6.34.tar.gz dest=/tmp
– name: cp 3355
  copy: src=m_mysql3355_setup.sh dest=/tmp mode=700
– name: cp 3355 add usre
  copy: src=m_mysql3355_adduser.sh dest=/tmp mode=700
– name: cp 3356
  copy: src=m_mysql3356_setup.sh dest=/tmp mode=700
– name: cp 3356 add user
  copy: src=m_mysql3356_adduser.sh dest=/tmp mode=700
#开始二进制安装
– name: exec m_mysql3355_setup.sh
  shell: /tmp/m_mysql3355_setup.sh
– name: exec m_mysql3356_setup.sh
  shell: /tmp/m_mysql3356_setup.sh
#开始启动授权
– name: start m_mysql3355
  shell: cd /usr/mysqlsoft_3355 && ./bin/mysqld_safe –user=mysql &
– name: start m_mysql3356
  shell: cd /usr/mysqlsoft_3356 && ./bin/mysqld_safe –user=mysql &
– name: sleep 2
  shell: sleep 2
– name: exec m_mysql3355_adduser.sh
  shell: /tmp/m_mysql3355_adduser.sh
– name: exec m_mysql3356_adduser.sh
  shell: /tmp/m_mysql3356_adduser.sh
– name: delete sh
  shell: rm -rf /tmp/*.sh

 

各脚本内容

———\m_mysql\files\m_mysql3355_setup.sh

 

#!/bin/bash
yum -y install gcc gcc-c++ make cmake automake autoconf libxml2 libxml2-devel zlib zlib-devel ncurses ncurses-devel
yum -y install libaio libaio-devel

groupadd mysql
useradd mysql -g mysql

rm -rf /usr/mysqlsoft_3355/*
rm -rf /usr/mysqldata/3355/*
mkdir /usr/mysqlsoft_3355
mkdir -p /usr/mysqldata/3355
mkdir -p /usr/mysqlsoft_3355/etc
touch /usr/mysqldata/3355/install3355.log
chown -R mysql:mysql  /usr/mysqlsoft_3355
chown -R mysql:mysql  /usr/mysqldata/3355

cd /usr/mysqlsoft_3355
cp /tmp/mysql-5.5.34.tar.gz .
tar -zxf mysql-5.5.34.tar.gz
cd mysql-5.5.34

cmake \
-DCMAKE_INSTALL_PREFIX=/usr/mysqlsoft_3355 \
-DMYSQL_DATADIR=/usr/mysqldata/3355 \
-DSYSCONFDIR=/usr/mysqlsoft_3355/etc \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/tmp/mysql3355.sock \
-DMYSQL_TCP_PORT=3355 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci

make && make install >> /usr/mysqldata/3355/install3355.log

rm -rf /etc/my.cnf
rm -rf /usr/mysqlsoft_3355/etc/my.cnf

cp /usr/mysqlsoft_3355/support-files/my-large.cnf /usr/mysqlsoft_3355/etc/my.cnf

cd /usr/mysqlsoft_3355
/usr/mysqlsoft_3355/scripts/mysql_install_db –user=mysql –datadir=/usr/mysqldata/3355/
#/usr/mysqlsoft_3355/bin/mysqladmin -umysql -pmysql -S /tmp/mysql3355.sock shutdown

 

———\m_mysql\files\

#!/bin/bash
/usr/mysqlsoft_3355/bin/mysql -u root  -S /tmp/mysql3355.sock << EOF
use mysql;
grant shutdown on *.* to mysql@’localhost’ identified by ‘mysql’;
flush privileges;
EOF

image

文章出自:CCIE那点事 http://www.jdccie.com/ 版权所有。本站文章除注明出处外,皆为作者原创文章,可自由引用,但请注明来源。 禁止全文转载。
本文链接:http://www.jdccie.com/?p=3726转载请注明转自CCIE那点事
如果喜欢:点此订阅本站
  • 相关文章
  • 为您推荐
  • 各种观点