centos 下 mysql 主从库搭建
作者:蘑菇 日期:2010-04-22 00:51
今天在本本上装了个mysql主从库配置,中间遇到了几个问题,不过经过搜寻资料,已经可以正常工作了。
过程写下来做个记录:
因为上次已经装过LNMP,所以只要再装一个mysql做从库就好了。重新编译mysql安装
$ tar -zxvf mysql-5.1.45.tar.gz
$ cd mysql-5.1.45
$ ./configure --prefix=/usr/local/mysql_slave --enable-assembler --with-charset=utf8 --with-extra-charsets=all --enable-thread-safe-client --with-big-tables --with-readline --with-embedded-server --with-ssl -enable-local-infile
$ make && make install
$ cd ..
$ mkdir /usr/local/mysql_slave/var
$ chown -R mysql:mysql /usr/local/mysql_slave/var
$ chgrp -R mysql /usr/local/mysql_slave
#发现/usr/local/mysql_slave/var/下的mysql和test的组均为root,修改其属组
$ chgrp -R mysql /usr/local/mysql_slave
#修改my.cnf位置
$ cp /usr/local/mysql_slave/share/mysql/my-medium.cnf /etc/my-slave.cnf
$ vi /etc/my-slave.cnf
$ :s/3306/3308/g
$ :s/tmp\/mysql.sock/tmp\/mysql-slave.sock/g
$ /usr/local/mysql_slave/bin/mysqld_safe --defaults-file=/etc/my-slave.cnf --user=mysql &
$ /usr/local/mysql_slave/bin/mysqladmin -uroot password 123456
配置主从库:
#创建mysql日志目录
$ mkdir /var/log/mysql
$ chown -R mysql:mysql /var/log/mysql
[vi /etc/my.cnf]
server-id=1
log_bin=/var/log/mysql/mysql-bin.log
binlog_do_db=test
binlog_ignore_db=mysql
[vi /etc/my-slave.cnf]
server-id=2
master-host=127.0.0.1
master-user=slave_usr
master-password=123456
master-port=3306
replicate-do-db=test
#启动测试:
$ /etc/init.d/mysql start
$ mysql -uroot -p123456
mysql > grant replication slave on *.* to 'slave_usr'@'127.0.0.1' identified by '123456';
mysql > exit;
$
$ /usr/local/mysql_slave/bin/mysqld_safe --defaults-file=/etc/my-slave.cnf --user=mysql &
$
#进入主库创建表
$ mysql -uroot -p123456
mysql > use test;
mysql > create table test(`id` int primary key auto_increment, `introtext` text);
mysql > exit;
$ mysql -uroot -p123456 -P3308 -h127.0.0.1
mysql > use test;
mysql > desc test;
我们会发现从库里创建了一个和主库一样的表。成功!
但是还有以下几个问题:
1.把/usr/local/mysql_slave/share/mysql/mysql.server拷贝到/etc/init.d/mysql-slave,但是无法用/etc/init.d/mysql-slave start启动从库。我改了pid,socket,datadir,basedir,启动也加了--defaults-file,但是没有成功,还要继续检查。
2.登录从库时必须加-h127.0.0.1,不知道怎么去掉这个选项。
ubuntu 安装 dnsmasq 解决网速慢的问题
作者:蘑菇 日期:2010-04-21 13:41
先安装dnsmasq,我们用它来做DNS缓存,因为ubuntu慢的原因大部分在域名解析上。
sudo apt-get install dnsmasq
然后我们编辑dnsmasq的配置文件:
sudo vi /etc/dnsmasq.conf
找到这一行,修改为
resolv-file=/etc/resolv.dnsmasq.conf
确保我们的/etc/resolv.conf里的DNS信息正确,然后执行
sudo cp /etc/resolv.conf /etc/resolv.dnsmasq.conf
然后将/etc/resolv.conf里的DNS改为127.0.0.1
nameserver 127.0.0.1
如果我们是adsl上网的话,要修改一下/etc/ppp/peers/dsl-provider,以免/etc/resolv.conf的内容被它覆盖。
//注释下面这句
#usepeerdns
然后我们重启dnsmasq服务。
sudo /etc/init.d/dnsmasq restart
再试试吧,效果显著。
数据结构 之 直接插入排序
作者:蘑菇 日期:2010-04-21 02:01
- <?php
- $array = array(13,15,6,10,20,6,3,19);
- $count = count($array);
- $n = $e = 0;
- for($i = 1; $i < $count; $i++)
- {
- $tmp = $array[$i];
- $j = $i;
- while($array[$j-1] > $tmp){
- $n++;
- $e++;
- $array[$j] = $array[$j-1];
- $j--;
- }
- $array[$j] = $tmp;
- }
- print_r($array);
- echo "共循环{$n}次,共执行{$e}次数据交换";
- ?>
执行结果为:
- Array ( [0] => 3 [1] => 6 [2] => 6 [3] => 10 [4] => 13 [5] => 15 [6] => 19 [7] => 20 )
- 共循环15次,共执行15次数据交换
数据结构 之 冒泡法排序
作者:蘑菇 日期:2010-04-21 01:44
- <?php
- $array = array(13,15,6,10,20,6,3,19);
- $count = count($array);
- $n = $e = 0;
- for($i = 0; $i < $count; $i++)
- {
- for($j = $i + 1; $j < $count; $j++)
- {
- $n++;
- if($array[$j] < $array[$i]){
- $e++;
- $tmp = $array[$i];
- $array[$i] = $array[$j];
- $array[$j] = $tmp;
- }
- }
- }
- print_r($array);
- echo "共循环{$n}次,共执行{$e}次数据交换";
- ?>
执行结果为:
- Array ( [0] => 3 [1] => 6 [2] => 6 [3] => 10 [4] => 13 [5] => 15 [6] => 19 [7] => 20 )
- 共循环28次,共执行14次数据交换
数据结构 之 简单选择排序
作者:蘑菇 日期:2010-04-21 01:38
- <?php
- $array = array(13,15,6,10,20,6,3,19);
- $count = count($array);
- $n = $e = 0;
- for($i = 1; $i < $count; $i++)
- {
- //find the min item from $i to last
- $min_index = $i;
- for($j = $i+1; $j < $count; $j++)
- {
- $n++;
- if($array[$j] < $array[$min_index]) $min_index = $j;
- }
- if($array[$min_index] < $array[$i-1])
- {
- $e++;
- $tmp = $array[$i-1];
- $array[$i-1] = $array[$min_index];
- $array[$min_index] = $tmp;
- }
- }
- print_r($array);
- echo "共循环{$n}次,共执行{$e}次数据交换";
- ?>
执行结果为:
- Array ( [0] => 3 [1] => 6 [2] => 6 [3] => 10 [4] => 13 [5] => 15 [6] => 19 [7] => 20 )
- 共循环21次,共执行5次数据交换

