Skip to content

Commit

Permalink
new file: mysql_master_install/README.md
Browse files Browse the repository at this point in the history
	new file:   mysql_master_install/mysql_master_install.yml
	new file:   mysql_master_install/roles/common/handlers/main.yml
	new file:   mysql_master_install/roles/common/meta/main.yml
	new file:   mysql_master_install/roles/common/tasks/main.yml
	new file:   mysql_master_install/roles/mysql_master_install/files/mysql.tar.gz
	new file:   mysql_master_install/roles/mysql_master_install/meta/main.yml
	new file:   mysql_master_install/roles/mysql_master_install/tasks/copy.yml
	new file:   mysql_master_install/roles/mysql_master_install/tasks/delete.yml
	new file:   mysql_master_install/roles/mysql_master_install/tasks/install.yml
	new file:   mysql_master_install/roles/mysql_master_install/tasks/main.yml
	new file:   mysql_master_install/roles/mysql_master_install/templates/11.sh
	new file:   mysql_master_install/roles/mysql_master_install/templates/create_master_slave.sh
	new file:   mysql_master_install/roles/mysql_master_install/templates/install_mysql.sh
	new file:   mysql_master_install/roles/mysql_master_install/templates/my.cnf
	new file:   mysql_master_install/roles/mysql_master_install/templates/mysql_security.sh
	new file:   mysql_master_install/roles/mysql_master_install/templates/mysqld
	new file:   mysql_master_install/roles/mysql_master_install/vars/main.yml
	new file:   mysql_slave_install/README.md
	new file:   mysql_slave_install/mysql_slave_install.yml
	new file:   mysql_slave_install/roles/common/handlers/main.yml
	new file:   mysql_slave_install/roles/common/meta/main.yml
	new file:   mysql_slave_install/roles/common/tasks/main.yml
	new file:   mysql_slave_install/roles/mysql_slave_install/files/mysql.tar.gz
	new file:   mysql_slave_install/roles/mysql_slave_install/meta/main.yml
	new file:   mysql_slave_install/roles/mysql_slave_install/tasks/copy.yml
	new file:   mysql_slave_install/roles/mysql_slave_install/tasks/delete.yml
	new file:   mysql_slave_install/roles/mysql_slave_install/tasks/install.yml
	new file:   mysql_slave_install/roles/mysql_slave_install/tasks/main.yml
	new file:   mysql_slave_install/roles/mysql_slave_install/templates/create_master_slave.sh
	new file:   mysql_slave_install/roles/mysql_slave_install/templates/install_mysql.sh
	new file:   mysql_slave_install/roles/mysql_slave_install/templates/my.cnf
	new file:   mysql_slave_install/roles/mysql_slave_install/templates/mysql_security.sh
	new file:   mysql_slave_install/roles/mysql_slave_install/templates/mysqld
	new file:   mysql_slave_install/roles/mysql_slave_install/vars/main.yml
  • Loading branch information
