ansible-playbook编译安装mysql5.6

2021/6/1 19:50:57

本文主要是介绍ansible-playbook编译安装mysql5.6,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

git地址:
https://github.com/ledrsnet/my-ansible-example/tree/main/compile_mysql
目录结构:

[root@maple-c8-n1 compile_mysql]# tree
.
├── ansible.cfg
├── compileMysql.yml
├── hosts
└── roles
    └── mysql
        ├── files
        │   └── my.cnf
        ├── handlers
        │   └── main.yml
        ├── tasks
        │   ├── compile.yml
        │   ├── main.yml
        │   ├── postCompile.yml
        │   └── preCompile.yml
        ├── templates
        └── vars
            └── main.yml

7 directories, 10 files
[root@maple-c8-n1 compile_mysql]# cat compileMysql.yml
---
- hosts: dbservers
  remote_user: root
  gather_facts: no

  roles:
    - mysql

[root@maple-c8-n1 compile_mysql]# vim roles/mysql/tasks/main.yml 
- include: preCompile.yml
- include: compile.yml
- include: postCompile.yml


#编译前准备
[root@maple-c8-n1 compile_mysql]# cat roles/mysql/tasks/preCompile.yml    
- name: yum install Packages
  yum: 
    name: "{{ yum_pks }}" 
    state: present

- name: create mysql user
  user: name=mysql system=yes create_home=no home=/data/mysql shell=/sbin/nologin
- name: create mysql data dir
  file: path={{ mysql_data_path }} state=directory owner=mysql group=mysql
- name: download src code
  unarchive: src={{ url }}{{ mysql }} dest={{ src_store_path }} copy=no

#编译
[root@maple-c8-n1 compile_mysql]# cat roles/mysql/tasks/compile.yml 
- name: generate mysql makefile
  shell: 
    chdir: "{{ src_store_path }}{{ src_code_dir }}"
    cmd: cmake . -DCMAKE_INSTALL_PREFIX={{ install_path }} -DMYSQL_DATADIR=/data/mysql/ -DSYSCONFDIR=/etc/ -DMYSQL_USER=mysql -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITHOUT_MROONGA_STORAGE_ENGINE=1 -DWITH_DEBUG=0 -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_LIBWRAP=0 -DENABLED_LOCAL_INFILE=1 -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
- name: compile mysql
  make:
    chdir: "{{ src_store_path }}{{ src_code_dir }}"
    target: install
    file: "{{ src_store_path }}{{ src_code_dir }}/Makefile"

#编译后配置
[root@maple-c8-n1 compile_mysql]# cat roles/mysql/tasks/postCompile.yml 
- name: prepare Path Variable
  shell: echo 'PATH=/apps/mysql/bin:$PATH' > /etc/profile.d/mysql.sh &&  source /etc/profile.d/mysql.sh
- name: datastatus
  stat: path={{ mysql_data_path }}
  register: dataResult
- name: initdb
  shell:
    chdir: "{{ install_path }}"
    cmd: scripts/mysql_install_db --datadir={{ mysql_data_path }} --user=mysql
  when: dataResult.stat.exists!=true
- name: copy config
  copy: src=my.cnf dest=/etc/my.cnf
- name: copy service script
  shell: cp {{ install_path }}/support-files/mysql.server /etc/init.d/mysqld
- name: bootstrap Start mysqld
  shell: chkconfig --add mysqld
- name: start service mysqld
  shell: service mysqld start



这篇关于ansible-playbook编译安装mysql5.6的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程