存档

文章标签 ‘Linux’

mysql备份之mysqldump

2009年8月23日 baalchina 没有评论

mysqldump其实就是把mysql数据库dump成sql文件。速度相当快(当然,没有直接copy快..哈哈),兼容性好。sql语句嘛,通吃的。

最简单的dump:

/usr/local/mysql/bin/mysqldump --uroot --ppassword discuz cdb_members > /data/backup/members.sql

rsync --vzrtopg –progress  --delete rsync://ubuntu.srt.cn/ubuntu/ /cygdrive/L/mirror/ubuntu/

 

就是把discuz库的cdb_members表dump成members.sql文件。

mysqldump还有很多参数,常用的:

  • --opt,等同与添加--add-drop-table --add-locks --create-options --disable-keys --extended-insert --lock-tables --quick --set-charset这一堆参数
  • --lock-tables,锁表。dump的时候把这个表锁起来,保证的完整性。
  • --lock-all-tables,锁有的表,保证的完整性。

 

参考:

http://dev.mysql.com/doc/refman/5.0/en/mysqldump.html

分类: Linux, Mysql 标签: , ,

mysql的常用操作命令

2009年8月20日 baalchina 没有评论

检测并修复数据库

修复特定库(database)

/usr/local/mysql/bin/mysqlcheck -o -r database –uroot –ppassword

 

修复所有库

/usr/local/mysql/bin/mysqlcheck -A -o -r -uroot –ppassword

 

如果只修复特定表:

/usr/local/mysql/bin/mysqlcheck -c -r discuz cdb_ai -uroot –ppassword

 

 

备份数据库,mysqldump

参考:mysqldump的使用

分类: Linux, Mysql 标签: ,

Linux集群的安装与配置(Part II,配置)

2009年8月13日 baalchina 没有评论

Heartbeat的配置文件主要是3个,也就是前面我们cp到/etc/ha.d下面的ha.cfharesources以及authkeys,作用可以理解为系统配置,资源配置,以及认证的设置。一个个搞定。

 

ha.cf

配置比较简单,保证能跑起来

#logfile
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility     local0

#time setting
keepalive 2
deadtime 30
warntime 10
initdead 120

#network setting
udpport 694
bcast eth1
ucast eth1 192.168.100.2

#node setting
auto_failback on
node    linux-ha-a
node    linux-ha-b

我这边跑的是双网卡。其中eth1作为心跳线,配置了192.168.100.1/2两个地址。

haresources

最简配制的话其实就是一条:

 

#this is resource config
linux-ha-a 210.28.92.233 httpd::start

三段:

主机名,集群的ip,需要启动的服务::传递给这个服务的参数。

文件介绍上说两台设备的haresources要完全一样,你可别真的完全一样把主机名也一样了…哈。

 

 

authkeys

这个支持3种认证方式,sha1>md5>crc。其中前两种需要指定密钥。crc只做校验用,没认证的效果。这个文件需要保证600权限。

因为是测试就简单点了,用MD5,验证码用linux-ha的md5值(17bc50a13f1dd31c14f2a3f321e017dc)。实际上直接输入一个字符串就可以了,没必要输入md5的值。

 

注意这个类似于eigrp的认证,是支持多个key-chain的。

auth 1
#1 crc
#2 sha1 HI!
1 md5 17bc50a13f1dd31c14f2a3f321e017dc

注意auth 1必须对应下面的1 md5 key

 

检测效果/MAC切换机制

全部配置完成之后可以打开虚拟ip地址,网页可以打开,然后再关掉server-a的接口,然后再刷新,看看可否看到页面?

我做的时候没自动切换,结果跑到交换机上#clea ip arp 才有效…郁闷…注意这个MAC地址:

MAC:

210.xx.yy.231   0          0050.56af.15fd arpa   VL922
210.xx.yy.232   0          0050.56af.3842 arpa   VL922
210.xx.yy.233   0          0050.56af.3842 arpa   VL922

这时候232这台设备生效。233为虚拟MAC。

可以看到的是,ha并没有诸如HSRP/VRRP那样的虚拟MAC机制。而是直接用的设备的MAC。

你ssh到233,其实就是连接到232。

待解决

如果跑的是http,那么就要考虑共享存储的问题。静态的还好,如果是动态的呢?

如果是数据库,同样要考虑存储。不过mysql本身的cluster应该可以解决--据说是不用共享存储的。

分类: Cluster, Linux 标签: , ,

Linux集群的安装与配置(Part I,安装)

2009年8月11日 baalchina 没有评论