denglei committed Mar 5, 2015
1 parent c79bc71 commit 0aa9b7e
Show file tree
Hide file tree
Showing 35 changed files with 1,256 additions and 0 deletions.
1 change: 1 addition & 0 deletions mysql_master_install/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
本文介绍使用ansible的playbook功能在centos或者redhat 6系列系统里安装5.5.21版本mysql master.
7 changes: 7 additions & 0 deletions mysql_master_install/mysql_master_install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- hosts: "{{host}}"
remote_user: "{{user}}"
gather_facts: True
roles:
- common
- mysql_master_install
2 changes: 2 additions & 0 deletions mysql_master_install/roles/common/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- name: restart ntpd
service: name=ntpd state=restarted
16 changes: 16 additions & 0 deletions mysql_master_install/roles/common/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
galaxy_info:
author: Deng Lei
description: Install initializtion Software
license: MIT
min_ansible_version: 1.6
platforms:
- name: CentOS
versions:
- 5
- 6
- name: Ubuntu
versions:
- precise
categories:
- system
dependencies: []
3 changes: 3 additions & 0 deletions mysql_master_install/roles/common/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- name: Install initializtion require software
shell: yum -y install make cmake bc gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-devel libidn libidn-devel openssl openssl-devel nss_ldap openldap openldap-devel openldap-clients openldap-servers libxslt-devel libevent-devel ntp libtool-ltdl bison libtool vim-enhanced tar wget readline-devel libyaml-devel patch telnet lrzsz sysstat screen parted rsync libselinux-python dmidecode ntpdate sar
poll: 0
Binary file not shown.
12 changes: 12 additions & 0 deletions mysql_master_install/roles/mysql_master_install/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
galaxy_info:
author: Deng Lei
description: Install Mysql Master
license: MIT
min_ansible_version: 1.6
platforms:
- name: CentOS
versions:
- 6
categories:
- Service
dependencies: []
18 changes: 18 additions & 0 deletions mysql_master_install/roles/mysql_master_install/tasks/copy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
- name: Copy Mysql Software To Redhat Client
copy: src=mysql.tar.gz dest=/tmp/mysql.tar.gz owner=root group=root
when: ansible_os_family == "RedHat" and ansible_distribution_version|int >=6
- name: Create Mysql User In Redhat Client
user: name={{ mysql_user }} state=present createhome=no shell=/sbin/nologin
when: ansible_os_family == "RedHat" and ansible_distribution_version|int >=6 and ansible_distribution_version|int >=6
- name: Copy Mysql Start Script To Redhat Client
template: src=mysqld dest=/etc/init.d/mysqld owner=root group=root mode=0755
when: ansible_os_family == "RedHat" and ansible_distribution_version|int >=6
- name: Copy Install Mysql Script To Redhat Client
template: src=install_mysql.sh dest=/tmp/ owner=root group=root mode=0755
when: ansible_os_family == "RedHat" and ansible_distribution_version|int >=6
- name: Copy Mysql Config To Redhat Client
template: src=my.cnf dest=/tmp/ owner=root group=root mode=0644
when: ansible_os_family == "RedHat" and ansible_distribution_version|int >=6
- name: Copy Mysql Security Script To Redhat Client
template: src=mysql_security.sh dest=/tmp/ owner=root group=root mode=0755
when: ansible_os_family == "RedHat" and ansible_distribution_version|int >=6
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- name: Delete Mysql compression Software In Redhat Client
shell: rm -rf /tmp/mysql.tar.gz /tmp/mysql_security.sh
when: ansible_os_family == "RedHat" and ansible_distribution_version|int >=6
41 changes: 41 additions & 0 deletions mysql_master_install/roles/mysql_master_install/tasks/install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
- name: Create Mysql Install Dir
file: dest={{ mysql_dir }} state=directory
when: ansible_os_family == "RedHat" and ansible_distribution_version|int >=6
- name: Uncompression Mysql Software To Redhat Client
shell: tar zxf /tmp/mysql.tar.gz -C {{ mysql_dir }}
when: ansible_os_family == "RedHat" and ansible_distribution_version|int >=6
- name: Modify Mysql Dir Permission In Redhat Client
file: path={{ item }} owner={{ mysql_user }} group={{ mysql_user }} mode=0755
with_items:
- "{{ mysql_datadir }}"
- "{{ mysql_basedir }}"
when: ansible_os_family == "RedHat" and ansible_distribution_version|int >=6
- name: Install Mysql Script In Redhat Client
shell: /bin/bash /tmp/install_mysql.sh
when: ansible_os_family == "RedHat" and ansible_distribution_version|int >=6
- name: Wait Untils Mysql Service Avaiable In Redhat Client
shell: "{{ mysql_basedir }}/bin/mysql -h localhost -u {{ mysql_database_user }} -P {{ mysql_port }} -S {{ mysql_sock }} -e 'show databases;' && echo 'ok' || echo 'work'"
register: result
until: result.stdout.find("ok") != -1
retries: 20
delay: 5
when: ansible_os_family == "RedHat" and ansible_distribution_version|int >=6
- name: Start Myql Security Script In Redhat Client
shell: "/bin/bash /tmp/mysql_security.sh && echo 'ok' || echo 'work'"
register: run_result
until: run_result.stdout.find("ok") != -1
retries: 10
delay: 5
when: ansible_os_family == "RedHat" and ansible_distribution_version|int >=6
- name: Add Boot Start Mysql Service In Redhat Client
shell: chkconfig --level 345 mysqld on
when: ansible_os_family == "RedHat" and ansible_distribution_version|int >=6
- name: Copy Mysql Create Slave Script To Redhat Client
template: src=create_master_slave.sh dest=/tmp/ owner=root group=root mode=0755
when: ansible_os_family == "RedHat" and ansible_distribution_version|int >=6
- name: Create Mysql Master And Slave In redhat Client
shell: /bin/bash /tmp/create_master_slave.sh
when: ansible_os_family == "RedHat" and ansible_distribution_version|int >=6
- name: Delete Create Mysql Master And Slave Script In redhat Client
shell: rm -rf /tmp/create_master_slave.sh
when: ansible_os_family == "RedHat" and ansible_distribution_version|int >=6
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- include: copy.yml
- include: install.yml
- include: delete.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
{{ mysql_basedir }}/bin/mysql -h localhost -u {{ mysql_database_user }} -P {{ mysql_port }} -S {{ mysql_sock }} -e "grant all privileges on *.* to {{ mysql_database_user }}@'localhost' identified by '{{ mysql_passwd }}' with grant option;"
{{ mysql_basedir }}/bin/mysql -h localhost -u {{ mysql_database_user }} -P {{ mysql_port }} -S {{ mysql_sock }} -e "grant PROCESS,REPLICATION CLIENT ON *.* TO 'zabbix'@'%' identified BY 'zabbix';"
{{ mysql_basedir }}/bin/mysql -h localhost -u {{ mysql_database_user }} -P {{ mysql_port }} -S {{ mysql_sock }} -e "flush privileges;"
{{ mysql_basedir }}/bin/mysql -h localhost -u {{ mysql_database_user }} -P {{ mysql_port }} -S {{ mysql_sock }} -e "delete from mysql.user where password='';"
{{ mysql_basedir }}/bin/mysql -h localhost -u {{ mysql_database_user }} -P {{ mysql_port }} -S {{ mysql_sock }} -e "drop database test;"
{{ mysql_basedir }}/bin/mysql -h localhost -u {{ mysql_database_user }} -P {{ mysql_port }} -S {{ mysql_sock }} -e "flush privileges;"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
#1. grant user for slave in master
{{ mysql_basedir }}/bin/mysql -h localhost -u {{ mysql_database_user }} -P {{ mysql_port }} -p{{ mysql_passwd }} -e "grant all on *.* to {{ mysql_database_user }}@'{{ mysql_slave_ip }}' identified by '{{ mysql_passwd }}' with grant option;"
{{ mysql_basedir }}/bin/mysql -h localhost -u {{ mysql_database_user }} -P {{ mysql_port }} -p{{ mysql_passwd }} -e "flush privileges;"
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
mv /tmp/my.cnf {{ mysql_datadir }}/my.cnf
chown -R {{ mysql_user }}:{{ mysql_user }} {{ mysql_datadir }} {{ mysql_basedir }}
###init mysql db###"
{{ mysql_basedir }}/scripts/mysql_install_db --defaults-file={{ mysql_datadir }}/my.cnf --basedir={{ mysql_basedir }} --datadir={{ mysql_datadir }} --user={{ mysql_user }} >> /dev/null 2>&1 &

