一、安裝
yum install gcc gcc-c++ autoconf automake make libtool bzr mysql-devel mysql libaio-devel
yum remove mariadb.x86_64 mariadb-devel.x86_64
sh install-mysql.sh --install=mysql --innodbbufferpoolsize=2G --datadir=/mysql/data --password=123321 --binlogdir=/mysql/binlog --id=1
sh install-mysql.sh --start=mysql --datadir=/mysql/data --password=123321 --slaveof=10.xx.xx.157
unzip sysbench-1.0.zip?
cd ?sysbench-1.0/
# ./autogen.sh?
./configure --prefix=/usr --mandir=/usr/share/man --without-mysql
make -j
make install
修改sysbench相關配置
sudo sh -c 'for x in /sys/class/net/eth0/queues/rx-*;do echo f>$x/rps_cpus;done'
sudo sh -c 'echo 36728>/proc/sys/net/core/rps_sock_flow_entries '
sudo sh -c 'echo 4096>/sys/class/net/eth0/queues/rx-0/rps_flow_cnt'
sudo sh -c 'for x in /sys/class/net/bond0/queues/rx-*;do echo f>$x/rps_cpus;done'
sudo sh -c 'echo 36728>/proc/sys/net/core/rps_sock_flow_entries '
sudo sh -c 'echo 4096>/sys/class/net/bond0/queues/rx-0/rps_flow_cnt'
臨時調整 ulimit 65535
測試完成后,需要再系統層做一些清理的工作
shell>sync #刷新臟數據到磁盤
shell>echo 3 >/proc/sys/vm/drop_cache #清除cache
echo 3 > /proc/sys/vm/drop_caches
shell>swapoff -a && swapon -a 釋放swap
3.壓測過程中需要修改參數max_prepared_stmt_count默認為16382,修改為65536
4.如果是SSD硬盤的話,innodb_io_capacity和innodb_io_capacity_max兩個參數也要相應調大,建議調整到50000
二、使用
sysbench fileio?
--file-test-mode值說明(prepare run 必須一致):
seqwr順序寫入。
seqrewr順序重寫。
seqrd順序讀取。
rndrd隨機讀取。?
rndwr隨機寫入。?
rndrw混合隨機讀/寫
--file-io-mode
sync同步
async異步
mmap
2.1CPU
sysbench --test=cpu --cpu-max-prime=2000 run
2.2內存
4C8G 帶80GB數據盤1個,邏輯掛載/mysql
sysbench --db-driver=mysql --mysql-host=10.xx.xx.157 --mysql-port=3306 ?--mysql-user=root --mysql-password=123321 ?--mysql-db=mypartition --table_size=25000 --table=250 --events=0 --timeout=600 oltp_read_write prepare
sysbench --db-driver=mysql --mysql-host=10.xx.xx.157 --mysql-port=3306 ?--mysql-user=root --mysql-password=123321 ?--mysql-db=mypartition --table_size=25000 --table=250 --events=0 --timeout=600 --threads=16 --percentile=95 --report-interval=1 oltp_read_write run
sysbench --db-driver=mysql --mysql-host=10.xx.xx.157 --mysql-port=3306 ?--mysql-user=root --mysql-password=123321 ?--mysql-db=mypartition --table_size=25000 --table=250 --events=0 --timeout=600 --threads=16 --percentile=95 ?oltp_read_write ?cleanup
2.3磁盤IO
sysbench --db-driver=mysql --mysql-host=192.168.X.X --mysql-port=3306 ?--mysql-user=root --mysql-password=123321 ?--mysql-db=mypartition --table_size=800000 --table=150 --events=0 --timeout=600 oltp_read_write prepare
sysbench --db-driver=mysql --mysql-host=192.168.X.X --mysql-port=3306 ?--mysql-user=root --mysql-password=123321 ?--mysql-db=mypartition --table_size=800000 --table=150 ?--events=0 --timeout=600 --threads=16 --percentile=95 --report-interval=1 oltp_read_write run
sysbench --db-driver=mysql --mysql-host=192.168.X.X --mysql-port=3306 ?--mysql-user=root --mysql-password=123321 ?--mysql-db=mypartition --table_size=800000 --table=150 --events=0 --timeout=600 --threads=16 --percentile=95 ?oltp_read_write ?cleanup
2.4?線程
sysbench ?--test=threads --num-threads=500 --thread-yields=100 --thread-locks=4 run
2.5oltp
1,prepare階段,生成需要的測試表
sysbench --test=oltp --mysql-table-engine=innodb --mysql-host=192.168.X.X --mysql-db=test --oltp-table-size=500000 --mysql-user=root --mysql-password=123321 prepare
2,run階段
sysbench --num-threads=16 --test=oltp --mysql-table-engine=innodb --mysql-host=192.168.x.x --mysql-db=test --oltp-table-size=500000 --mysql-user=root --mysql-password=123321 run
3,清理測試時生成的測試表
sysbench --num-threads=16 --test=oltp --mysql-table-engine=innodb --mysql-host=192.168.x.x --mysql-db=test --oltp-table-size=500000 --mysql-user=root --mysql-password=123321 cleanup
2.6
sysbench fileio --time=120 --threads=16 --file-test-mode=seqwr --file-io-mode=async --file-num=40 --file-block-size=16384 --file-total-size=20G --file-fsync-freq=100 --file-fsync-all=off --file-fsync-end=on --file-merged-requests=0 --file-rw-ratio=1 run
sysbench fileio --time=120 --threads=16 --file-test-mode=rndrw --file-io-mode=async --file-num=40 --file-block-size=16384 --file-total-size=20G --file-fsync-freq=100 --file-fsync-all=off --file-fsync-end=on --file-merged-requests=0 --file-rw-ratio=1.5 run
三、結果解析
File operations:
? ? reads/s: ? ? ? ? ? ? ? ? ? ? ?0.00 #每秒讀次數
? ? writes/s: ? ? ? ? ? ? ? ? ? ? 20850.83#每秒寫次數
? ? fsyncs/s: ? ? ? ? ? ? ? ? ? ? 8340.85#每秒從內存向磁盤同步的次數
/io類型測試
Throughput: #吞吐量
? ? read, MiB/s: ? ? ? ? ? ? ? ? ?0.00
? ? written, MiB/s: ? ? ? ? ? ? ? 325.79
/cpu類型測試
CPU speed: events per second: 4500.61 #每秒創建 events 數量
General statistics:
? ? total time: ? ? ? ? ? ? ? ? ? ? ? ? ?60.0105s # --time 執行測試的時間
? ? total number of events: ? ? ? ? ? ? ?1752371 ?#總共創建的 events 數量
Latency (ms):
? ? ? ? ?min: ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?0.01 #最小執行時間
? ? ? ? ?avg: ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?0.03
? ? ? ? ?max: ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 10.71
? ? ? ? ?95th percentile: ? ? ? ? ? ? ? ? ? ? ? ?0.05#95% events 執行時間
? ? ? ? ?sum: ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?59314.03#總時間
Threads fairness:#?與線程相關的指標
? ? events (avg/stddev): ? ? ? ? ? 1752371.0000/0.00?#?事件(平均值/偏差)
? ? execution time (avg/stddev): ? 59.3140/0.00#?執行時間(平均值/偏差)
四、其他
忘記密碼:
1./etc/my.cnf的[mysqld]中添加skip-grant-tables
2.重啟mysql
3.mysql
>use mysql;(使用mysql數據庫)
>update user set password=password("你的密碼") where user="root";
>flush privileges;
>quit
4.編輯my.cnf,去掉剛才添加的內容,然后重啟MySQL
獲取臨時密碼:
mysqld --no-defaults --user=mysql --datadir=/mysql/data --initialize