集群的作用有很多,比如HA(high availability),比如负载均衡等。我这里只做HA,保证可用性。

 

软件用的是开源的heartbeat,http://www.linux-ha.org

安装详解:

下载软件包:

#wget http://hg.linux-ha.org/lha-2.1/archive/STABLE-2.1.4.tar.bz2

 

解压编译并安装

 

 

#./ConfigureMe configure

#make

#make install

 

可能会少很多软件包,一个个打上就行了。我的CentOS 5.3,安装的时候自定义只选择开发工具,需要以下的包:

#yum install libnet
#yum install glib2-devel
#yum install libxml2-devel(这个没说,但是后面是需要的)

#yum install PyXML

 

另外需要注意的是,如果他告诉你缺某个包,你yum之后,重新make还是会报错的,需要重新./configure再make。这点比较诡异。

扫尾搞定配置文件

cp doc/ha.cf /etc/ha.d/
cp doc/haresources /etc/ha.d/
cp doc/authkeys /etc/ha.d/
cp ldirectord/ldirectord.cf /etc/ha.d/

 

服务的启动、停止等

 

/etc/rc.d/init.d/heartbeat start | stop | restert| status

 

安装的Troubleshooting

 

configure: WARNING: The following recommended components noted earlier are missing:
     uuid library, Python.h, security/pam_appl.h, gnutls/gnutls.h, gnutls/gnutls.h
    We will continue but you may have lost some non-critical functionality.
configure: error: The following required components noted earlier are missing:
     glib2-devel, libnet
    Please supply them and try again.

./bootstrap exiting due to error (sorry!).

这个是缺少包了。把几个包yum一下就行了。

题外话:

libnet也可以自己编译,这个比较诡异。

wget http://ncu.dl.sourceforge.net/project/libnet/libnet/0.10.11/libnet-0.10.11.tar.gz
cd libnet
cp makfiles/linux.mak port.mak(注意是makfile不是makefile啊)

 

#yum install hearbeat

提示如下:

Installing:
heartbeat               i386       2.1.3-3.el5.centos       extras       1.7 M
Installing for dependencies:
PyXML                   i386       0.8.4-4                  base         1.1 M
heartbeat-pils          i386       2.1.3-3.el5.centos       extras       213 k
heartbeat-stonith       i386       2.1.3-3.el5.centos       extras       311 k

原来是要PyXML这个包,注意大小写

 

接下来继续编译,安装
make又错:

cc1: warnings being treated as errors
xml.c: In function 'write_xml_file':
xml.c:635: warning: unused variable 'in'
xml.c: In function 'get_message_xml':
xml.c:775: error: 'BZ_OK' undeclared (first use in this function)
xml.c:775: error: (Each undeclared identifier is reported only once
xml.c:775: error: for each function it appears in.)
xml.c:796: warning: implicit declaration of function 'BZ2_bzBuffToBuffDecompress'
xml.c:799: error: 'BZ_OUTBUFF_FULL' undeclared (first use in this function)
gmake[3]: *** [xml.lo] 错误 1
gmake[3]: Leaving directory `/root/Heartbeat-STABLE-2-1-STABLE-2.1.4/lib/crm/common'
gmake[2]: *** [all-recursive] 错误 1
gmake[2]: Leaving directory `/root/Heartbeat-STABLE-2-1-STABLE-2.1.4/lib/crm'
gmake[1]: *** [all-recursive] 错误 1
gmake[1]: Leaving directory `/root/Heartbeat-STABLE-2-1-STABLE-2.1.4/lib'
make: *** [all-recursive] 错误 1

这个应该是bz报错,bz是什么?bzip2?

不管了

yum install bzip2-devel

继续

编译完成之后有这个提示:

chown hacluster /var/lib/heartbeat/cores/hacluster
chown: “hacluster”: 无效的用户
gmake[2]: [install-exec-local] 错误 1 (忽略)
chmod 700 /var/lib/heartbeat/cores/hacluster
cd /usr/lib/heartbeat;                          \
        for file in `ls /usr/share/heartbeat`;                  \
        do if [  -d $file ]; then continue; fi; \
                rm -f $file && ln -s /usr/share/heartbeat/$file .;      \
        done
gmake[2]: Nothing to be done for `install-data-am'.
gmake[2]: Leaving directory `/root/Heartbeat-STABLE-2-1-STABLE-2.1.4'
gmake[1]: Leaving directory `/root/Heartbeat-STABLE-2-1-STABLE-2.1.4'

注意用户问题哦。

 

 