/etc/init.d/mysqld start &
ln -s {{ mysql_basedir }}/bin/mysql /usr/bin/mysql
ln -s {{ mysql_sock }} /tmp/mysql.sock
chkconfig --add mysqld
check_mysql=$(ps aux|grep mysql|grep -v grep|grep -v ansible|wc -l)
rm -rf /tmp/$(basename $0)
87 changes: 87 additions & 0 deletions mysql_master_install/roles/mysql_master_install/templates/my.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
[client]
port = {{ mysql_port }}
socket = {{ mysql_sock }}

[mysqld]
character-set-server = utf8
bind-address = {{ ansible_default_ipv4.address }}
port = {{ mysql_port }}
socket = {{ mysql_sock }}
basedir = {{ mysql_basedir }}
datadir = {{ mysql_datadir }}
log-error = {{ mysql_datadir }}/mysql-error.log
pid-file = {{ mysql_datadir }}/mysql.pid
log-bin = {{ mysql_datadir }}/mysql-bin
skip-external-locking
skip-name-resolve
skip-symbolic-links
server-id = {{ ansible_default_ipv4.address.split('.')[3] }}
binlog_format=mixed
binlog_cache_size=64M
max_binlog_cache_size=128M
max_binlog_size=1G
expire_logs_days=7

