一看必會系列:ansible 自動部署mysql多實例

來源:本站原創 Linux, mysql_mariadb 超過1,282 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 [email protected]’localhost’ identified by ‘mysql’;
flush privileges;
EOF

image

文章出自:CCIE那點事 http://www.qdxgqk.live/ 版權所有。本站文章除注明出處外,皆為作者原創文章,可自由引用,但請注明來源。 禁止全文轉載。
本文鏈接:http://www.qdxgqk.live/?p=3726轉載請注明轉自CCIE那點事
如果喜歡:點此訂閱本站
?
?
萌宠夺宝游戏