Ansible-playbook批量安裝MariaDB-10.3
準備:
MrariaDB10.3二進制包倉庫:mysql
[mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.3/centos7-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1
把二進制壓縮包下載下來,解壓放在files文件裏
目錄結構以下:
sql
建立用戶,組,家目錄:
cat create_group.ymlshell
- name: create group group: name=mysql system=yes gid=336
cat create_user.ymlcentos
- name: create user user: name=mysql uid=336 group=mysql shell=/sbin/nologin system=yes create_home=no home=/data/mysql
cat dir_home.yml安全
- name: mysql file: path=/data/mysql state=directory - name: chown shell: chown -R mysql:mysql /data/mysql
cat install.ymlide
- name: install mariadb synchronize: src=files/mysql dest=/usr/local - name: chown shell: chown -R root:root /usr/local/mysql
cat dir_configre.yml測試
- name: create /etc/mysql file: path=/etc/mysql state=directory - name: my.cnf template: src=my.cnf.j2 dest=/etc/mysql/my.cnf
cat gen_db.ymlui
- name: gendb shell: chdir=/usr/local/mysql ./scripts/mysql_install_db --datadir=/data/mysql --user=mysql - name: chown shell: chown -R mysql:mysql /data/mysql
cat service.ymlurl
- name: init.d/mysqld copy: src=files/mysql/support-files/mysql.server dest=/etc/rc.d/init.d/mysqld mode=755 - name: enabled shell: chkconfig --add mysqld - name: start mysqld shell: service mysqld start
cat add_path.ymlcentos7
- name: add PATH shell: echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
cat secure.yml
- name: trans secure.txt copy: src=files/secure.txt dest=/usr/local/mysql/bin - name: chdir shell: chdir=/usr/local/mysql/bin ./mysql_secure_installation < secure.txt
cat secure.txt
y centos centos y y y y
cat main.yml
- include: add_path.yml - include: create_group.yml - include: create_user.yml - include: dir_home.yml - include: install.yml - include: dir_configre.yml - include: gen_db.yml - include: service.yml - include: add_path.yml - include: secure.yml
cat role-mysql.yml
--- - hosts: 172.22.5.6 remote_user: root roles: - role: mysql
先用一臺設備安裝測試一下:172.22.5.6
---記錄一下安裝時間:
start 2019/4/28 20:50
end 20:55:12.312359安裝一臺大概花費5分鐘。服務已經啓動,端口正常監聽,安全加固腳本已經執行完