key_buffer_size = 384M
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 16M
join_buffer_size = 2M
thread_cache_size = 32
thread_concurrency = 16

interactive_timeout = 120
wait_timeout = 120

table_cache = 4069
table_open_cache = 512
open_files_limit = 10240
back_log=600

max_connections = 5000
max_connect_errors = 5000
max_allowed_packet = 16M
tmp_table_size = 256M
max_heap_table_size = 512M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 64M
myisam_repair_threads =1
myisam_recover

long_query_time = 2
slow_query_log
slow_query_log_file = {{ mysql_datadir }}/slow.log

innodb_additional_mem_pool_size = 64M
{% set memory=ansible_memtotal_mb/1024/2 %}
innodb_buffer_pool_size = {{ memory | round |int }}G
innodb_data_file_path = ibdata1:2G:autoextend
innodb_data_home_dir = {{ mysql_datadir }}
innodb_log_group_home_dir = {{ mysql_datadir }}
innodb_file_io_threads = 4
innodb_thread_concurrency = 8
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 256M
innodb_log_file_size = 512M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = 1
innodb_support_xa=0
innodb_flush_method = O_DIRECT

[mysqldump]
quick
max_allowed_packet = 512M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 512M
sort_buffer_size = 512M
read_buffer = 8M
write_buffer = 8M

[mysqlhotcopy]
interactive-timeout
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
{{ mysql_basedir }}/bin/mysql -h localhost -u {{ mysql_database_user }} -P {{ mysql_port }} -S {{ mysql_sock }} -e "grant all privileges on *.* to {{ mysql_database_user }}@'{{ ansible_default_ipv4.address }}' identified by '{{ mysql_passwd }}' with grant option;"
{{ mysql_basedir }}/bin/mysql -h localhost -u {{ mysql_database_user }} -P {{ mysql_port }} -S {{ mysql_sock }} -e "grant PROCESS,REPLICATION CLIENT ON *.* TO 'zabbix'@'%' identified BY 'zabbix';"
{{ mysql_basedir }}/bin/mysql -h localhost -u {{ mysql_database_user }} -P {{ mysql_port }} -S {{ mysql_sock }} -e "flush privileges;"
{{ mysql_basedir }}/bin/mysql -h localhost -u {{ mysql_database_user }} -P {{ mysql_port }} -S {{ mysql_sock }} -e "drop database test;"
{{ mysql_basedir }}/bin/mysql -h localhost -u {{ mysql_database_user }} -P {{ mysql_port }} -S {{ mysql_sock }} -e "update mysql.user set password=password('{{ mysql_passwd }}') where user='{{ mysql_database_user }}' and host='localhost';"
{{ mysql_basedir }}/bin/mysql -h localhost -u {{ mysql_database_user }} -P {{ mysql_port }} -S {{ mysql_sock }} -e "delete from mysql.user where password='';"
{{ mysql_basedir }}/bin/mysql -h localhost -u {{ mysql_database_user }} -P {{ mysql_port }} -S {{ mysql_sock }} -e "flush privileges;"
Loading

0 comments on commit 0aa9b7e

Please sign in to comment.