Ansible-playbook实现 Centos8 二进制安装MariaDB-10.4.21

1. playbook.yaml

- hosts: mariadb
  remote_user: root
  gather_facts: no
  vars:
    mariadb_file: mariadb-10.4.21-linux-systemd-x86_64

  tasks:
  - name: Ansible delete file /etc/yum.repos.d/*.repo
    find:
      paths: /etc/yum.repos.d/
      patterns: "*.repo"
    register: repos_to_del
  - name: yum repo file clean
    file: 
      path: "{{ item.path }}"
      state: absent
    with_items: "{{ repos_to_del.files }}"
  - name: copy repo file to remote
    copy:
      src: centos8.repo
      dest: /etc/yum.repos.d/
  - name: yum repo init
    mount:
      path: /media
      src: /dev/sr0
      fstype: iso9660
      opts: ro,noauto
      state: mounted
  - name: install packages
    yum:
      name:
        - libncurses* 
        - lrzsz 
      state: present
  - name: Extract {{ mariadb_file }} into /usr/local/
    unarchive:
     src: ./{{ mariadb_file }}.tar.gz
     dest: /usr/local/
  - name: Ensure group "mysql" exists
    group:
      name: mysql
      state: present
      gid: 306
  - name: Add the user 'mysql' with a specific uid and a primary group of 'mysql'
    user:
      name: mysql
      comment: mysql
      uid: 306
      group: mysql
  - name: Create mariadb symbolic link
    file:
      src: /usr/local/{{ mariadb_file }}/
      dest: /usr/local/mysql
      owner: mysql
      group: mysql
      state: link
  - name: Create a directory if it does not exist
    file:
      path: /data/binlog
      state: directory
      mode: '0755'
      owner: mysql
      group: mysql
  - name: Create a directory if it does not exist
    file:
      path: /etc/my.cnf.d
      state: directory
      mode: '0755'
      owner: mysql
      group: mysql
  - name: Create Datafiles
    shell: /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data
  - name: Recursively change ownership of a directory
    file:
      path: /usr/local/{{ mariadb_file }}/
      state: directory
      recurse: yes
      owner: mysql
      group: mysql
  - name: Copy Configfiles
    copy: 
      src: ./my.cnf
      dest: /etc/my.cnf
      remote_src: no
    notify: restart mysqld service
  - name: Copy PATH Configfiles
    copy:
      src: ./mysql.sh
      dest: /etc/profile.d/mysql.sh
      mode: '0644'
  - name: Copy Configfiles2
    copy:
      src: /usr/local/mysql/support-files/mysql.server
      dest: /etc/init.d/mysqld
      mode: '0755'
      remote_src: yes
  - name: Replace mysqld systemd file
    replace:
      path: /etc/init.d/mysqld
      regexp: '^(basedir=)$'
      replace: '\1/usr/local/mysql'
  - name: Replace mysqld systemd file2
    replace:
      path: /etc/init.d/mysqld
      regexp: '^(datadir=)$'
      replace: '\1/data'
  - name: Config Mariadb configfiles
    shell: export PATH=/usr/local/mysql/bin:$PATH
  - name: add systemctl mysqld
    shell: chkconfig --add mysqld

  handlers:
    - name: restart mysqld service
      service:
        name: mysqld
        state: started
        enabled: yes

2. hosts

[mariadb]
192.168.31.61

3.centos8.repo

[BaseOS]
name=CentOS Linux 8
baseurl=file:///media/BaseOS
gpgcheck=0
enabled=1

[AppStream]
name=AppStream
baseurl=file:///media/AppStream
enabled=1
gpgcheck=0

4.my.cnf

[mysqld]
basedir=/usr/local/mysql
datadir=/data
port=3306
socket=/usr/local/mysql/mysql.sock
pid-file=/usr/local/mysql/mysql.pid
[client]
socket=/usr/local/mysql/mysql.sock

5.mysql.sh

PATH=/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

6. mariadb-10.4.21-linux-systemd-x86_64.tar.gz

https://mariadb.org/download/

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值