编写二进制安装mariadb10.2的ansible-playbook剧本
今天帮一个同学修改剧本,说是跑不起来服务,中间报错,我就直接修改好放在这,以后供大家浏览看看,虽然写的一般,但是起码功能实现了,哈哈
做该实验起码先把mariadb-10.2.32.tar.gz包下载下来,大概441M。下载链接: wget https://mirrors.tuna.tsinghua.edu.cn/mariadb//mariadb-10.2.32/bintar-linux-x86_64/mariadb-10.2.32-linux-x86_64.tar.gz
编译安装mariadb-10.2.32
1.制作mysql的配置文件
[mysqld]
socket=/tmp/mysql.sock
user=mysql
symbolic-links=0
datadir=/data/mysql
innodb_file_per_table=1
log-bin
pid-file=/data/mysql/mysqld.pid
[client]
port=3306
socket=/tmp/mysql.sock
[mysqld_safe]
log-error=/var/log/mysqld.log
2、编写yml
[root@Centos8-2 ansible]$vim install_mariadb.yml
---
#Installing MariaDB Binary Tarballs
- hosts: mysql
remote_user: root
gather_facts: no
tasks:
- name: create group
group: name=mysql gid=27 system=yes
- name: create user
user: name=mysql uid=27 system=yes group=mysql shell=/sbin/nologin home=/data/mysql create_home=no
- name: mkdir datadir
file: path=/data/mysql owner=mysql group=mysql state=directory
- name: unarchive package
unarchive: src=/data/ansible/files/mariadb-10.2.32.tar.gz dest=/usr/local owner=root group=root
- name: move
shell: mv /usr/local/mariadb* /usr/local/mysql
- name: install database
shell: scripts/mysql_install_db --datadir=/data/mysql --user=mysql
args:
chdir: /usr/local/mysql
- name: config file
copy: src=/data/ansible/files/my.cnf dest=/etc/ backup=yes
- name: service script
shell: /bin/cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
- name: start service
service: name=mysqld state=started enabled=yes
- name: PATH variable
copy: content='PATH=/usr/local/mysql/bin:$PATH' dest=/etc/profile.d/mysql.sh
- name: source script
shell: source /etc/profile.d/mysql.sh
4.确认要复制文件的所在路径
[root@Centos8-2 ansible]$ls /data/ansible/files/
install_mariadb.yml mariadb-10.2.32.tar.gz my.cnf