Category Archivelinux 维护优化
linux 维护优化 & 技术 10 Nov 2008 02:53 pm
用jailkit创建一个chroot环境的sftp
jailkit 官网
http://olivier.sessink.nl/jailkit/
环境as4
#wget http://olivier.sessink.nl/jailkit/jailkit-2.5.tar.gz
#tar zxvf jailkit-2.5.tar.gz
#cd jailkit-2.5
#./configure
#make
#make install
创建jail环境目录
#mkdir /home/jail
创建初始权限
#jk_init -v -j /home/jail basicshell editors extendedshell netutils ssh sftp scp
上面的斜体字都是可用的服务,可以在/etc/jailkit/jk_init.ini 中找到相应的部分
创建需限制的用户
#groupadd backup
#useradd -g backup -m john
#passwd john
限制该用户
#jk_jailuser -m -j /home/jail john
如果遇到错误
ldconfig: Can’t open configuration file /etc/ld.so.conf: No such file or directory
编辑/etc/jailkit/jk_init.ini
vi /etc/jailkit/jk_init.ini
#增加ldconfig
[ldconfig]
executables = /sbin/ldconfig
regularfiles = /etc/ld.so.conf
[uidbasics]
# this section probably needs adjustment on 64bit systems
# or non-Linux systems
# regularfiles = /etc/nsswitch.conf /etc/ld.so.conf
comment = common files for all jails that need user/group information
libraries = /lib/libnsl.so.1, /lib64/libnsl.so.1, /lib/libnss*.so.2, /lib64/libnss*.so.2
regularfiles = /etc/nsswitch.conf
#去掉/etc/ld.so.conf增加下面一行
includesections = ldconfig
修改完成后相应的passwd如下
#tail /etc/passwd
john:x:504:504::/home/jail/./home/john:/usr/sbin/jk_chrootsh
#cat /home/jail/etc/passwd
root:x:0:0:root:/root:/bin/bash
john:x:504:504::/home/john:/usr/sbin/jk_lsh
参考:
http://olivier.sessink.nl/jailkit/howtos_chroot_shell.html
http://bemike.org/2007/12/14/jailkit.html
http://forums.opensuse.org/applications/390698-jailkit-install-problems.html
linux 维护优化 & 技术 10 Nov 2008 01:17 pm
用scponly创建一个chroot环境的sftp
使用scponly可以使用户只能运行scp / sftp等命令,与rsync、subversion、gftp兼容,对winscp这个open source for Windows的client端支持很好.
scponly官网
http://sublimation.org/scponly/
服务器为as4
#wget http://nchc.dl.sourceforge.net/sourceforge/scponly/scponly-4.8.tgz
#tar zxvf scponly-4.8.tgz
#cd scponly-4.8
#./configure –prefix=/usr/local/scponly –enable-chrooted-binary –enable-winscp-compat –enable-sftp-logging-compat –enable-scp-compat –enable-rsync-compat –enable-passwd-compat
#make
#make install
#echo /usr/local/scponly/sbin/scponlyc >> /etc/shells
#make jail
/usr/bin/install -c -d /usr/local/scponly/bin
/usr/bin/install -c -d /usr/local/scponly/man/man8
/usr/bin/install -c -d /usr/local/scponly/etc/scponly
/usr/bin/install -c -o 0 -g 0 scponly /usr/local/scponly/bin/scponly
/usr/bin/install -c -o 0 -g 0 -m 0644 scponly.8 /usr/local/scponly/man/man8/scponly.8
/usr/bin/install -c -o 0 -g 0 -m 0644 debuglevel /usr/local/scponly/etc/scponly/debuglevel
if test “xscponlyc” != “x”; then \
/usr/bin/install -c -d /usr/local/scponly/sbin; \
rm -f /usr/local/scponly/sbin/scponlyc; \
cp scponly scponlyc; \
/usr/bin/install -c -o 0 -g 0 -m 4755 scponlyc /usr/local/scponly/sbin/scponlyc; \
fi
chmod u+x ./setup_chroot.sh
./setup_chroot.sh
Next we need to set the home directory for this scponly user.
please note that the user’s home directory MUST NOT be writeable
by the scponly user. this is important so that the scponly user
cannot subvert the .ssh configuration parameters.
for this reason, a writeable subdirectory will be created that
the scponly user can write into.
Username to install [scponly]larry
home directory you wish to set for this user [/home/larry]
name of the writeable subdirectory [incoming]incoming
ldconfig: /usr/lib/libmcrypt.so.4 is not a symbolic link
creating /home/larry/incoming directory for uploading files
Your platform (Linux) does not have a platform specific setup script.
This install script will attempt a best guess.
If you perform customizations, please consider sending me your changes.
Look to the templates in build_extras/arch.
- joe at sublimation dot org
please set the password for larry:
Changing password for user larry.
New UNIX password:
BAD PASSWORD: it is too simplistic/systematic
Retype new UNIX password:
Sorry, passwords do not match
New UNIX password:
BAD PASSWORD: it is too simplistic/systematic
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
if you experience a warning with winscp regarding groups, please install
the provided hacked out fake groups program into your chroot, like so:
cp groups /home/larry/bin/groups
#ll /home/larry/
drwxr-xr-x 2 root root 4096 11月 10 11:23 bin
drwxr-xr-x 2 root root 4096 11月 10 11:23 etc
drwxr-xr-x 2 larry larry 4096 11月 10 11:26 incoming
drwxr-xr-x 3 root root 4096 11月 10 11:23 lib
drwxr-xr-x 5 root root 4096 11月 10 11:23 usr
larry用户登录后只能在incoming目录里传东西
创建新用户需在编辑目录里执行setup_chroot.sh
#./setup_chroot.sh
#mkdir /home/larry/dev #cp -a /dev/null /home/larry/dev/
64位系统# mkdir /home/larry/lib64 # cp /lib64/ld-linux-x86-64.so.2 /home/larry/lib64/
参考:http://bbs.chinaunix.net/viewthread.php?tid=785820
http://hi.baidu.com/fengzhenjie/blog/item/2a4b1e7fe072ba0e29388a66.html
linux 维护优化 & 技术 27 Oct 2008 05:56 pm
使用vnstat监控流量
vnstat通/proc来监控流量,无需root权限,提供每日、每月等报表,并有php前台扩展。
http://humdi.net/vnstat/
wget http://humdi.net/vnstat/vnstat-1.6.tar.gz
tar zxvf vnstat-1.6.tar.gz
cd vnstat-1.6
make && make install ; vnstat –testkernel && vnstat -u -i eth0
如果用户在一个64位平台上编译,应改用make 64bit命令.
添加crontab
crontab -e
0-55/5 * * * * if [ -x /usr/bin/vnstat ] && [ `ls/var/lib/vnstat/ | wc -l` -ge 1 ]; then /usr/bin/vnstat -u; fi
vnStat 1.6 by Teemu Toivola -q, --query query database -h, --hours show hours -d, --days show days -m, --months show months -w, --weeks show weeks -t, --top10 show top10 -s, --short use short output -u, --update update database -i, --iface change interface (default: eth0) -?, --help short help -v, --version show version -tr, --traffic calculate traffic -l, --live show transfer rate in real time See also "--longhelp" for complete options list and "man vnstat". |
$ vnstat Database updated: Sun Dec 2 22:20:01 2007 inet (eth0) received: 735.00 GB (48.9%) transmitted: 769.38 GB (51.1%) total: 1.47 TB rx | tx | total -----------------------+------------+----------- yesterday 23.35 MB | 20.25 MB | 43.60 MB today 27.47 MB | 21.37 MB | 48.84 MB -----------------------+------------+----------- estimated 29 MB | 22 MB | 51 MB |
(with 2 interfaces)
$ vnstat
rx / tx / total / estimated
Internet (eth1):
yesterday 209.36 MB / 322.88 MB / 532.24 MB
today 1.99 GB / 2.46 GB / 4.46 GB / 4.67 GB
Local (eth0):
yesterday 248.27 MB / 4.63 GB / 4.87 GB
today 2.31 GB / 4.21 GB / 6.52 GB / 6.83 GB
|
$ vnstat -h inet (eth0) 22:15 ^ r | rt r | rt rt | rt rt | r rt rt | rt r rt rt | rt rt rt rt rt | rt rt rt r r rt r rt r rt rt rt | rt rt rt r rt rt rt rt rt rt rt rt rt | rt rt rt rt r r r r r rt rt rt rt rt rt rt rt rt rt -+---------------------------------------------------------------------------> | 23 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 h rx (kB) tx (kB) h rx (kB) tx (kB) h rx (kB) tx (kB) 23 1,352 1,219 07 277 151 15 1,352 1,165 00 2,281 2,140 08 402 158 16 1,487 878 01 1,485 1,261 09 290 155 17 1,752 1,559 02 648 522 10 589 185 18 1,455 1,001 03 392 261 11 650 202 19 2,332 1,835 04 323 240 12 907 350 20 3,881 3,619 05 311 179 13 1,234 1,044 21 3,695 3,237 06 281 173 14 1,221 812 22 675 591 |
$ vnstat -d
inet (eth0) / daily
day rx | tx | total
------------------------+-------------+----------------------------------------
03.11. 26.57 MB | 27.39 MB | 53.97 MB %%%%%%:::::::
04.11. 22.23 MB | 16.71 MB | 38.94 MB %%%%%::::
05.11. 31.38 MB | 23.35 MB | 54.74 MB %%%%%%%::::::
06.11. 35.17 MB | 26.85 MB | 62.02 MB %%%%%%%%%::::::
07.11. 42.65 MB | 34.19 MB | 76.84 MB %%%%%%%%%%%::::::::
08.11. 36.65 MB | 26.75 MB | 63.40 MB %%%%%%%%%::::::
09.11. 35.01 MB | 27.45 MB | 62.47 MB %%%%%%%%:::::::
10.11. 24.48 MB | 22.72 MB | 47.20 MB %%%%%%:::::
11.11. 26.04 MB | 19.91 MB | 45.95 MB %%%%%%:::::
12.11. 27.89 MB | 18.73 MB | 46.61 MB %%%%%%%::::
13.11. 33.82 MB | 24.52 MB | 58.35 MB %%%%%%%%::::::
14.11. 39.11 MB | 31.76 MB | 70.86 MB %%%%%%%%%::::::::
15.11. 41.57 MB | 36.23 MB | 77.80 MB %%%%%%%%%%:::::::::
16.11. 36.93 MB | 33.51 MB | 70.44 MB %%%%%%%%%::::::::
17.11. 25.79 MB | 23.87 MB | 49.66 MB %%%%%%::::::
18.11. 29.51 MB | 22.50 MB | 52.01 MB %%%%%%%::::::
19.11. 43.46 MB | 32.91 MB | 76.38 MB %%%%%%%%%%%::::::::
20.11. 51.90 MB | 47.82 MB | 99.72 MB %%%%%%%%%%%%%::::::::::::
21.11. 38.77 MB | 34.21 MB | 72.98 MB %%%%%%%%%%::::::::
22.11. 34.54 MB | 31.22 MB | 65.76 MB %%%%%%%%::::::::
23.11. 22.61 MB | 21.16 MB | 43.76 MB %%%%%:::::
24.11. 22.49 MB | 20.84 MB | 43.34 MB %%%%%:::::
25.11. 31.60 MB | 26.50 MB | 58.10 MB %%%%%%%%::::::
26.11. 38.23 MB | 33.84 MB | 72.07 MB %%%%%%%%%%::::::::
27.11. 43.54 MB | 41.88 MB | 85.42 MB %%%%%%%%%%%::::::::::
28.11. 38.86 MB | 30.87 MB | 69.73 MB %%%%%%%%%::::::::
29.11. 40.16 MB | 33.64 MB | 73.79 MB %%%%%%%%%%::::::::
30.11. 32.73 MB | 28.67 MB | 61.40 MB %%%%%%%%:::::::
01.12. 23.35 MB | 20.25 MB | 43.60 MB %%%%%:::::
02.12. 27.27 MB | 21.21 MB | 48.47 MB %%%%%%%:::::
------------------------+-------------+----------------------------------------
estimated 29 MB | 22 MB | 51 MB
|
$ vnstat -m inet (eth0) / monthly month rx | tx | total -------------------------+--------------+-------------------------------------- Jan '07 1.33 GB | 1.25 GB | 2.58 GB %%%%%%%%%:::::::: Feb '07 1.31 GB | 1.51 GB | 2.82 GB %%%%%%%%%:::::::::: Mar '07 1.54 GB | 1.66 GB | 3.20 GB %%%%%%%%%%%::::::::::: Apr '07 1.27 GB | 1.13 GB | 2.40 GB %%%%%%%%:::::::: May '07 1.17 GB | 1.31 GB | 2.48 GB %%%%%%%%::::::::: Jun '07 920.61 MB | 2.00 GB | 2.90 GB %%%%%%::::::::::::: Jul '07 917.21 MB | 763.12 MB | 1.64 GB %%%%%%::::: Aug '07 915.59 MB | 905.99 MB | 1.78 GB %%%%%%:::::: Sep '07 926.10 MB | 678.70 MB | 1.57 GB %%%%%%:::: Oct '07 1.00 GB | 714.00 MB | 1.69 GB %%%%%%::::: Nov '07 0.99 GB | 842.16 MB | 1.81 GB %%%%%%%::::: Dec '07 50.62 MB | 41.46 MB | 92.07 MB -------------------------+--------------+-------------------------------------- estimated 808 MB | 663 MB | 1.44 GB |
$ vnstat -t inet (eth0) / top 10 # day rx | tx | total -------------------------------+-------------+--------------------------------- 1 26.03.06 6.41 GB | 10.83 GB | 17.24 GB %%%%%%%::::::::::: 2 05.02.04 8.31 GB | 7.08 GB | 15.39 GB %%%%%%%%%::::::: 3 04.02.05 7.96 GB | 6.21 GB | 14.17 GB %%%%%%%%:::::: 4 04.09.05 8.09 GB | 5.22 GB | 13.30 GB %%%%%%%%::::: 5 04.11.03 4.52 GB | 5.96 GB | 10.47 GB %%%%:::::: 6 26.06.05 4.12 GB | 6.10 GB | 10.22 GB %%%%:::::: 7 02.11.03 7.18 GB | 2.79 GB | 9.97 GB %%%%%%%::: 8 31.01.05 3.68 GB | 5.99 GB | 9.66 GB %%%%:::::: 9 28.08.03 5.93 GB | 3.69 GB | 9.62 GB %%%%%%:::: 10 23.12.03 4.36 GB | 5.23 GB | 9.59 GB %%%%%::::: -------------------------------+-------------+--------------------------------- |
$ vnstat -w Local (eth0) / weekly rx | tx | total ----------------------------+---------------+-------------- last 7 days 4.83 GB | 18.82 GB | 23.65 GB last week 2.52 GB | 14.58 GB | 17.10 GB current week 2.31 GB | 4.24 GB | 6.55 GB ----------------------------+---------------+-------------- estimated 17.66 GB | 32.36 GB | 50.02 GB |
$ vnstat -tr
10386 packets sampled in 5 seconds
Traffic average for eth1
rx 112.21 kB/s 620 packets/s
tx 1444.77 kB/s 1456 packets/s
|
$ vnstat -l
Monitoring eth0... (press CTRL-C to stop)
rx: 430.68 kB/s 291 p/s tx: 10.21 kB/s 147 p/s
eth0 / traffic statistics
rx | tx
--------------------------------------+----------------------------------------
bytes 32.79 MB | 957 kB
--------------------------------------+----------------------------------------
max 656.39 kB/s | 90.50 kB/s
average 419.78 kB/s | 11.97 kB/s
min 288.37 kB/s | 7.03 kB/s
--------------------------------------+----------------------------------------
packets 23298 | 12348
--------------------------------------+----------------------------------------
max 732 p/s | 609 p/s
average 291 p/s | 154 p/s
min 195 p/s | 100 p/s
--------------------------------------+----------------------------------------
time 1.33 minutes
|
linux 维护优化 & 技术 27 Oct 2008 05:28 pm
使用iftop实时监控网卡流量
iftop是类似于top的实时流量监控工具,无报表功能,需使用root运行。
官方网站:http://www.ex-parrot.com/~pdw/iftop/
目前最新版本为: iftop-0.17pre3.tar.gz
安装需要:
libpcap
http://www.tcpdump.org/
安装libpcap时出错
gcc -O2 -I. -DHAVE_CONFIG_H -D_U_=”__attribute__((unused))” -c ./fad-getad.c
In file included from ./fad-getad.c:64:
/usr/include/linux/if_packet.h:52: 错误:expected specifier-qualifier-list before ‘__u32’
make: *** [fad-getad.o] 错误 1
#include <linux/types.h>
加入到
/usr/include/linux/if_packet.h
libcurses
界面:
界面说明:
第一行为带宽,这里为1Mbit,不是字节哦.
连接列表,最后三个分别是2秒,10秒和40秒的平均流量
=>代表发送,<= 代表接收
最后三行表示发送,接收和全部的流量,第二列为你运行iftop到目前流量,第三列为高峰值,第四列为平均值。
命令:
iftop: display bandwidth usage on an interface by host
Synopsis: iftop -h | [-npbBP] [-i interface] [-f filter code] [-N net/mask]
-h display this message
-n don’t do hostname lookups(不进行dns解析)
-N don’t convert port numbers to services (直接显示端口号,不显示服务名称)
-p run in promiscuous mode (show traffic between other
hosts on the same network segment)(嗅探器)
-b don’t display a bar graph of traffic
-B Display bandwidth in bytes (以字节统计)
-i interface listen on named interface
-f filter code use filter code to select packets to count
(default: none, but only IP packets are counted)
-F net/mask show traffic flows in/out of network
-P show ports as well as hosts(按照端口对应ip地址)
-m limit sets the upper limit for the bandwidth scale
-c config file specifies an alternative configuration file
iftop, version 0.17pre3
copyright (c) 2002 Paul Warren <pdw@ex-parrot.com> and contributors
安装
wget http://www.ex-parrot.com/~pdw/iftop/download/iftop-0.17pre3.tar.gz
tar zxvf iftop-0.17pre3.tar.gz
cd iftop-0.17pre3
./configure
make
make install
iftop
========================================================
12.5Kb 25.0Kb 37.5Kb 50.0Kb 62.5Kb
mqqqqqqqqqqqqqvqqqqqqqqqqqqqvqqqqqqqqqqqqqvqqqqqqqqqqqqqvqqqqqqqqqqqqq
192.168.54.96 => 192.168.54.83 1.00Kb 1.86Kb 2.42Kb
<= 160b 518b 485b
192.168.54.96 => 202.96.209.5 0b 0b 95b
<= 0b 0b 168b
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq
TX: cumm: 3.77KB peak: rates:Kb 1.00Kb 1.86Kb 2.51Kb
RX: 980B 1.31Kb 160b 518b 653b
TOTAL: 4.73KB 7.10Kb 1.16Kb 2.36Kb 3.15Kb
linux 维护优化 & 技术 17 Oct 2008 11:51 am
Linux下查看版本号的命令
[root@localhost ~]# uname -a
Linux localhost.localdomain 2.6.18-8.el5 #1 SMP Fri Jan 26 14:15:14 EST 2007 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost ~]# cat /proc/version
Linux version 2.6.18-8.el5 (brewbuilder@ls20-bc1-14.build.redhat.com) (gcc version 4.1.1 20070105 (Red Hat 4.1.1-52)) #1 SMP Fri Jan 26 14:15:14 EST 2007
[root@localhost ~]# lsb_release -a
LSB Version: :core-3.1-amd64:core-3.1-ia32:core-3.1-noarch:graphics-3.1-amd64:graphics-3.1-ia32:graphics-3.1-noarch
Distributor ID: RedHatEnterpriseServer
Description: Red Hat Enterprise Linux Server release 5 (Tikanga)
Release: 5
Codename: Tikanga
[root@localhost ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5 (Tikanga)
[root@localhost ~]# rpm -q redhat-release
redhat-release-5Server-5.0.0.9
[root@localhost ~]# cat /etc/issue
Red Hat Enterprise Linux Server release 5 (Tikanga)
Kernel \r on an \m
参考:http://www.51testing.com/?89868/action_viewspace_itemid_11978.html
linux 维护优化 & 技术 07 Oct 2008 03:27 pm
关闭631端口cups打印服务和8009端口ajp
用nmap扫了下服务器发现631端口是打开的。
631/tcp open ipp
//先检查下
#ps aux|grep cups
//关闭服务
#service cups stop
//查看自启动
#chkconfig –list cups
cups 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
//关闭自启动服务
#chkconfig –level 2345 cups off
//再检查下
#chkconfig –list cups
cups 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭 6:关闭
============================我是分割线===================
8009/tcp open ajp13
8009端口是tomcat和apache的mod_proxy_ajp,mod_jk沟通的端口,我这里apache纯做代理所以可以关闭。
tomcatpath/conf/server.xml 中的这段注释掉
<!–
<Connector port=”8009″ protocol=”AJP/1.3″ redirectPort=”8443″ />
–>
重启tomcat
收工~
linux 维护优化 & 技术 22 Sep 2008 02:09 pm
awstats按日产生统计报表
修改wwwroot/cgi-bin/awstats.pl
7851行增加日期下拉框
[code]
print “<select class=\”aws_formfield\” name=\”day\”>\n”;
foreach (1..31) {
my $dayix=sprintf(”%02s”,$_);
print “<option”.(”$DayRequired” eq “$dayix”?” selected=\”true\”":”").” value=\”$dayix\”>$dayix</option>\n”;
}
print “</select>\n”;
[/code]
7871行增加databasebreak参数
[code]
if ($DatabaseBreak) { print “<input type=\”hidden\” name=\”DatabaseBreak\” value=\”$DatabaseBreak\” />\n”; }
[/code]
命令行统计增加:-databasebreak=day
查看报表时地址栏需增加:&databasebreak=day&day=DD
以下为查看页代码
[code]
<script>
var d = new Date();
d.setTime(d.setDate(d.getDate()-1));
var day=d.getDate();
var srv = new Array();
srv[0]=’www.c1gstudio.com’;
srv[1]=’bbs.c1gstudio.com’;
srv[2]=’blog.c1gstudio.com’;
srv[3]=’admin.c1gstudio.com’;
for (var i=0;i<srv.length ;i++ )
{
document.writeln(’<p><a href=”http://admin.c1gstudio.com/cgi-bin/awstats.pl?config=’+srv[i]+’&databasebreak=day&day=’+day+’” target=”_blank”>http://admin.c1gstudio.com/cgi-bin/awstats.pl?config=’+srv[i]+’</a></p>’);
}
document.writeln(’<hr>’);
[/code]
参考:
http://blogger.org.cn/blog/more.asp?name=chenjiejacky&id=20464
http://www.chedong.com/blog/archives/001293.html#more
Web Server/Apache/Nginx & linux 维护优化 & 技术 08 Sep 2008 04:34 pm
设置apache 日志不记录图片
<FilesMatch “\.(gif|jpg|jpeg|png|css|swf)”>
SetEnv NoLOG 1
</FilesMatch>
CustomLog logs/www.c1gstudio.com-access_log common env=!NoLOG
对于找不到图片的还是会记录在log中的
linux 维护优化 & 技术 25 Aug 2008 04:49 pm
tomcat 内存溢出
装完nginx环境重启后,tomcat不能启动
tail tomcat/logs/catalina.out
2008-8-25 15:55:37 org.apache.tomcat.util.net.JIoEndpoint processSocket
严重: Error allocating socket processor
java.lang.OutOfMemoryError: Java heap space
at java.lang.Thread.<init>(Thread.java:208)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.start(JIoEndpoint.java:468)
at org.apache.tomcat.util.net.JIoEndpoint.newWorkerThread(JIoEndpoint.java:681)
….
free -m 看了一下内存从2G变成了1G,让机房重插下内存后一切正常。
Database & linux 维护优化 & 技术 19 Aug 2008 02:12 pm
mysqlhotcopy备份数据库
首先是perl支持
shell>perl -MCPAN -e shell
cpan>install DBI
cpan>install DBD::mysql ( 安装这个时test通不过)
cpan>q
退出
unset LANG
cd ~/.cpan/build/DBI-1.607
perl Makefile.PL
make test
make install
cd ../DBD-mysql-4.007
perl Makefile.PL –mysql_config=/opt/mysql/bin/mysql_config
make
make test
<coolcode>
failed: Can’t load ‘/root/.cpan/build/DBD-mysql-4.007/blib/arch/auto/DBD/mysql/mysql.so’
</coolcode>
ln -s /opt/mysql/lib/mysql/* /usr/lib/
make test
<coolcode>
/root/.cpan/build/DBD-mysql-4.007/blib/arch/auto/DBD/mysql/mysql.so: undefined symbol:
</coolcode>
make realclean
perl Makefile.PL –mysql_config=/opt/mysql/bin/mysql_config –libs=”-L/opt/mysql/lib/mysql -lmysqlclient -lz -lcrypt -lnsl -lm”
<coolcode>
all skipped: ERROR: Access denied for user ‘root’@'localhost’ (using password: NO). Can’t continue test
</coolcode>
perl Makefile.PL –mysql_config=/opt/mysql/bin/mysql_config –libs=”-L/opt/mysql/lib/mysql -lmysqlclient -lz -lcrypt -lnsl -lm” –testpassword=123456
make
make test
<coolcode>
t/00base………………..String found where operator expected at t/00base.t line 20, near “BAIL_OUT “Unable to load DBI”"
(Do you need to predeclare BAIL_OUT?)
</coolcode>
make realclean
perl Makefile.PL –mysql_config=/opt/mysql/bin/mysql_config –libs=”-L/opt/mysql/lib/mysql -lmysqlclient -lz” –cflags=-I/opt/mysql/include/mysql –testhost=localhost –testsocket=/opt/mysql/mysql.sock –testdb=bugdb –testuser=root –testpassword=123456
make
make test
<coolcode>
t/00base………………..String found where operator expected at t/00base.t line 20, near “BAIL_OUT “Unable to load DBI”"
(Do you need to predeclare BAIL_OUT?)
</coolcode>
(在另一机器上没出这个错)-_-*!!! 直接make install
检察是否安装成功
shell>perldoc DBI
shell>perldoc DBI::mysql
从源码装
http://search.cpan.org/dist/DBD-mysql/lib/DBD/mysql.pm#INSTALLATION
gzip -cd DBI-(version).tar.gz | tar xf - cd DBI-(version) perl Makefile.PL make make test make install cd .. gzip -cd Data-ShowTable-(version).tar.gz | tar xf - cd Data-ShowTable-3.3 perl Makefile.PL make make install
Data-ShowTable-3.3.tar.gz 安装时有个错误 *** ERROR: Unterminated I<…> at line 724 in file ShowTable.pm 用以下方法解决 http://lists.mysql.com/perl/1015
cd .. gzip -cd DBD-mysql-(version)-tar.gz | tar xf - cd DBD-mysql-(version) perl Makefile.PL –mysql_config=/opt/mysql/bin/mysql_config –libs=”-L/opt/mysql/lib/mysql -lmysqlclient -lcrypt -lnsl -lm -lz” –cflags=-I/opt/mysql/include/mysql –testsocket=/opt/mysql/mysql.sock –testhost=localhost –testuser=root –testpassword=****** make make test make install
在数据库段分配一个专门用于备份的用户
mysql> grant select,reload,lock tables on *.* to ‘hotcopyer’@‘localhost’ identified by ‘123456′;
mysql> grant insert on hotcopy.checkpoint to hotcopyer@‘localhost’;
mysql> flush privileges;
建表记录下历史
create database hotcopy;
create table checkpoint(time_stamp timestamp not null,src varchar(32),dest varchar(60), msg varchar(255));
cd /opt/mysql/bin/
./mysqlhotcopy test_ucenter –noindices –allowold –checkpoint hotcopy.checkpoint –addtodest /home/admin –user=hotcopyer –password=123456
你也可以将备份用的用户和密码放在~/.my.cnf下
# vi /root/.my.cnf
<coolcode>
[client]
host=localhost
user=hotcopyer
password=123456
</coolcode>
<coolcode>
DBD::mysql::db do failed: MySQL server has gone away at /opt/mysql/bin/mysqlhotcopy line 513.
</coolcode>
看了下备份执行时间为10S左右,和我my.cnf中的wait timeout一样,调大max_allowed_packet和wait_timeout参数后没有错误。
修改下配置为
vi /opt/mysql/my.cnf
<coolcode>
max_allowed_packet = 4M #字段最大的可能值
wait_timeout = 60
</coolcode>以上参数放在my.cnf的[mysqlhotcopy]和/root/.my.cnf中的[client]无效。
wait_timeout = 60可能会占用太多的connection。
我将它改为 10,然后修改mysqlhostcopy脚本来解决”has gone away”错误
复制第177行的mysql连接至513行
<coolcode>
my $dbh = DBI->connect(”dbi:mysql:$dsn;mysql_read_default_group=mysqlhotcopy”,
$opt{user}, $opt{password},
{
RaiseError => 1,
PrintError => 0,
AutoCommit => 1,
});
</coolcode>分析:
mysqlhotcopy时会先连上数据库,然后lock table再复制数据库文件,最后unlock table,
由于复制数据文件会占用一定时间,所以再次执行unlock table时可能已超过设置的wait timeout时间,
我这里将它再连接一次就不会报错啦。
如用到checkpoint,那492行也要插一次.
mysqlhotcopy比较适合备份小型一点(1G以下)的数据库,还需留意下table lock wait timeout参数