去官方网站下mysql的repo文件:
https://dev.mysql.com/downloads/repo/yum/
[
root@nfs-server ~]# rpm -ivh mysql80-community-release-el7-6.noarch.rpm
警告:mysql80-community-release-el7-6.noarch.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql80-community-release-el7-6 ################################# [100%]
[root@nfs-server ~]# cd /etc/yum.repos.d/
[root@nfs-server yum.repos.d]# ls
CentOS-Base.repo CentOS-fasttrack.repo CentOS-Vault.repo mysql-community.repo
CentOS-CR.repo CentOS-Media.repo CentOS-x86_64-kernel.repo mysql-community-source.repo
CentOS-Debuginfo.repo CentOS-Sources.repo mysql-community-debuginfo.repo nginx.repo
安装sysbench所需要的依赖软件
automake、libtool 、 mysql-community-devel
[root@nfs-server yum.repos.d]# yum -y install automake libtool
[root@nfs-server yum.repos.d]# yum -y install mysql-community-devel
使用localinstall去安装下载好的rpm包
[root@nfs-server packages]# yum localinstall mysql-community-*
[root@nfs-server packages]# ls
mysql-community-client-plugins-8.0.30-1.el7.x86_64.rpm mysql-community-libs-8.0.30-1.el7.x86_64.rpm
mysql-community-common-8.0.30-1.el7.x86_64.rpm mysql-community-libs-compat-8.0.30-1.el7.x86_64.rpm
mysql-community-devel-8.0.30-1.el7.x86_64.rpm
[root@nfs-server packages]# pwd
/var/cache/yum/x86_64/7/mysql80-community/packages
使用香港的服务器去下载sysbench的源码包
wget https://github.com/akopytov/sysbench/archive/1.0.15.tar.gz
因为在国内,可能****(下不了),我是用了香港的服务器下,很快。然后直接用Xtfp传输过来。
[root@nfs-server sysbench]# tar xf 1.0.15.tar.gz
[root@nfs-server sysbench]# ls
1.0.15.tar.gz sysbench-1.0.15
[root@nfs-server sysbench]# cd sysbench-1.0.15/
[root@nfs-server sysbench-1.0.15]# ls
autogen.sh configure.ac doc Makefile.am README.md rpm src
ChangeLog COPYING install-sh missing README-Oracle.md scripts tests
config debian m4 mkinstalldirs README-WIN.txt snap third_party
[root@nfs-server sysbench-1.0.15]# ./configure
[root@nfs-server sysbench-1.0.15]# make -j 2
[root@nfs-server sysbench-1.0.15]# make install
[root@nfs-server sysbench-1.0.15]# which sysbench
/usr/local/bin/sysbench
使用epel-release源去安装sysbench
[root@nfs-server ~]# yum install epel-release -y
[root@nfs-server ~]# yum install sysbench -y
需要提前在数据库里新建sbtest的库
[root@sc-slave ~]# mysql -uwrite -p'Jiangda123#' -h 192.168.1.151 -P 7001
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 5.7.37-log MySQL Community Server (GPL)
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
write@(none) 15:38 mysql>create database sbtest;
Query OK, 1 row affected (0.00 sec)
测试连接中间件服务器的时候,一定要去连接写的端口7002,不然会导致写数据到从服务器上,因为有2个从服务器,会轮询调度到不同的机器,会出现找不到数据库。使用写的账号连接,不然会没有权限去写入数据。
[root@nfs-server src]# sysbench --mysql-host=192.168.1.150 --mysql-port=7002 --mysql-user=write --mysql-password='Jiangda123#' /root/sysbench/sysbench-1.0.15/src/lua/oltp_common.lua --tables=10 --table_size=10000 prepare
sysbench 1.0.15 (using bundled LuaJIT 2.1.0-beta2)
Creating table 'sbtest1'...
Inserting 10000 records into 'sbtest1'
Creating a secondary index on 'sbtest1'...
Creating table 'sbtest2'...
Inserting 10000 records into 'sbtest2'
Creating a secondary index on 'sbtest2'...
Creating table 'sbtest3'...
Inserting 10000 records into 'sbtest3'
Creating a secondary index on 'sbtest3'...
Creating table 'sbtest4'...
Inserting 10000 records into 'sbtest4'
Creating a secondary index on 'sbtest4'...
Creating table 'sbtest5'...
Inserting 10000 records into 'sbtest5'
Creating a secondary index on 'sbtest5'...
Creating table 'sbtest6'...
Inserting 10000 records into 'sbtest6'
Creating a secondary index on 'sbtest6'...
Creating table 'sbtest7'...
Inserting 10000 records into 'sbtest7'
Creating a secondary index on 'sbtest7'...
Creating table 'sbtest8'...
Inserting 10000 records into 'sbtest8'
Creating a secondary index on 'sbtest8'...
Creating table 'sbtest9'...
Inserting 10000 records into 'sbtest9'
Creating a secondary index on 'sbtest9'...
Creating table 'sbtest10'...
Inserting 10000 records into 'sbtest10'
Creating a secondary index on 'sbtest10'...
[root@nfs-server src]# sysbench --mysql-host=192.168.1.150 --mysql-port=7002 --mysql-user=write --mysql-password='Jiangda123#' /root/sysbench/sysbench-1.0.15/src/lua/oltp_common.lua --tables=10 --table_size=10000 run
sysbench 1.0.15 (using bundled LuaJIT 2.1.0-beta2)
Running the test with following options:
Number of threads: 4
Report intermediate results every 5 second(s)
Initializing random number generator from current time
Initializing worker threads...
Threads started!
[ 5s ] thds: 4 tps: 109.14 qps: 2203.91 (r/w/o: 1545.10/113.33/545.48) lat (ms,95%): 80.03 err/s: 0.80 reconn/s: 0.00
[ 10s ] thds: 4 tps: 118.69 qps: 2378.68 (r/w/o: 1665.31/129.08/584.28) lat (ms,95%): 68.05 err/s: 0.00 reconn/s: 0.00
[ 15s ] thds: 4 tps: 97.94 qps: 1955.49 (r/w/o: 1368.22/114.73/472.53) lat (ms,95%): 80.03 err/s: 0.00 reconn/s: 0.00
[ 20s ] thds: 4 tps: 102.79 qps: 2055.78 (r/w/o: 1438.64/121.59/495.55) lat (ms,95%): 73.13 err/s: 0.00 reconn/s: 0.00
SQL statistics:
queries performed:
read: 30128
write: 2399
other: 10505
total: 43032
transactions: 2148 (107.02 per sec.)
queries: 43032 (2144.06 per sec.)
ignored errors: 4 (0.20 per sec.)
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 20.0665s
total number of events: 2148
Latency (ms):
min: 7.18
avg: 37.29
max: 232.38
95th percentile: 74.46
sum: 80104.43
Threads fairness:
events (avg/stddev): 537.0000/158.50
execution time (avg/stddev): 20.0261/0.02
[root@nfs-server src]#
1.下载源码包,解压安装
wget http://imysql.com/wp-content/uploads/2014/09/tpcc-mysql-src.tgz
tar xf tpcc-mysql-src.tar
cd tpcc-mysql/src
make
之后会生成两个二进制工具tpcc_load(提供初始化数据的功能)和tpcc_start(进行压力测试)
[root@nfs-server src]# cd ..
[root@nfs-server tpcc-mysql]# ls
add_fkey_idx.sql drop_cons.sql schema2 tpcc_load
count.sql load.sh scripts tpcc_start
create_table.sql README src
2.tpcc测试前准备,初始化数据库
在其他的服务器上连接到读写分离器上创建tpcc库
需要在测试的服务器上创建tpcc的库
[root@jd-slave ~]# mysqladmin -uwrite -p'Jiangda123#' -h 192.168.1.151 -P 7002 create tpcc
需要导入表到tpcc库里
需要将tpcc的create_table.sql 和add_fkey_idx.sql 远程拷贝到master服务器上
[root@nfs-server tpcc-mysql]# ls
add_fkey_idx.sql count.sql create_table.sql drop_cons.sql load.sh README schema2 scripts src tpcc_load tpcc_start
[root@nfs-server tpcc-mysql]# pwd
/root/sysbench/tpcc-mysql
[root@nfs-server tpcc-mysql]# scp create_table.sql add_fkey_idx.sql [email protected]:/root
[email protected]'s password:
create_table.sql 100% 3105 1.1MB/s 00:00
add_fkey_idx.sql 100% 1621 607.2KB/s 00:00
然后在master服务器上导入create_table.sql 和add_fkey_idx.sql 文件
mysql -uroot 'Jiangda123#' tpcc <create_table.sql
mysql -uroot 'Jiangda123#' tpcc <add_fkey_idx.sql
在测试服务器上执行脚本tpcc_load 去测试
3.加载数据
注意:server是要测试的服务器,db,user,password也是要测的服务器上mysql的信息
#./tpcc_load --help
./tpcc_load [server] [db] [user] [password] [warehouse]
服务器名 数据库名 用户名 密码 仓库数量
例如:
#./tpcc_load localhost tpcc root xxx 150
真实测试中,数据库仓库一般不少于100个,如果配置了ssd,建议最少不低于1000个
[root@nfs-server tpcc-mysql]# ./tpcc_load 192.168.1.151:7002 tpcc write Jiangda123# 150
*************************************
*** ###easy### TPC-C Data Loader ***
*************************************
<Parameters>
[server]: 192.168.2.151
[port]: 7002
[DBname]: tpcc
[user]: write
[pass]: Jiangda123#
[warehouse]: 150
TPCC Data Load Started...
Loading Item
4.进行测试
注意:server等信息与步骤4中保持一致
#./tpcc_start --help
tpcc_start -h [server_host] -P [port] -d [database_name] -u [mysql_user] -p [mysql_password] -w [warehouses] -c [connections] -r [warmup_time] -l [running_time] -i [report_interval] -f [report_file] -t [trx] - > out1
各个参数用法如下:
-h server_host: 服务器名
-P port : 端口号,默认为3306
-d database_name: 数据库名
-u mysql_user : 用户名
-p mysql_password : 密码
-w warehouses: 仓库的数量
-c connections : 线程数,默认为1
-r warmup_time : 热身时间,单位:s,默认为10s , 热身是为了将数据加载到内存。(真实测试中建议热身时间不低于5分钟)
-l running_time: 测试时间,单位:s,默认为20s
-i report_interval: 指定生成报告间隔时长(真实测试中不低于30min)
-f report_file: 测试结果输出文件(一般命名为xxx.log)
-t trx:输出文件
- > out1: 将控制台输出存入文件out1中
例如:
./tpcc_start -h 192.168.1.151 -p 7002 -d tpcc -u write -p Jiangda123# -w 150 -c 12 -r 300 -l 360 -f test0.log -t test1.log - >test0.out