Ansible-playbook批量安装MariaDB-10.3

Ansible-playbook批量安装MariaDB-10.3
准备:
MrariaDB10.3二进制包仓库:

[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.3/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

把二进制压缩包下载下来,解压放在files文件里
目录结构如下:

创建用户,组,家目录:
cat create_group.yml

- name: create group
  group: name=mysql system=yes gid=336

cat create_user.yml

- 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.yml

- 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.yml

- 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.yml

- 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.yml

- 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分钟。
服务已经启动,端口正常监听,安全加固脚本已经执行

转载于:https://blog.51cto.com/13182370/2386322

你可能感兴趣的:(Ansible-playbook批量安装MariaDB-10.3)