Latest posts.

使用密钥来登录ssh-免密码输入

第一步:生成密匙对,我用的是rsa的密钥。使用命令 ”ssh-keygen -t rsa”

   [user1@rh user1]$ ssh-keygen -t rsa

   Generating public/private rsa key pair.

   Enter file in which to save the key (/home/user1/.ssh/id_rsa):

   Created directory '/home/user1/.ssh'.

   Enter passphrase (empty for no passphrase):

   Enter same passphrase again:

   Your identification has been saved in /home/user1/.ssh/id_rsa.

   Your public key has been saved in /home/user1/.ssh/id_rsa.pub.

   The key fingerprint is:

   e0:f0:3b:d3:0a:3d:da:42:01:6a:61:2f:6c:a0:c6:e7 user1@rh.test.com

   [user1@rh user1]$

生成的过程中提示输入密钥对保存位置,直接回车,接受默认值就行了。接着会提示输入一 

个不同于你的password的密码,直接回车,让它空着。当然,也可以输入一个
其中公共密钥保存在 ~/.ssh/id_rsa.pub
私有密钥保存在 ~/.ssh/id_rsa

之后把这个密钥对中的公共密钥复制到你要访问的机器上去,并保存为

~/.ssh/authorized_keys.

   [user1@rh user1]$ scp ~/.ssh/id_rsa.pub rh1:/home/user1/.ssh/authorized_keys

   user1@rh1's password:

   id_rsa.pub                                    100%  228     3.2MB/s   00:00

至此完成。登录不用密码了

mysql添加一个复制用户

grant replication slave on *.* to repluser1@192.168.8.126 identified by ‘111111′;

又一个sysbench for mysql监控的文摘

第一步,准备测试数据。

[root@node1 ~]# sysbench –test=oltp –oltp-table-size=1000000 –mysql-table-engine=myisam –mysql-db=test –mysql-socket=/opt/mysql1/data/mysql.sock –mysql-user=root prepare
sysbench 0.4.12:  multi-threaded system evaluation benchmarkNo DB drivers specified, using mysql
Creating table ’sbtest’…
Creating 1000000 records in table ’sbtest’…

同时,在另一个窗口使用vmstat去关注cpu idle、context switch,一些必要参数的变化,随时掌握系统的运行状况。

vmstat_sysbench1

第二步,20个用户同时并发500000条查询请求,对测试表sbtest进行只读操作。执行完成总时间大概26分钟左右,执行中最长的一次操作接近9分钟,还有结果中95%这个指标我们也会关注。

[root@node1 ~]# sysbench –num-threads=20 –max-requests=500000 –test=oltp –oltp-table-size=1000000 –mysql-db=test –mysql-socket=/opt/mysql1/data/mysql.sock –mysql-user=root –oltp-read-only run
sysbench 0.4.12:  multi-threaded system evaluation benchmarkNo DB drivers specified, using mysql
Running the test with following options:
Number of threads: 20Doing OLTP test.
Running mixed OLTP test
Doing read-only test
Using Special distribution (12 iterations,  1 pct of values are returned in 75 pct cases)
Using “LOCK TABLES READ” for starting transactions
Using auto_inc on the id column
Maximum number of requests for OLTP test is limited to 500000
Threads started!
Done.OLTP test statistics:
queries performed:
read:                            7000112
write:                           0
other:                           1000016
total:                           8000128
transactions:                        500008 (322.15 per sec.)
deadlocks:                           0      (0.00 per sec.)
read/write requests:                 7000112 (4510.14 per sec.)
other operations:                    1000016 (644.31 per sec.)Test execution summary:
total time:                          1552.0822s
total number of events:              500008
total time taken by event execution: 31034.2430
per-request statistics:
min:                                  3.56ms
avg:                                 62.07ms
max:                                521.56ms
approx.  95 percentile:              95.59msThreads fairness:
events (avg/stddev):           25000.4000/61.39
execution time (avg/stddev):   1551.7121/0.16

通过vmstat监测,会发现cpu空闲保持在34%上下,context switch的速度在每秒29000左右。

vmstat_sysbench2

下面是用strace这个工具去监测sysbench的执行,你可以看到从fd3到fd22一共20并发请求的执行状况。

strace1

********************************omit**********************************

strace2

mysqld_multi管理启动多个mysql进程

mysqlmanager的管理方式貌似在慢慢被遗忘,现流行用mysqld_multi来管理多个实例:

配置文件:  my.cnf

[mysqld_multi]
mysqld = /usr/bin/mysqld_safe
mysqladmin = /usr/bin/mysqladmin
user = root
password = defage
[mysqld1]
datadir=/opt/data1
socket=/opt/data1/mysql.sock
pid-file=/opt/data1/mysql1.pid
log=/opt/data1/mysql1.log
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1

default-character-set=utf8

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[mysqld2]
datadir=/opt/data2
socket=/opt/data2/mysql.sock
pid-file=/opt/data2/mysql2.pid
log=/opt/data2/mysql2.log
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
port=3307

default-character-set=utf8

[mysqld3]
datadir=/opt/data3
socket=/opt/data3/mysql.sock
pid-file=/opt/data3/mysql3.pid
log=/opt/data3/mysql3.log
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
port=3308

default-character-set=utf8

启动:

mysqld_multi  –config-file=/etc/my.cnf     start  1 ;只启动第一个mysql服务,相关文件由my.cnf中mysql1设定。

mysqld_multi   –config-file=/etc/my.cnf start 1-4,启动 第1至4mysql服务

sysbench 测试mysql

安装sysbench:
tar zxvf sysbench-4.12
cd sysbench-4.12
./configure –prefix=/usr/local/sysbench -with-mysql-includes=/usr/local/mysql/include/mysql –with-mysql-libs=/usr/local/mysql/lib/mysql
make && make install
出现这个错误是没有指定相应的–with-mysql-includes和–with-mysql-libs目录.找到正确的目录从新编译。
3、make的时候出现
../libtool: line 2412: Xsysbench: command not found
../libtool: line 2547: X-lmysqlclient_r: command not found
../libtool: line 2547: X-lz: command not found
../libtool: line 2547: X-lcrypt: command not found

只要先运行一次./autogen.sh,然后再configure,make就可以了.autogen.sh文件在sysbench-4.12解压目录下的.

1 、准备数据
#sysbench –debug=off –test=oltp –mysql-host=127.0.0.1 –mysql-user=root –mysql-password=defage –oltp-table-size=1000000 –mysql-db=test –oltp-table-name=stest –num-threads=20 –max-requests=10000 –oltp-auto-inc=off –mysql-engine-trx=yes –db-driver=mysql –mysql-port=3307 prepare

2、测试
# sysbench –debug=off –test=oltp –mysql-host=10.15.2.137 –mysql-user=test –mysql-password=test –oltp-table-size=1000000 –mysql-db=test –oltp-table-name=stest –num-threads=20 –max-requests=10000 –oltp-auto-inc=off –mysql-engine-trx=yes run

3、删除数据
# sysbench –debug=off –test=oltp –mysql-host=10.15.2.137 –mysql-user=test –mysql-password=test –oltp-table-size=1000000 –mysql-db=test –oltp-table-name=stest –num-threads=20 –max-requests=10000 –oltp-auto-inc=off –mysql-engine-trx=yes cleanup

提示错误:sysbench 0.4.10:  multi-threaded system evaluation benchmark

FATAL: no database driver specified
FATAL: failed to initialize database driver!

则是sysbench没有指定对应的数据库driver,在上面的命令后加参数  –db-driver=mysql即可