English Sentence Loading...
英语句子加载中...
预览模式: 普通 | 列表

centos 下 mysql 主从库搭建

今天在本本上装了个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 解决网速慢的问题

我的系统是Ubuntu-9.10,平时看其他同事用的电脑上网都没有问题,但是我的总是很慢,于是上网找了一个解决办法,果然奏效。

先安装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

再试试吧,效果显著。
标签: ubuntu linux

数据结构 之 直接插入排序

  1. <?php
  2.     $array = array(13,15,6,10,20,6,3,19);
  3.     $count = count($array);
  4.     $n = $e = 0;
  5.     for($i = 1; $i < $count; $i++)
  6.     {
  7.         $tmp = $array[$i];
  8.         $j = $i;
  9.         while($array[$j-1] > $tmp){
  10.             $n++;
  11.             $e++;
  12.             $array[$j] = $array[$j-1];
  13.             $j--;
  14.         }
  15.         $array[$j] = $tmp;
  16.     }
  17.     print_r($array);
  18.     echo "共循环{$n}次,共执行{$e}次数据交换";
  19. ?>


执行结果为:
  1. Array ( [0] => 3 [1] => 6 [2] => 6 [3] => 10 [4] => 13 [5] => 15 [6] => 19 [7] => 20 )
  2. 共循环15次,共执行15次数据交换

数据结构 之 冒泡法排序

  1. <?php
  2.     $array = array(13,15,6,10,20,6,3,19);
  3.     $count = count($array);
  4.     $n = $e = 0;
  5.     for($i = 0; $i < $count; $i++)
  6.     {
  7.             for($j = $i + 1; $j < $count; $j++)
  8.             {
  9.                 $n++;
  10.                 if($array[$j] < $array[$i]){
  11.                     $e++;
  12.                     $tmp = $array[$i];
  13.                     $array[$i] = $array[$j];
  14.                     $array[$j] = $tmp;  
  15.                 }  
  16.             }
  17.     }
  18.     print_r($array);
  19.     echo "共循环{$n}次,共执行{$e}次数据交换";
  20. ?>

执行结果为:
  1. Array ( [0] => 3 [1] => 6 [2] => 6 [3] => 10 [4] => 13 [5] => 15 [6] => 19 [7] => 20 )
  2. 共循环28次,共执行14次数据交换

数据结构 之 简单选择排序

  1. <?php
  2.     $array = array(13,15,6,10,20,6,3,19);
  3.     $count = count($array);
  4.     $n = $e = 0;
  5.     for($i = 1; $i < $count; $i++)
  6.     {
  7.         //find the min item from $i to last
  8.         $min_index = $i;
  9.         for($j = $i+1; $j < $count; $j++)
  10.         {
  11.             $n++;
  12.             if($array[$j] < $array[$min_index]) $min_index = $j;
  13.         }
  14.       
  15.         if($array[$min_index] < $array[$i-1])
  16.         {
  17.             $e++;
  18.         $tmp = $array[$i-1];
  19.         $array[$i-1] = $array[$min_index];
  20.         $array[$min_index] = $tmp;
  21.         }
  22.     }
  23.     print_r($array);
  24.     echo "共循环{$n}次,共执行{$e}次数据交换";
  25. ?>


执行结果为:
  1. Array ( [0] => 3 [1] => 6 [2] => 6 [3] => 10 [4] => 13 [5] => 15 [6] => 19 [7] => 20 )
  2. 共循环21次,共执行5次数据交换