[root@linux-ha-a ~]# /etc/rc.d/init.d/heartbeat start
logd is already running
Starting High-Availability services:
[失败]
heartbeat: udpport setting must precede media statementsheartbeat[20883]: 2009/08/13_06:26:00 ERROR: Invalid user id name [hacluster]
heartbeat[20883]: 2009/08/13_06:26:00 ERROR: Bad uid list [hacluster]
heartbeat[20883]: 2009/08/13_06:26:00 ERROR: Invalid apiauth directive [ipfail uid=hacluster]

这个就是结果啦。

解决方法:

useradd hacluster
groupadd haclient

chown hacluster /var/lib/heartbeat/cores/hacluster
chmod 700 /var/lib/heartbeat/cores/hacluster

 

这个报错:

heartbeat: udpport setting must precede media statementsheartbeat[21237]: 2009/08/13_06:39:21 ERROR: Auth Key [1] not found in keyfile [/etc/ha.d/authkeys]
heartbeat[21237]: 2009/08/13_06:39:21 ERROR: Authentication configuration error.
heartbeat[21237]: 2009/08/13_06:39:21 ERROR: Configuration error, heartbeat not started.

这个有点好玩,意思是udpport的设置必须在media设置之前。但是实际上是authkey报错造成的,解决方法就是正确配置authkey。

分类: Cluster, Linux 标签: , , ,

Linux下DNS/IP/主机名等的设定

2009年8月11日 baalchina 没有评论

其实很基础..但是老是忘记,记在这里。

 

DNS设置

vi /etc/resovl.conf

添加

nameserver 210.28.92.7

 

 

IP设置

其实最简单的方法就是运行setup了…不过作为专业人士,我们一定要用cli才显得拉风…

vi /etc/sysconfig/network-scripts/ifcfg-eth0

如果是双网卡,那么就是eth1,eth2…

照这个配置就可以了

DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
HWADDR=00:50:56:af:15:fd
NETMASK=255.255.255.0
IPADDR=192.168.1.100
GATEWAY=192.168.1.1

 

 

修改主机名

  1. #hostname newname
  2. #vi /etc/sysconfig/network
  3. #vi /etc/hosts
  4. #reboot
分类: Linux 标签: , , ,

Squid的设置(Part II,Troubleshooting,200100128)

2009年8月8日 baalchina 没有评论

WARNING: transparent proxying not supported

2009/08/03 08:22:07| WARNING: transparent proxying not supported

不支持透明代理.

Aug  7 11:20:29 cache squid[21884]:     Failed to verify one of the swap directories, Check cache.log   for details.  Run 'squid -z' to create swap directories  if needed, or if running Squid for the first time.
Aug  7 11:20:29 cache squid[21882]: Squid Parent: child process 21884 exited with status 1
[root@cache ~]# /usr/local/squid/sbin/squid -z

第一次运行的时候需要建立CACHE目录.通过-z参数实现.

启动报错,Cannot open HTTP Port

Dec 31 01:04:46 cache squid[12484]: Squid Parent: child process 12489 started
Dec 31 01:04:46 cache (squid): Cannot open HTTP Port
Dec 31 01:04:46 cache squid[12484]: Squid Parent: child process 12489 exited with status 1

非root用户不能启动大于1024的端口,用root启动。另外selinux也会阻挡。关掉,重启。

 

 

WARNING cache_mem is larger than total disk cache space!

[root@cache squid-3.1.0.13]# /usr/local/squid/sbin/squid -k parse
2009/08/08 15:20:17| Processing Configuration File: /usr/local/squid/etc/squid.conf (depth 0)
2009/08/08 15:20:17| Starting Authentication on port [::]:80
2009/08/08 15:20:17| Disabling Authentication on port [::]:80 (interception enabled)
2009/08/08 15:20:17| Disabling IPv6 on port [::]:80 (interception enabled)
2009/08/08 15:20:17| WARNING cache_mem is larger than total disk cache space!

 

cache_men不能超过cache_dir中的一个数值,比如我的cache_dir是

cache_dir ufs /data/squid_log 100 16 256

cache_men被注释掉了,于是报错。

修改为

cache_men 96 MB,OK。

参考:http://bbs.chinaunix.net/archiver/?tid-114374.html

 

ACL的问题

默认Squid(3.1)不支持反向代理访问的(但是RFC1918的地址可以),是通过squid.conf中的ACL来实现的。

具体现象就是你在172地址访问没问题,但是公网访问就提示Access Denied。

日志显示:

1249718043.103      0 218.94.50.92 TCP_DENIED/403 3750 GET http://english.nau.edu.cn/ - NONE/- text/html

这时候只需要将squid.conf中默认的

