兩台測試機192.168.0.182和192.168.0.183,root賬号登陸,centos系統
1.分别配置hostname:
vi /etc/sysconfig/network
兩台分别配置 HOSTNAME=centos-182 和 HOSTNAME=centos-183
2.分别配置本地host解析:
vi /etc/hosts 兩台配置一樣内容
192.168.0.182 centos-182
192.168.0.183 centos-183
3.分别配置ssh免密碼登陸:
ssh-keygen,輸出内容直接三個回車,在/root/.ssh/目錄下生成id_rsa和id_rsa.pub
cat id_rsa.pub >> authorized_keys
在192.168.0.183上執行
ssh-keygen,輸出内容直接三個回車,在/root/.ssh/目錄下生成id_rsa和id_rsa.pub
scp id_rsa.pub [email protected]:/root/.ssh/
在192.168.0.182的/root/.ssh/下
cat id_rsa.pub >> authorized_keys
chmod 600 authorized_keys
再将authorized_keys檔案scp到192.168.0.183上
scp authorized_keys [email protected]:/root/.ssh/
4.分别配置known_hosts:
在192.168.0.182和192.168.0.183上分别執行ssh centos-182 和 ssh centos-183,出現類似以下内容,輸入yes之後回車
The authenticity of host 'centos-182 (192.168.0.182)' can't be established.
RSA key fingerprint is 75:93:cd:ba:d3:d4:5a:70:8c:dd:4c:11:43:fe:b4:00.
Are you sure you want to continue connecting (yes/no)? yes
配置成功之後,在兩台機子上分别執行ssh centos-182 和 ssh centos-183,可以不用輸入密碼登陸上去說明配置成功。
5.在192.168.0.183上安裝MySQL資料庫,具體可以參見http://willvvv.iteye.com/blog/1460568
6.在192.168.0.182上安裝tsung,具體可以參見http://willvvv.iteye.com/blog/1469324
7.在192.168.0.182上編寫tsung腳本,進行測試
mkdir -p /root/.tsung
cd /root/.tsung
vi tsung.xml
<?xml version="1.0"?>
<!DOCTYPE tsung SYSTEM "/usr/local/share/tsung/tsung-1.0.dtd">
<tsung loglevel="debug" dumptraffic="true">
<clients>
<client host="localhost" use_controller_vm="true"/>
</clients>
<!-- Server side setup -->
<servers>
<server host="centos-183" port="3306" type="tcp"/>
</servers>
<monitoring>
<monitor host="centos-183"/>
</monitoring>
<load>
<arrivalphase phase="1" duration="1" unit="minute">
<users interarrival="3" unit="second"></users>
</arrivalphase>
</load>
<sessions>
<session probability="100" name="mysql-example" type="ts_mysql">
<request>
<mysql type="connect" />
</request>
<request>
<mysql type="authenticate" database="yourdb" username="youruser" password="yourpassword" />
</request>
<request>
<mysql type="sql">SHOW TABLES</mysql>
</request>
<request>
<mysql type="sql">SELECT * FROM yourtable</mysql>
</request>
<request>
<mysql type="close"></mysql>
</request>
</session>
</sessions>
</tsung>
注意:<server host="centos-183" port="3306" type="tcp"/> 和 <monitor host="centos-183"/> host屬性需要填寫配置的host而不是IP或者localhost
不然就會出現Host key verification failed
tsung start
8.在192.168.0.183上執行tcpdump檢視sql執行情況
tcpdump -i eth0 -s 0 -l -w - dst port 3306 | strings
9.執行完畢使用http://willvvv.iteye.com/blog/1469324上python啟動web server直接看圖形,注意iptables要開啟8000端口
![](https://img.laitimes.com/img/__Qf2AjLwojIjJCLyojI0JCLicmbw5SMykzYxczYhZDZ2ETLiZTMh1yM3M2MtQDM2YWLlRjZ3AjZlN2LcRjM4kzLcdjNwAzLcRnbl1GajFGd0F2LcRWYvxGc19CXt92YuUWelRXauwGZvw1LcpDc0RHaiojIsJye.png)