利用crontab 每夜备份MySQL数据库 

自从数据库挂过一次之后,我越来越开始重视起我的数据安全了~特别是数据备份,一直要保质保量的完成。

我是这样做的,由于现在还没有找到完美的远程备份的解决方案,我先是在本地备份在本地,而后在手动转移。

首先,创建一个专门用于备份数据的MySQL用户,比如 dumper,授予所有数据库及表的select 和 lock table 权限,密码一定要足够的强大,并且只允许在本地登录。

命令:
grant select,lock tables on *.* to 'dumper'@'localhost' identified by PASSWORD('XXXX').
即可。

之后,为了让crontab 执行mysqldump 时不使用交互密码,编辑 my.cnf 配置文件。

找到[mysqldump]节点,加入
user = dumper
password = XXXX

保存。

一切OK后,使用crontab 创建备份任务.

运行 crontab -e
输入 0 0 * * * mysqldump -A -C -u dumper | bzip2 -9 > ~/sql/mysql_`date +%s`.sql.bz2

保存退出即可。

查看一下:
[root@PowerPC sql]# crontab -l
0 0 * * * mysqldump -A -C -u dumper | bzip2 -9 > ~/sql/mysql_`date +%s`.sql.bz2

这样的话,在每晚的0点,mysql 都会被整个压缩备份下来一次,再也不用担心数据库挂掉拉~

我个人建议是压缩一下,gzip/bzip 均可,压一下的结果很明显,毕竟VPS的硬盘也不算大~

[root@PowerPC sql]# ls -l -h
total 3.9M
-rw-r--r-- 1 root root 689K Jul 9 12:53 mysql_1310201629.sql.bz2
-rw-r--r-- 1 root root 3.2M Jul 9 12:54 mysql_1310201645.sql
[ ] ( 3290 次浏览 ) 永久链接 ( 3 / 2418 )
编译安装 Apache Traffic Server 3.0.0 通过 

本来想这篇文章不发算了~因为事实是trafficserver 的一个bug删掉了我的所有数据,而我也没有在用它~

不过想想我的这些噩梦般的遭遇可能会帮到一些人,便还是贴了出来~