http_access deny all修改为

http_access allow all就可以了。一个很简单的ACL。

 

重启的时候提示squid: No running copy

使用squid -k reconfigure重启的时候老是提示

[root@cache ~]# /usr/local/squid/sbin/squid -k shutdown
squid: No running copy

 

解决办法:squid将pid记录在一个文件里面,如果不存在(默认好像不会自己建立),那么就找不到了,虽然这时候squid是在运行的。只要指定一个pid文件就行了。

[root@cache ~]#touch /usr/local/squid/var/squid.pid

再到squid.conf里面加入:

pid_filename /usr/local/squid/var/squid.pid

就搞定了。

 

2010/01/25 18:09:09| client_side.cc(2949) okToAccept: WARNING! Your cache is running out of filedescriptors

访问squid发现非常非常之慢,然后找cache.log,发现如上提示。

google了一下,发现是因为打开的文件数超过了linux的限制造成的,修改即可。

# ulimit -HSn 65536

修改Linux为65536,并加入到/etc/profile中。

然后重新编译Squid,加入

--with-filedescriptors=65536

参数即可。

参考:

  1. http://blog.verycd.com/dash/cmd=showentry&eid=10840
  2. http://linux.chinaunix.net/bbs/viewthread.php?tid=1028215

不停的自动关闭

squid不断地自动关闭,然后发现/var/log/message里面有这个

Jan 28 12:20:16 cache-lab squid[6725]: Squid Parent: child process 6741 exited due to signal 25 with status 0
Jan 28 12:20:19 cache-lab squid[6725]: Squid Parent: child process 6744 started
Jan 28 12:20:26 cache-lab squid[6725]: Squid Parent: child process 6744 exited due to signal 25 with status 0
Jan 28 12:20:26 cache-lab squid[6725]: Exiting due to repeated, frequent failures

singal 25,貌似是因为日志文件太大了。看了一下日志:

[root@cache-lab ~]# ll /data/logs/squid/
total 3757392
-rw-r----- 1 nobody nobody 1661531737 Jan 28 15:56 access.log
-rw-r----- 1 nobody nobody   34775796 Jan 28 15:56 cache.log
-rw-r----- 1 nobody nobody 2147483647 Jan 27 04:12 store.log

看到那个著名的2147483647了...


暂时把store.log写到/dev/null试试看。

分类: Linux, Squid 标签: ,

Squid反向代理的实现(Part I, Installing and configuration)

2009年8月3日 baalchina 没有评论

目的

  1. 很多服务器需要公网加速,但是公网IP有限。
  2. 实现对外提供IPv6服务,但是不是每台服务器都可以直接接入到IPv6网络中(能否通过Squid实现?)
  3. 最新的3.1版本和以前的差别很大!很多文档还是基于2.6之前版本的。务必注意

Squid下载地址:
http://mirror.aarnet.edu.au/pub/squid/squid/

安装

很简单。

#./configure --prefix=/usr/local/squid

#make

#make install

配置

首先要给日志文件夹写权限

#chmod +777 –R /usr/local/squid/logs

前面说过3.1版本区别很大…比如反向代理的,网上常见文档是这么说的

http://www.linux.gov.cn/netweb/squid.htm#reverseconf

httpd_accel_host virtual
httpd_accel_port 80
httpd_accel_single_host off
httpd_accel_uses_host_header on

然后加上dns解析就行了。但是3.1里面,检测直接报错。实际上3.1里面只需要一条就够了:

http_port 80 transparent

也就是在后面加上transparent参数。

注一下:实际上一开始我理解错了。transparent参数是透明代理的意思,用于正向代理。直接打开虽然可以实现反向代理的功能,但是实际上任何一个用户、网站都可以通过我的cache服务器进行代理访问了(比如通过我的代理服务器访问edu.cn网站)。

正确的反向代理的做法是通过cache_peer这个参数实现的:

http_port 80 accel vhost

cache_peer xlzx.nau.edu.cn parent 80 0 originserver no-query name=xlzx
cache_peer english.nau.edu.cn parent 80 0 originserver no-query name=english

cache_peer_domain xlzx xlzx.nau.edu.cn
cache_peer_domain english english.nau.edu.cn

 

http_port监听80端口,accel代表加速模式,vhost代表传递主机名,否则虚拟主机会失效。

解释一下这里的cache_peer含义:

  1. cache_peer,监听squid的80
  2. 转向给english.nau.edu.cn的80originserver参数代表将squid本机“伪装”成原始的web服务器(causes this parent peer to be contacted as a origin server.)。但是抓包的时候没有发现区别...
  3. no-query代表不向这台server发送ICP(Squid用于集群的一个协议)请求。单台主机没必要。
  4. 另外cache_peer_domain没有的话,所有域名都会指向第一个主机,而不是根据主机头区分服务。

