Skip to content

Commit

Permalink
add complete testing examples
Browse files Browse the repository at this point in the history
  • Loading branch information
denglei committed Sep 2, 2014
1 parent dea221d commit df258ca
Show file tree
Hide file tree
Showing 53 changed files with 1,025 additions and 1 deletion.
1 change: 1 addition & 0 deletions complete_testing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
本文介绍使用ansible的playbook功能在centos或者redhat 6系列系统里安装percona 5.5.21版本mysql与tpcc测试mysql事物处理能力.
7 changes: 7 additions & 0 deletions complete_testing/complete_testing_delete.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- hosts: "{{host}}"
remote_user: "{{user}}"
gather_facts: True
roles:
- mysql_tpcc_delete
- mysql_delete
11 changes: 11 additions & 0 deletions complete_testing/complete_testing_install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
- hosts: "{{host}}"
remote_user: "{{user}}"
gather_facts: True
roles:
- common
- mysql_install
- mysql_tpcc_install
- sysbench_install
- fio_install
- complete_testing_install
2 changes: 2 additions & 0 deletions complete_testing/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 complete_testing/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: []
2 changes: 2 additions & 0 deletions complete_testing/roles/common/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- 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 dmidecode
12 changes: 12 additions & 0 deletions complete_testing/roles/complete_testing_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 Complete Testing
license: MIT
min_ansible_version: 1.6
platforms:
- name: CentOS
versions:
- 6
categories:
- Service
dependencies: []
15 changes: 15 additions & 0 deletions complete_testing/roles/complete_testing_install/tasks/install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
- name: Copy Complete Test Script To Redhat Client
connection: local
template: src=complete_testing.sh dest=/tmp/complete_testing.sh owner=root group=root mode=0755
when: ansible_os_family == "RedHat" and ansible_distribution_version|int >=6
tags: Onlytest
- name: Run Complete Test Script In Redhat Client
shell: /bin/bash /tmp/complete_testing.sh
connection: local
when: ansible_os_family == "RedHat" and ansible_distribution_version|int >=6
tags: Onlytest
- name: Delete Complete Test Script In Redhat Client
shell: rm -rf /tmp/complete_testing.sh
connection: local
when: ansible_os_family == "RedHat" and ansible_distribution_version|int >=6
tags: Onlytest
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- include: install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
time=`date +%Y%m%d%H%M`
#create complete testing temp dir
mkdir -p {{ complete_testing_temp_dir }} {{ complete_testing_dir }}
#copy tpcc test result
cd {{ tpcc_dir }}
`which cp` -a `ls -lrt |tail -n 1` {{ complete_testing_temp_dir }}
#copy sysbench test result
cd {{ sysbench_dir }}
`which cp` -a `ls -lrt|tail -n 4` {{ complete_testing_temp_dir }}
#copy fio test result
cd {{ fio_dir }}
`which cp` -a `ls -lrt|tail -n 1` {{ complete_testing_temp_dir }}
#grep tpcc test result
tpcc_result=`tail -n 1 {{ complete_testing_temp_dir }}/*tpcc* |awk '{print $1" "$2}'`
echo "Tpcc reslut is: $tpcc_result" >> {{ complete_testing_dir }}/{{ host }}_complete_testing_result-$time.log
#grep sysbench test result
cputest=`grep taken {{ complete_testing_temp_dir }}/*sysbench_cputest*`
echo "Sysbench cpu_test result is: $cputest" >> {{ complete_testing_dir }}/{{ host }}_complete_testing_result-$time.log
threads=`grep taken {{ complete_testing_temp_dir }}/*sysbench_threads*`
echo "Sysbench sysbench_threads result is: $threads" >> {{ complete_testing_dir }}/{{ host }}_complete_testing_result-$time.log
mutexxx=`grep taken {{ complete_testing_temp_dir }}/*sysbench_mutexxx*`
echo "Sysbench sysbench_mutexxx result is: $mutexxx" >> {{ complete_testing_dir }}/{{ host }}_complete_testing_result-$time.log
memory=`grep taken {{ complete_testing_temp_dir }}/*sysbench_memory*`
echo "Sysbench sysbench_memory result is: memory" >> {{ complete_testing_dir }}/{{ host }}_complete_testing_result-$time.log
#grep fio test result
fio=`grep iops {{ complete_testing_temp_dir }}/*fio*`
echo "Fio result is: $fio" >> {{ complete_testing_dir }}/{{ host }}_complete_testing_result-$time.log
rm -rf {{ complete_testing_temp_dir }}
2 changes: 2 additions & 0 deletions complete_testing/roles/complete_testing_install/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
complete_testing_temp_dir: /tmp/complete_testing_temp
complete_testing_dir: /tmp/complete_testing
2 changes: 2 additions & 0 deletions complete_testing/roles/fio_install/files/check_disk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
awk -v result=`df -h|egrep -Ev '(Filesystem|shm|boot|mapper|devtmpfs|/$)'|awk '{print $NF}'|head -n 1` 'BEGIN{if(result=="") {print "/tmp"} else {print result}}'
Binary file not shown.
12 changes: 12 additions & 0 deletions complete_testing/roles/fio_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 Fio
license: MIT
min_ansible_version: 1.6
platforms:
- name: CentOS
versions:
- 6
categories:
- Test
dependencies: []
50 changes: 50 additions & 0 deletions complete_testing/roles/fio_install/tasks/install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
- name: Install Fio Require Software To Redhat Client
yum: name=libaio-devel state=latest
when: ansible_os_family == "RedHat" and ansible_distribution_version|int >=6
tags: Only_install_fio
- name: Copy Fio Software To Redhat Client
copy: src={{ item }} dest=/tmp/{{ item }} owner=root group=root
with_items:
- fio-{{ fio_version }}.tar.gz
when: ansible_os_family == "RedHat" and ansible_distribution_version|int >=6
tags: Only_install_fio
- name: Uncompression Fio Software In Redhat Client
shell: tar zxf /tmp/fio-{{ fio_version }}.tar.gz -C /tmp/
ignore_errors: yes
when: ansible_os_family == "RedHat" and ansible_distribution_version|int >=6
tags: Only_install_fio
- name: Install Fio Software In Redhat Client
shell: "cd /tmp/fio-{{ fio_version }}; make && make install"
ignore_errors: yes
when: ansible_os_family == "RedHat" and ansible_distribution_version|int >=6
tags: Only_install_fio
- name: Delete Old Software In Redhat Client
shell: rm -rf /tmp/fio-{{ fio_version }}.tar.gz /tmp/fio-{{ fio_version }}
when: ansible_os_family == "RedHat" and ansible_distribution_version|int >=6
tags: Only_install_fio
- name: Get the current time In Redhat Client
command: date +%Y%m%d%H%M
register: time
when: ansible_os_family == "RedHat" and ansible_distribution_version|int >=6
tags: Onlytest
- name: Copy Test Disk Script In Redhat Client
copy: src=check_disk.sh dest=/tmp/check_disk.sh owner=root group=root mode=0755
when: ansible_os_family == "RedHat" and ansible_distribution_version|int >=6
tags: Onlytest
- name: Get Test Disk info In Redhat Client
shell: /bin/bash /tmp/check_disk.sh
register: test_disk
when: ansible_os_family == "RedHat" and ansible_distribution_version|int >=6
tags: Onlytest
- name: Start Fio Random Write And Read Test In Redhat Client
shell: /usr/local/bin/fio -filename={{ test_disk.stdout }}/{{ filename }} -direct={{ direct }} -iodepth {{ iodepth }} -thread -rw={{ rw }} -rwmixread={{ rwmixread }} -ioengine={{ ioengine }} -bs={{ bs }} -size={{ size }} -numjobs={{ numjobs }} -runtime={{ runtime }} -group_reporting -name={{ name }} -ioscheduler={{ ioscheduler }} --output=/tmp/{{ ansible_hostname }}-fio-{{ time.stdout }}.log
when: ansible_os_family == "RedHat" and ansible_distribution_version|int >=6
tags: Onlytest
- name: Copy Fio Test Result from Redhat Client
fetch: src=/tmp/{{ ansible_hostname }}-fio-{{ time.stdout }}.log dest={{ fio_dir }}/{{ host }}-fio-{{ time.stdout }}.log flat=yes
when: ansible_os_family == "RedHat" and ansible_distribution_version|int >=6
tags: Onlytest
- name: Delete Fio Test Log In Redhat Client
shell: rm -rf {{ test_disk.stdout }}/{{ filename }} /tmp/{{ ansible_hostname }}-fio-{{ time.stdout }}.log /tmp/check_disk.sh
when: ansible_os_family == "RedHat" and ansible_distribution_version|int >=6
tags: Onlytest
1 change: 1 addition & 0 deletions complete_testing/roles/fio_install/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- include: install.yml
14 changes: 14 additions & 0 deletions complete_testing/roles/fio_install/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
fio_dir: /tmp/fio_log
fio_version: 2.1.11
filename: random_write_read
direct: 1
iodepth: 1
rw: randrw
rwmixread: 70
ioengine: psync
bs: 16K
size: 2G
numjobs: 30
runtime: 1000
name: random_read_write
ioscheduler: noop
12 changes: 12 additions & 0 deletions complete_testing/roles/mysql_delete/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
galaxy_info:
author: Deng Lei
description: Delete Mysql
license: MIT
min_ansible_version: 1.6
platforms:
- name: CentOS
versions:
- 6
categories:
- Service
dependencies: []
18 changes: 18 additions & 0 deletions complete_testing/roles/mysql_delete/tasks/delete.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
- name: Stop Mysql Service
shell: /etc/init.d/mysqld stop
ignore_errors: yes
when: ansible_os_family == "RedHat" and ansible_distribution_version|int >=6
- name: Delete Mysql Boot Start Script
shell: chkconfig --del mysqld
ignore_errors: yes
when: ansible_os_family == "RedHat" and ansible_distribution_version|int >=6
- name: Delete Mysql Dir And Socket
shell: rm -rf {{ mysql_basedir }} {{ mysql_datadir }} /tmp/mysql.sock /usr/bin/mysql /usr/bin/mysql_config /data/mysql
when: ansible_os_family == "RedHat" and ansible_distribution_version|int >=6
- name: Delete Mysql User
shell: userdel {{ mysql_user }}
ignore_errors: yes
when: ansible_os_family == "RedHat" and ansible_distribution_version|int >=6
- name: Delete Mysql Service Start Script
shell: rm -rf /etc/init.d/mysqld
when: ansible_os_family == "RedHat" and ansible_distribution_version|int >=6
1 change: 1 addition & 0 deletions complete_testing/roles/mysql_delete/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- include: delete.yml
10 changes: 10 additions & 0 deletions complete_testing/roles/mysql_delete/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
mysql_basedir: /data/mysql/basedir
mysql_datadir: /data/mysql/datadir
mysql_user: mysql
mysql_database_user: root
mysql_passwd: 'E4yR3WnoluSFTCB'
mysql_port: 3306
mysql_sock: /data/mysql/datadir/mysql.sock
mysql_charset: utf8
mysql_collation: utf8_general_ci
mysql_version: Percona-Server-5.5.21-rel25.1.tar.gz
Binary file not shown.
12 changes: 12 additions & 0 deletions complete_testing/roles/mysql_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
license: MIT
min_ansible_version: 1.6
platforms:
- name: CentOS
versions:
- 6
categories:
- Service
dependencies: []
18 changes: 18 additions & 0 deletions complete_testing/roles/mysql_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
3 changes: 3 additions & 0 deletions complete_testing/roles/mysql_install/tasks/delete.yml
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
21 changes: 21 additions & 0 deletions complete_testing/roles/mysql_install/tasks/install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
- 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: Start Myql Security Script In Redhat Client
shell: /bin/bash /tmp/mysql_security.sh
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
3 changes: 3 additions & 0 deletions complete_testing/roles/mysql_install/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- include: copy.yml
- include: install.yml
- include: delete.yml
15 changes: 15 additions & 0 deletions complete_testing/roles/mysql_install/templates/install_mysql.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/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 &
rm -rf /usr/bin/mysql /usr/bin/mysql_config
ln -s {{ mysql_basedir }}/bin/mysql /usr/bin/mysql
ln -s {{ mysql_basedir }}/bin/mysql_config /usr/bin/mysql_config
ln -s {{ mysql_sock }} /tmp/mysql.sock
echo "{{ mysql_basedir }}/lib/" >>/etc/ld.so.conf
/sbin/ldconfig
chkconfig --add mysqld
rm -rf /tmp/$(basename $0)
Loading

0 comments on commit df258ca

Please sign in to comment.