我是在trafficserver 正式发布了3.0.0版本后,从apache官网下载的trafficserver的源码包(http://www.apache.org/dist//trafficserver/trafficserver-3.0.0.tar.bz2)。

解压,进入目录:
我的configure:
[root@PowerPC trafficserver-3.0.0]# ./configure \
> --prefix=/usr/local/trafficserver \
> --exec-prefix=/usr/local \
> --sysconfdir=/etc/sysconfig/trafficserver \
> --localstatedir=/var/run \
> --enable-purify \
> --enable-tproxy=auto \
> --with-user=cache \
> --with-group=web

倒也没什么特别的,检查依赖,报错:

checking for Tcl configuration... configure: error: Can't find Tcl configuration, install the TCL dev package


解决方案:yum install tcl-devel
再次检查,通过。接下来 make 编译,再次报错:

cc1plus: warnings being treated as errors
LogAccess.cc: In member function ‘int LogAccess::marshal_record(char*, char*)’:
LogAccess.cc:729: warning: comparison between signed and unsigned integer expressions


这是configure文件的问题,警告就导致编译程序退出了~修改一下,打开configure,
删除所有含有 "-Werror"的地方,一共有11处:

[root@PowerPC trafficserver-3.0.0]# cat configure |grep Werror
# or remarks (even with -Werror). So we grep stderr for any message
# or remarks (even with -Werror). So we grep stderr for any message
# or remarks (even with -Werror). So we grep stderr for any message
# common_opt="-pipe -Wall -Werror -Wconversion -Wno-sign-conversion"
common_opt="-pipe -Wall -Werror"
common_opt="-pipe -Wall -Werror"
common_opt="-pipe -Wall -Werror"
common_opt="-pipe -Wall -Werror"
common_opt="-pipe -Wall -Werror"
CFLAGS="$CFLAGS -Werror"
CFLAGS="$CFLAGS -Werror"


具体操作,vi里面replace即可,
:%s/\-Werror/ /g
11 substitutions on 11 lines

完了之后,编译通过,之后 make install 安装.

启动trafficserver,又报错了~

traffic_server: error while loading shared libraries: libtsutil.so.3: cannot open shared object file: No such file or directory


看来是动态链接库的问题,编辑位于 /etc 下的ld.so.conf文件,加入trafficserver的lib路径(/usr/local/libexec/trafficserver).
再重新刷新下ldconfig,
ldconfig -v
即可。
之后就可以正常启动了~

关于trafficserver的配置,可以说是比同类的Squid cache和Varnish cache 都要复杂,看的人都冒汗。

下面是所有配置文件的列表:
[root@PowerPC trafficserver]# ls -l
total 216
-rw-r--r-- 1 cache web 1324 Jun 16 07:08 ae_ua.config
drwxr-xr-x 3 cache web 4096 Jun 16 07:08 body_factory
-rw-r--r-- 1 cache web 1210 Jun 16 07:26 cache.config
-rw-r--r-- 1 cache web 657 Jun 16 07:26 cluster.config
-rw-r--r-- 1 cache web 1868 Jun 16 07:26 congestion.config
-rw-r--r-- 1 cache web 746 Jun 16 07:26 hosting.config
-rw-r--r-- 1 cache web 1313 Jun 16 07:26 icp.config
drwxr-xr-x 2 cache web 4096 Jun 16 07:26 internal
-rw-r--r-- 1 cache web 254 Jun 16 07:26 ip_allow.config
-rw-r--r-- 1 cache web 328 Jun 16 07:26 log_hosts.config
-rw-r--r-- 1 cache web 15076 Jun 16 07:26 logs_xml.config
-rw-r--r-- 1 cache web 365 Jun 16 07:08 mgr.cnf
-rw-r--r-- 1 cache web 1362 Jun 16 07:26 parent.config
-rw-r--r-- 1 cache web 310 Jun 16 07:26 plugin.config
-rw-r--r-- 1 cache web 318 Jun 16 07:08 plugin.db
-rw-r--r-- 1 cache web 0 Jun 16 07:26 proxy.pac
-rw-r--r-- 1 cache web 27444 Jun 16 07:26 records.config
-rw-r--r-- 1 cache web 7047 Jun 16 07:26 remap.config
drwx------ 2 cache web 4096 Jun 16 07:26 snapshots
-rw-r--r-- 1 cache web 1677 Jun 16 07:26 socks.config
-rw-r--r-- 1 cache web 2139 Jun 16 07:26 splitdns.config
-rw-r--r-- 1 cache web 430 Jun 16 07:26 ssl_multicert.config
-rw-r--r-- 1 cache web 68821 Jun 16 07:26 stats.config.xml
-rw-r--r-- 1 cache web 2960 Jun 16 07:26 storage.config
-rw-r--r-- 1 root root 19 Jun 16 07:08 trafficserver-release
-rw-r--r-- 1 cache web 1420 Jun 16 07:26 update.config
-rw-r--r-- 1 cache web 464 Jun 16 07:26 vaddrs.config
-rw-r--r-- 1 cache web 1278 Jun 16 07:26 volume.config
-rw-r--r-- 1 cache web 0 Jun 16 07:26 wpad.dat

很是恐怖~ 不过可以不时的参考官方的帮助文档(http://trafficserver.apache.org/docs/v2/admin/files.htm)。

而我在粗略的配置了一通后,居然报错了~

[Jun 16 15:08:00.991] Manager {3078682880} ERROR: [bindProxyPort] Unable to bind socket: 80 : Permission denied
[Jun 16 15:08:00.991] Manager {3078682880} ERROR: (last system error 13: Permission denied)


我很是不解~有人说,可能是我之前使用了root运行过服务,所以导致了部分文件不能被写入。最好的办法是卸载,重装,恢复初始化。

我便运行了"make uninstall && make distclean",于是我便杯具了~
[ ] ( 3618 次浏览 ) 永久链接 ( 3 / 2340 )
从头到脚编译安装VPS上所有东西 

拜Trafficserver 所赐,把我的VPS上所有的数据都搞没了~使用开源软件的潜在风险还得自己担着~ 我也只好是只认倒霉了~谁让使用MySQL养成的臭习惯呢~

具体见:http://www.mail-archive.com/[email protected]/msg00875.html (需翻墙)

总之,我之后便一狠心删除掉了VPS上的所有数据,就差重装系统了~现如今,我的数据也就那样了,我便打算重新架起VPS。

下载所有需要软件的源码包~如PHP、MySQL之类的.

wget http://mysql.mirrors.hoobly.com/Downloa ... -m5.tar.gz
wget http://nginx.org/download/nginx-1.0.4.tar.gz
wget http://downloads.php.net/stas/php-5.4.0alpha1.tar.bz2
wget ftp://vsftpd.beasts.org/users/cevans/vsftpd-2.3.4.tar.gz
wget http://www.hiawatha-webserver.org/files ... 7.5.tar.gz
wget http://repo.varnish-cache.org/source/va ... 0.0.tar.gz
wget http://prdownloads.sourceforge.net/pam- ... RC1.tar.gz

全部解压,ls一下,

drwxr-xr-x 3 root root 4096 Jul 3 06:31 config_bak
drwxrwxrwx 7 1000 users 4096 Jun 6 01:06 hiawatha-7.5
drwxr-xr-x 31 7161 wheel 4096 Mar 14 16:40 mysql-5.6.2-m5
drwxr-xr-x 8 http games 4096 Jun 1 13:30 nginx-1.0.4
drwxrwxrwx 2 1000 1000 4096 Jan 9 2006 pam_mysql-0.7RC1
drwxr-xr-x 14 http games 4096 Jun 20 00:24 php-5.4.0alpha1
drwxr-xr-x 10 1000 1000 4096 Jun 16 15:38 varnish-3.0.0
drwxr-x--x 8 1000 1000 4096 Jun 30 18:15 vsftpd-2.3.4

一个个来吧~

先MySQL,进入目录:
首先 cmake . -LAH 查看编译帮助,我的编译参数:

[root@PowerPC mysql-5.6.2-m5]# cmake . \
> -DCMAKE_BUILD_TYPE:STRING=Release \
> -DCMAKE_INSTALL_PREFIX:PATH=/usr/local/mysql \
> -DCOMMUNITY_BUILD:BOOL=ON \
> -DINSTALL_BINDIR:STRING=../bin \
> -DINSTALL_LAYOUT:STRING=STANDALONE \
> -DINSTALL_SBINDIR:STRING=../sbin \
> -DMYSQL_DATADIR:PATH=/var/mysql/data \
> -DSYSCONFDIR:PATH=/etc/sysconfig/mysql \
> -DWITH_BLACKHOLE_STORAGE_ENGINE:BOOL=ON \
> -DWITH_EXTRA_CHARSETS:STRING=all \
> -DWITH_FEDERATED_STORAGE_ENGINE:BOOL=ON \
> -DWITH_INNOBASE_STORAGE_ENGINE:BOOL=ON \
> -DWITH_PARTITION_STORAGE_ENGINE:BOOL=ON \
> -DWITH_PERFSCHEMA_STORAGE_ENGINE:BOOL=ON \
> -DWITH_SSL:STRING=no \
> -DWITH_ZLIB:STRING=bundled

依赖没有问题,开始编译,之后安装.再把之前的配置文件my.cnf 恢复下。

进入 /usr/local/mysql 目录,创建软连接至 /usr/local/bin:
ln -s ../bin bin

再把sbin 下的mysqld 复制到 bin 下:
cp mysqld ../bin

这么做,是为了方便初始化数据库,运行位于scripts 下的mysql_install_db 脚本:
./mysql_install_db --datadir=/var/mysql --user=mysql --basedir=/usr/local/mysql

数据库初始化完了之后,就可以启动MySQL服务了~
mysqld_safe &

最好在运行下 mysql_secure_installation ,设置下root 密码,以及删除测试表.

不过,我发现test 表并没有被删掉,phpmyadmin 提示"can't rmdir './test/', errno: 17"错误。排除了权限问题,我发现原来test 目录下并不是空的,而是有一个".empty"的文件,手动删除(rm -rf test)即可~

接下来PHP,进入目录:
我的configure:
[root@PowerPC php-5.4.0alpha1]# ./configure \
> --prefix=/usr/local/php \
> --exec-prefix=/usr/local \
> --sysconfdir=/etc/sysconfig/php \
> --localstatedir=/var \
> --disable-cli \
> --enable-fpm \
> --with-fpm-user=http \
> --with-fpm-group=web \
> --with-config-file-path=/etc/sysconfig/php/php.ini \
> --with-config-file-scan-dir=/etc/sysconfig/php \
> --disable-ipv6 \
> --enable-calendar \
> --enable-dba=shared \
> --enable-exif \
> --with-gd \
> --enable-gd-native-ttf \
> --with-mhash \
> --enable-mbstring \
> --with-mcrypt \
> --with-mysql=/usr/local/mysql \
> --with-mysql-sock=/tmp/mysql.sock \
> --with-mysqli=/usr/local/bin/mysql_config \
> --disable-pdo \
> --enable-sockets \
> --with-xmlrpc \
> --enable-zip \
> --with-zlib \
> --with-bz2 \
> --without-pear

依赖没问题,直接make 编译,之后make install 安装,最后恢复下备份的配置文件。

再然后是Web server,首先是nginx,进入目录:
我的configure:
[root@PowerPC nginx-1.0.4]# ./configure \
> --prefix=/usr/local/nginx \
> --sbin-path=/usr/local/sbin/nginx \
> --conf-path=/etc/sysconfig/nginx/nginx.conf \
> --error-log-path=/var/log/nginx/error.log \
> --pid-path=/var/run/nginx.pid \
> --lock-path=/var/run/nginx.lock \
> --user=http \
> --group=web \
> --with-select_module \
> --with-poll_module \
> --with-http_image_filter_module \
> --with-http_sub_module \
> --with-http_dav_module \
> --with-http_flv_module \
> --with-http_gzip_static_module \
> --without-http_fastcgi_module \
> --without-http_uwsgi_module \
> --without-http_scgi_module \
> --http-log-path=/var/log/nginx/access.log \
> --http-client-body-temp-path=/tmp/nginx \
> --http-proxy-temp-path=/tmp/nginx \
> --without-mail_pop3_module \
> --without-mail_imap_module \
> --without-mail_smtp_module \
> --with-pcre

检查依赖,报错:

./configure: error: the HTTP image filter module requires the GD library.
You can either do not enable the module or install the libraries.


解决方案:yum install gd-devel
再次检查,通过。
编译概况为:

Configuration summary
+ using system PCRE library
+ OpenSSL library is not used
+ md5: using system crypto library
+ sha1: using system crypto library
+ using system zlib library

nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/sbin/nginx"
nginx configuration prefix: "/etc/sysconfig/nginx"
nginx configuration file: "/etc/sysconfig/nginx/nginx.conf"
nginx pid file: "/var/run/nginx.pid"
nginx error log file: "/var/log/nginx/error.log"
nginx http access log file: "/var/log/nginx/access.log"
nginx http client request body temporary files: "/tmp/nginx"
nginx http proxy temporary files: "/tmp/nginx"


make && make install 开始编译安装。之后恢复下之前的配置文件。
nginx -t 测试下配置文件,报错:

nginx: [emerg] the default path name "/tmp/nginx" has the same name as another default path, but the different levels, you need to redefine one of them in http section


看来缓存路径不能设成一样的,如果不像重新编译,就在配置文件里重写。
在nginx.conf 的http 块里加入
client_body_temp_path /tmp/nginx/request/;
一行即可。

之后就是hiawatha了,同样是7.5的版本,我之前编译过一次。不赘述了~
我的configure:
[root@PowerPC hiawatha-7.5]# ./configure \
> --prefix=/usr/local/hiawatha \
> --exec-prefix=/usr/local \
> --sysconfdir=/etc/sysconfig/hiawatha \
> --localstatedir=/var \
> --disable-largefile \
> --enable-chroot \
> --enable-command \
> --disable-ipv6 \
> --disable-monitor \
> --disable-ssl

然后就是缓存服务器Varnish,进入目录:
我的configure:
[root@PowerPC varnish-3.0.0]# ./configure \
> --prefix=/usr/local/varnish \
> --exec-prefix=/usr/local \
> --sysconfdir=/etc/sysconfig/varnish \
> --localstatedir=/var \
> --disable-largefile \
> --with-pcre-config=/usr/bin/pcre-config \
> --with-jemalloc

检查依赖,没有问题。make 编译,之后make install 安装。
最后在恢复下以前的配置文件,不过值得注意的是适用于2.1.x的配置格式可能与3.0.0有些出入,如引入了字符串 "+" 连接功能。

本来想,随便把vsftpd搞好,随便把pam_mysql 验证也搞定的~不过vsftpd 在编译的时候报错~这真的是很奇怪~

[root@PowerPC vsftpd-2.3.4]# make
gcc -o vsftpd main.o utility.o prelogin.o ftpcmdio.o postlogin.o privsock.o tunables.o ftpdataio.o secbuf.o ls.o postprivparent.o logging.o str.o netstr.o sysstr.o strlist.o banner.o filestr.o parseconf.o secutil.o ascii.o oneprocess.o twoprocess.o privops.o standalone.o hash.o tcpwrap.o ipaddrparse.o access.o features.o readwrite.o opts.o ssl.o sslslave.o ptracesandbox.o ftppolicy.o sysutil.o sysdeputil.o -Wl,-s `./vsf_findlibs.sh`
sysutil.o: In function `vsf_sysutil_open_file':
sysutil.c:(.text+0x1626): undefined reference to `__open64_2'
collect2: ld returned 1 exit status
make: *** [vsftpd] Error 1


可能我要发邮件问下开发者了~
[ ] ( 1903 次浏览 ) 永久链接 ( 3 / 2251 )
在CentOS 上编译安装 Hiawatha 7.5 

昨天接到通知,hiawatha 发布了最新版本7.5,修复了一些bug,官方标记紧急程度为低级。可是上面的一条更新引起了我的注意,就是反SQL注入可能导致崩溃的问题。

我心想这个问题我好像遇到了,因为我查看日志的事后,经常会有Garbage导致的服务器503问题。这个问题确实是很恶心,故而火速升级至7.5.

下载源码包(http://www.hiawatha-webserver.org/files/hiawatha-7.5.tar.gz),解压,进入目录,

我的configure:
[root@PowerPC hiawatha-7.5]# ./configure \
> --prefix=/usr/local/hiawatha \
> --exec-prefix=/usr/local \
> --sysconfdir=/etc/sysconfig \
> --localstatedir=/var \
> --datadir=/usr/lcoal/hiawatha/doc \
> --disable-largefile \
> --enable-chroot \
> --enable-command \
> --disable-ipv6 \
> --disable-monitor \
> --disable-ssl

检查依赖,通过,make && make check && make install 安装。

一切顺利。查看安装好的版本信息:
[root@PowerPC ~]# hiawatha -v
Hiawatha v7.5, cache, chroot, CommandChannel, URL toolkit, XSLT
Copyright (C) by Hugo Leisink <[email protected]>

这时候,进入配置文件目录 /etc/sysconfig/hiawatha,用之前备份的配置文件(主要是hiawatha.conf 和 php-fcgi.conf) 覆盖掉默认的。

再启动服务器,这就好了。

如果需要,最后在移除掉安装文件,make distclean 清理下,再 rm -rf * 删除即可.
[ ] ( 1860 次浏览 ) 永久链接 ( 3 / 2544 )
在Ubuntu 上源码安装 Go 语言环境 

最近一些事情也忙定下来了,于是开始打算把自己系统里面的一些开发语言的环境搞定,比如OpenJDK、PHP、Groovy以及Google App Engine 和 Android SDK 等等。

这些大都是从软件仓库里面直接安装的或者是直接下载二进制包的,没什么特殊的地方值得记录,只有Go 语言是从源码编译安装的,便记录一下。

首先,按照GO 官方的信息,确保系统里面存在必须的依赖。

如不满足,则安装:
sudo apt-get install gcc bison ed gawk libc6-dev python-setuptools python-dev build-essential

然后就是从Go 位于谷歌代码的源码库里面复制出一份最新的版本。由于Go 是使用户Mercurial 作为版本控制。所以,确保已经安装了 Mercurial(这个比较冷门,估计都没有)
安装即可:
sudo apt-get install mercurial

之后,克隆出一份代码到本地当前目录:
hg clone -u release https://go.googlecode.com/hg/ go

完了后,进入的源码目录下src目录,运行 all.bash 脚本,开始编译。
之后可能会花费一些时间,同时CPU的占用也会有所增加,正常~

直到屏幕中打印出如下的信息时,编译就算完成了。

--- cd ../test
1 known bugs; 0 unexpected bugs

ALL TESTS PASSED

---
Installed Go for linux/386 in /home/sharl/go.
Installed commands in /home/sharl/go/bin.
*** You need to add /home/sharl/go/bin to your $PATH. ***
The compiler is 8g.


这时候Go语言的二进制文件已经全部都生成了,进入到用户主目录(~)下,把整个Go文件夹移动到/usr/local 下(这是我的习惯,应用程序都安装在这里),之后编辑~/.profile 文件,加入如下的命令:

export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
export GOARCH=386
export GOOS=linux



保存,再注销,重新登入下,Go的 bin 下的命令都进入系统$PATH了。

下面来测试下,查看版本:
sharl@sharl-laptop:~$ 8g -V
8g version release.r57.1 8294

恩,有了.

随便编写个Go程序测试看看,按照Go官网(http://golang.org/)的"hello,world"案例,写个"hello,girl".囧rz

新建一个hello girl.go文件,
sharl@sharl-laptop:~$ ls -l |grep girl
-rw-r--r-- 1 sharl sharl 72 2011-06-01 18:59 hello girl.go

hello girl.go 内容为:
sharl@sharl-laptop:~$ cat "hello girl.go"
package main

import "fmt"

func main() {
fmt.Println("hello,GIRL!")
}

编译,产生链接文件:
sharl@sharl-laptop:~$ 8g "hello girl.go"
sharl@sharl-laptop:~$ ls -l |grep girl
-rw-r--r-- 1 sharl sharl 6670 2011-06-01 19:02 hello girl.8
-rw-r--r-- 1 sharl sharl 72 2011-06-01 18:59 hello girl.go

链接、生成可执行文件:
sharl@sharl-laptop:~$ 8l "hello girl.8"
sharl@sharl-laptop:~$ ls
8.out hello girl.8 mm.cfg 公共的 桌面
examples.desktop hello girl.go Ubuntu One 模板

运行:
sharl@sharl-laptop:~$ ./8.out
hello,GIRL!

看起来,成功了~
[ ] ( 1923 次浏览 ) 永久链接 ( 3 / 2534 )

<< <上一页 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 下一页> >>