更多参数参照:http://www.squid-cache.org/Versions/v3/3.1/cfgman/cache_peer.html

这样才是完整的反向代理配置:服务器必须通过我的配置才能通过我的cache被加速。

启动Squid,可以通过/var/log/message或者tail -100 /usr/local/squid/var/logs/cache.log 看到日志。刚开始的时候好像好多日志文件没有建立。

注意日志,可以看到Squid从DNS解析到了域名

常用命令

#/usr/local/squid/sbin/squid –k parse

检测squid.conf是否正确。

# /usr/local/squid/sbin/squid

启动Squid

# squid -k shutdown

不用说了吧

# squid -k reconfigure

这个有点类似于#clear bgp * soft in。哈。

 

贴一下我的squid.conf的配置

#Cache peer setting

cache_peer xlzx.nau.edu.cn parent 80 0 originserver no-query name=xlzx
cache_peer english.nau.edu.cn parent 80 0 originserver no-query name=english

cache_peer_domain xlzx xlzx.nau.edu.cn
cache_peer_domain english english.nau.edu.cn

#Main Configuration

http_port 80 accel vhost

cache_mgr baalchina

cache_mem 96 MB
cache_dir ufs /data/squidcache 100 16 256

access_log /data/logs/squid/access.log squid
cache_log /data/logs/squid/cache.log
cache_store_log /data/logs/squid/store.log

visible_hostname cache.nau.edu.cn

pid_filename /usr/local/squid/var/squid.pid

分类: Linux, Squid 标签: ,

MySQL的安装

2009年8月2日 baalchina 没有评论

Mysql的安装还是比较简单的。

 

首先去下载源码包,注意选择Source。

 

一路编译,安装。

参考:

 

http://dev.mysql.com/doc/refman/5.1/zh/installing.html#quick-install

shell> groupadd mysql

shell> useradd -g mysql mysql

shell> gunzip < mysql-VERSION.tar.gz | tar -xvf -

shell> cd mysql-VERSION

shell> ./configure --prefix=/usr/local/mysql

shell> make

shell> make install

shell> cp support-files/my-medium.cnf /etc/my.cnf

shell> cd /usr/local/mysql

shell> bin/mysql_install_db --user=mysql

shell> chown -R root  .

shell> chown -R mysql var

shell> chgrp -R mysql .

shell> bin/mysqld_safe --user=mysql &

我编译用的是这个参数:

./configure --prefix=/usr/local/mysql --with-comment=Source --with-server-suffix=-Nau_MySQL --with-mysqld-user=mysql --without-debug --with-big-tables --with-charset=gbk --with-collation=gbk_chinese_ci --with-extra-charsets=all --with-pthread --enable-static --enable-thread-safe-client --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --enable-assembler --without-isam --without-innodb --without-ndb-debug

安装好之后,记得给MySQL设置一个密码

mysqladmin uroot -password123456

 

或者

shell> mysql -u root

mysql> SET PASSWORD FOR ''@'localhost' = PASSWORD('newpwd');

 

http://dev.mysql.com/doc/refman/5.1/zh/installing.html#default-privileges

分类: Linux, Mysql 标签: ,

yum的使用

2009年8月2日 baalchina 没有评论

有时候编译发现某组件没有,这时候用yum就很方便了。

比如编译mysql提示

checking for termcap functions library... configure: error: No curses/termcap library found

那么

 

yum search curses

yum search termcap

 

提示:

[root@mysql-replication mysql-5.1.36]# yum search termcap
libtermcap.i386 : A basic system library for accessing the termcap database.
termcap.noarch : The terminal feature database used by certain applications.
termcap.noarch : The terminal feature database used by certain applications.
libtermcap-devel.i386 : Development tools for programs which will access the termcap database.
libtermcap.i386 : A basic system library for accessing the termcap database.

接下来安装之:

 

yum install libtermcap-devel

下面的就很简单了。不多说了。

分类: Linux 标签: ,

MySQL数据库备份+定时上传

2009年2月22日 baalchina 没有评论

比较的简单。

#!/bin/bash
date=` date +%Y%m%d`
/usr/local/mysql/bin/mysqldump --database uch -uroot -ppassword &gt; /data/mysqldata/uch-$date.dump
gzip /data/mysqldata/uch-$date.dump
分类: Linux, Mysql 标签: , ,