Tag Archive for 'system'

Page 2 of 4

Apache 2.2.3 PHP 5.2.0 Mysql 4.1 Install

以 apache handler 和 fastcgi 两种方式安装 PHP 5.2.0, 并使用 –with-mysql 和 –with-mysqli 两种方式连接 Mysql 数据库

  1. 配置 PHP 安装
    1
    './configure' '--codefix=/opt/php5' '--with-apxs2=/opt/bin/apxs' '--enable-fastcgi' '--with-mysql=/usr/local/mysql' '--enable-calendar' '--enable-force-cgi-redirect' '--with-configure-file-path=/opt/php5/cgi' '--enable-trans-sid' '--with-gd' '--with-xml' '--with-ttf=/usr' '--with-freetype-dir=/usr' '--enable-exif' '--with-dom-xslt=/usr' '--with-jpeg-dir=/usr/local/jpeg6b' '--with-png-dir=/usr' '--with-zlib-dir=/usr' '--enable-ftp' '--with-curl=/usr' '--enable-mbstring' '--with-mysqli=/usr/local/mysql/bin/mysql_config' '--with-openssl=/usr' '--with-gettext' '--enable-sockets' '--enable-memory-limit' '--with-xmlrpc' '--enable-debug=no' '--enable-track-vars' '--with-iconv' '--enable-sqlite-utf8' '--with-pgsql=/opt/postgresql'
  2. 这里我还安装了 Postgresql 所以使用了 ‘–with-pgsql=/opt/postgresql’ ,不过奇怪的是 如果我使用
    1
    --with-pdo-mysql --with-pdo-pgsql

    就会出现配置安装的错误。

  3. 同时使用 mysql 和 mysqli 在 make 的时候可能会出现很多警告,在 MAKEFILE 文件中找到以 EXTRA_LIBS 开始的行,删除第二个 -lmysqlclient_r

SVN服务器搭建完全手册

  1. 准备,下载所需要文件.
  2. 检查已安装的 Apache2 是否已经安装了 mod_dav .
  3. 编译SVN,遇到的问题和解决方法
    1. 使用 默认文件系统(fsfs) 保存数据
    2. 使用 Berkeley DB 保存数据
  4. 配置Apache和SVN,测试.
  5. 其它小结
    1. 从Windows平台上数据转移
    2. 配置文件,使用其支持对文件中的 $Id$ 标签每次提交的时候自动更新版本信息.
    3. 基于路径的权限控制
    4. 常用SVN命令
  6. 相关资源

准备,下载所需要文件

本文测试环境

1
Linux MY_SERVER 2.6.9-5.ELsmp #1 SMP Wed Jan 5 19:30:39 EST 2005 i686 i686 i386 GNU/Linux

Apache 2.2.2

最新的版本 Subversion 可以在这里找到 :http://subversion.tigris.org/project_packages.html

检查已安装的 Apache2 是否已经安装了 mod_dav

如果已经成功安装了Apache,使用 httpd -M 来查看有没有安装 dav_module,如果没有的话 必须附加 ‘–enable-dav’ ‘–enable-dav-fs’ 两个参数重新编译 Apache,否则即使编译通过了svn,apache也会启动不起来.

编译APACHE2.2

  1. 修改部分源代码
    1
    # vi server/mpm/worker/worker.c

    找到下面几行,并改成如下的数值,其目的是在源码中修改apache可支持的 最大线程数和最大客户端数目。

    1
    2
    3
    4
    # define DEFAULT_SERVER_LIMIT 256
    # define MAX_SERVER_LIMIT 40000
    # define DEFAULT_THREAD_LIMIT 256
    # define MAX_THREAD_LIMIT 40000
  2. 编译配置
    优化编译选项及配置apache可加载的模块

    1
    2
    3
    4
    5
    # CFLAGS="-O6 -mpentiumpro -fomit-frame-pointer" CXX=gcc CXXFLAGS="-O6 -mpentiumpro -fomit-frame-pointer -felide-constructors -fno-exceptions -fno-rtti" \
    > ./configure --codefix=/usr/local/apache2.2 --enable-mods-shared=all \
    > --enable-so --with-mpm=worker --enable-deflate \
    > --enable-cache --enable-disk-cache --enable-mem-cache --enable-file-cache \
    > --enable-proxy --enable-suexec
  3. 编译及安装
    1
    # gmake && make install
  4. 优化apache配置选项
    修改MPM(多道处理器)参数

    1
    2
    # cd /usr/local/apache2.2
    # vi conf/extra/httpd-mpm.conf

    找到如下选项,并改成对应的数值

    1
    2
    3
    4
    5
    6
    7
    8
    ServerLimit 64
    ThreadLimit 128
    StartServers 8
    MaxClients 8192
    MinSpareThreads 50
    MaxSpareThreads 256
    ThreadsPerChild 128
    MaxRequestsPerChild 0

    修改apache2.2子进程所有者

    1
    2
    3
    4
    # vi /usr/local/apache2.2/conf/httpd.conf
    把daemon改为nobody
    User nobody
    Group nobody

编译SVN,遇到的问题和解决方法

使用默认的文件系统保存数据.

最终完整通过安装和测试的编译参数为:

1
2
3
./configure --with-apxs=/usr/local/apache2/bin/apxs \
--with-apr=/home/src/server/httpd-2.2.2/srclib/apr \
--with-apr-util=/home/src/server/httpd-2.2.2/srclib/apr-util
1
2
# make
# make install

其中 /home/src/server/ 为 httpd-2.2.2 源代码所在文件夹,根据实际情况调整一下.

遇到问题
  1. –with-apr 和 –with-apr-util 如果没有加上的话,即使编译成功了也会出现
    1
    Can’t set position pointer in file ‘/home/svn/repos/db/revs/0′: Invalid argument

    这样的错误提示.

  2. 暂时不能使用 Berkeley DB [* 已解决]
    svn保存文件更新数据库的方法有两个,一种是直接使用 fs (filesystem)来保存,另一种是通过Oracle提供支持的开源数据库 Berkeley DB 进行保存。但是如果加上 –with-berkeley-db=/usr/local/BerkeleyDB.4.4 就会configure时就会报错.

    1
    2
    configure: error: APR-UTIL was installed independently, it won’t be
    possible to use the specified Berkeley DB: /usr/local/BerkeleyDB.4.4

    我想 apr-unit 暂时不支持吧,我们就用默认的fs好了.

  3. 在make 的时候可能会遇到缺少 srclib/apr/libapr-1.la,srclib/apr-util/libaprutil-1.la 两个文件,找不到而make error.

    解决办法:/usr/local/apache2/lib/ 中找到,将其复制到源代码文件夹相应的位置中.

UPDATE!!!

使用 BerkeleyDB 保存数据

  1. 安装 BerkeleyDB
    1
    2
    3
    4
    5
    6
    7
    cd /usr/local/src
    $ wget http://downloads.sleepycat.com/db-4.3.29.tar.gz
    $ tar xzvf db-4.3.29.tar.gz
    $ cd /usr/local/src/db-4.3.29/build_unix
    $ ../dist/configure --enable-compat185
    $ make
    $ make install
  2. 更新apr和apr-util源代码
    1
    2
    3
    4
    5
    6
    7
    8
    # 清理编译后的.la文件
    $ cd /usr/local/src/httpd-2.2.3
    $ make clean
    $ cd /usr/local/src/subversion-1.3.2
    $ rm -rf apr
    $ rm -rf apr-util
    $ cp -rf /usr/local/src/httpd-2.2.3/srclib/apr ./
    $ cp -rf /usr/local/src/httpd-2.2.3/srclib/apr-util/ ./
  3. 编译安装
    1
    2
    3
    4
    5
    # /configure --with-apxs=/usr/local/apache2/bin/apxs \
    > --with-berkeley-db=/usr/local/BerkeleyDB.4.3 \
    > --with-ssl
    # make
    # make install
遇到问题
  1. BerkeleyDB 版本不能大于 4.3.否则同样会出现以下错误.
    1
    2
    configure: error: APR-UTIL was installed independently, it won’t be
    possible to use the specified Berkeley DB: /usr/local/BerkeleyDB.4.4

    主要是apr-util 暂时不支持4.4的版本.

  2. 必须更新apr,apr-util 源代码.
    subversion-1.3.2 自带的 apr-util 的版本是0.9.6的,必须升级为 1.2.7 虽然能编译过去。但在 svn checkout 的时候会提示

    1
    2
    svn: REPORT request failed on ‘/!svn/vcc/default’
    svn: REPORT of ‘/!svn/vcc/default’: Could not read status line: connection was closed by server.

    这个问题困扰了我很长时间,Google和官方论坛都无结果。后来昨天竟然自己无意中解决了,感动的得哭了:)

配置Apache和SVN,测试

成功编译svn后会在 httpd.conf 中自动加上

1
2
LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so

两个模块,没有的话,自行加上或检测是否真的编译成功.

假设我们现在要将一个名为 Lair 的项目导入到 SVN中

  1. Apache的配置
    在 conf/httpd.conf 或 conf/extra/httpd-vhosts.conf 中加入

    1
    2
    3
    4
    <Location /svn/Lair>
    DAV svn
    SVNPath /home/svn/Lair
    </Location>

    可以参考以下apache的配置,实现数据加密传输,用户身份验证.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    Listen 443

    AddType application/x-x509-ca-cert .crt
    AddType application/x-pkcs7-crl .crl.

    SSLPassPhraseDialog exec:/etc/sendsslpwd
    SSLSessionCache shmcb:/usr/local/apache2/logs/ssl_scache(512000)
    SSLSessionCacheTimeout 300
    SSLMutex file:/usr/local/apache2/logs/ssl_mutex

    <VirtualHost _default_:443>
    DocumentRoot /var/SVNRoot
    ServerName svn.yousite.com:443
    ServerAdmin [email protected]
    <Location />

    DAV svn
    SVNPath /var/SVNRoot
    AuthzSVNAccessFile /etc/svnserve.conf
    Satisfy Any
    AuthType Basic
    AuthName “yousite SVN Repository”
    AuthUserFile /etc/httpd-passwords.txt
    Require valid-user

    </Location>
    SSLEngine on
    SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
    SSLCertificateFile /etc/ssl/server.crt
    SSLCertificateKeyFile /etc/ssl/server.key

    </VirtualHost>

    更详细的配置说明文档 http://svnbook.red-bean.com/nightly/en/svn.ref.mod_dav_svn.conf.html

  2. 配置,并且测试SVN,

    创建一个新用户,用了保存仓库.

    1
    useradd -m svn

    创建一个新模块

    1
    2
    # su daemon #(apache是以daemon用户运行的,所以要切换身份,否则可能会报目录访问权限错误)
    # svnadmin create --fs-type fsfs /home/svn/Lair

    导入原来的项目

    1
    svn import /var/www/Lair http://localhost/svn/Lair -m ‘Initial import’

    重新建立工作目录

    1
    2
    # rm -rf /var/www/Lair  ##(注意备份!!)
    # svn checkout http://localhost/svn/Lair

    测试打开 http://localhost/svn/Lair

    如能看到一个你项目录列表,说明您成功了。

其它小结

  1. 数据转移:

    从 Windows 平台 SVN 服务器转移
    如果windows svn储存的格式也是dbd的话,直接将SVN的文件夹copy过来即可.然后
    执行 svnadmin recover /var/SVNRoot 检查一下数据库是否损坏.

    最后注意权限,确保 db 目录下的所有文件可写。

    1
    2
    chmod 755 db
    chmod 666 db/*

    否则checkout时出现以下错误,多数是因为 文件或者目录权限问题 引起的,可以尝试用 chown 或者 chmod 命令修改一下权限

    1
    2
    3
    4
    5
    6
    7
    8
    <m:human-readable errcode=”160029″>

    Could not open the requested SVN filesystem
    </m:human-readable>

    <m:human-readable errcode=”13″>
    Could not open the requested SVN filesystem
    </m:human-readable>

    另外一种方法没有测试过,原理大致和mysqldump一样,将svn导出为文本文件,然后重新导入,好处是可以避免因为存储格式不同而导致的数据转移困难。

    1
    2
    3
    4
    5
    6
    7
    # dump data to file (assuming a repo @ c:\repo):

    svnadmin dump c:\repo > c:\repo.txt
    # Copy the file over to linux:
    mkdir /repo
    svnadmin create /repo
    svnadmin load /repo < /repo.txt
  2. 设置访问控制

    当 httpd.conf 中 设置 AuthzSVNAccessFile 时,可以设置不同用户对不同目录的访问控制.以下是一个例子.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    [groups]
    root = admin.root
    web = user1,user2
    soft = user3,user4

    [/]
    @root = rw

    [/www]

    @web = rw

    [/soft]
    @soft = rw
  3. 详细的说明文档:http://svnbook.red-bean.com/nightly/en/svn.serverconfig.httpd.html

  4. 配置文件,使用其支持对文件中的 $Id$ 标签每次提交的时候自动更新版本信息(自动属性).
    1
    2
    3
    4
    5
    6
    7
    8
    Windows : C:\Documents and Settings\%USERNAME%\Application Data\Subversion\config
    Linux : ~\.subversion\config
    [miscellany]

    enable-auto-props = yes
    [auto-props]
    *.php=svn:keywords=Id
    *.html=svn:keywords=Id

    关于自动属性的更高级讨论

  5. 几条常用svn 命令
    1
    2
    3
    $ svn update
    $ svn add “filename”
    $ svn commit

参考

Ruby on Rails Windows安装问题

Ruby on Rails使用Windows上安装Ruby on Rails的时候,在使用gem安装Rails的时候遇到这样的问题

1
gem install rails --include-dependencies

错误提示找不到 ssleay32.dllzlib.dll,这时候需要下载下面这几个文件放到 \ruby-version\bin 这个目录下

DBD::mysql安装问题

在安装perl的DBD::mysql模块的时候遇到一些问题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$ perl -MCPAN -e shell
[....]
 Can't exec "mysql_config": No such file or directory at Makefile.PL line 76.
 
 Cannot find the file 'mysql_config'! Your execution PATH doesn't seem
 not contain the path to mysql_config. Resorting to guessed values!
 Can't exec "mysql_config": No such file or directory at Makefile.PL line 454.
 Can't exec "mysql_config": No such file or directory at Makefile.PL line 454.
 Can't exec "mysql_config": No such file or directory at Makefile.PL line 454.
 Can't exec "mysql_config": No such file or directory at Makefile.PL line 454.
 Can't exec "mysql_config": No such file or directory at Makefile.PL line 454.
 Can't exec "mysql_config": No such file or directory at Makefile.PL line 454.
 Failed to determine directory of mysql.h. Use
 [....]

进入DBD::mysql的代码安装目录

1
2
3
4
5
$ cd $HOME/.cpan/build/DBD-mysql-3.0008
$ perl --mysql_config=$MYSQL_PREFIX_DIR/bin/mysql_config
$ make
$ make test
$ make install

这样就安装成功了

Perl安装问题

Perl在测试服务器上安装perl5.8.8

1
2
$./configure.gnu --codefix=$HOME/local
make

结果出错啦~

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
make[1]: Leaving directory `/home/.salk/ndw/src/perl-5.8.6/x2p'

        Making B (dynamic)
opendir(./../../../../..): Permission denied at ../../lib/File/Find.pm line 597
Use of chdir('') or chdir(undef) as chdir() is decodecated at ../../lib/File/Find.pm line 741.
opendir(./..): Permission denied at ../../lib/ExtUtils/MakeMaker.pm line 165
Couldn't change to directory /home/.salk/ndw/C: No such file or directory at Makefile.PL line 18
Writing Makefile for B
Warning: No Makefile!
make[1]: Entering directory `/home/.salk/ndw/src/perl-5.8.6/ext/B'
make[1]: *** No rule to make target `config'.  Stop.
make[1]: Leaving directory `/home/.salk/ndw/src/perl-5.8.6/ext/B'
make config failed, continuing anyway...
make[1]: Entering directory `/home/.salk/ndw/src/perl-5.8.6/ext/B'
make[1]: *** No rule to make target `all'.  Stop.
make[1]: Leaving directory `/home/.salk/ndw/src/perl-5.8.6/ext/B'
make: *** [lib/auto/B/B.so] Error 2

1
$make minitest

来测试,结果在98.5%的地方出错了,没有办法,GOOGLE上搜索了一下,结果是编译的地方出错了,在 /tmp 下面编译一点问题都没有,看来是不是以后都要改变一下编译的习惯了? ;)

1
/tmp$ ./configure.gnu --codefix=$HOME/local && make && make test && make install

Installing Ruby on Rails with mod_fcgi for Apache 2

railsAfter a few hours of trial and error using advice from many different sites/posts, this is the process that I found successful in getting Ruby on Rails working with the Apache 2 fcgi module on linux. I hope this helps someone hang onto a few more hair follicles.

Before we begin, I can say that this was only successful when I did the setup in this order. Perhaps others have done it in a different way, but this worked for me. BTW, I using Redhat Enterprise 4.

First, we’ll install ruby.

1
2
3
4
5
6
7
curl -O ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.4.tar.gz
tar xvfz ruby-1.8.4.tar.gz
cd ruby-1.8.4
./configure --codefix=/usr/local
make
make install
cd ..

Just to make sure everything installed properly try this:

1
ruby --version

It should return something like this:

1
ruby 1.8.4 (2005-12-24) [i686-linux]

Now let’s install ruby gems.

1
2
3
4
5
curl -O http://rubyforge.org/frs/download.php/5207/rubygems-0.8.11.tgz
tar xvfz rubygems-0.8.11.tgz
cd rubygems-0.8.11
ruby setup.rb
cd ..

Now we need to install the FastCGI development kit.

1
2
3
4
5
6
7
curl -O http://www.fastcgi.com/dist/fcgi-2.4.0.tar.gz
tar xvfz fcgi-2.4.0.tar.gz
cd fcgi-2.4.0
./configure --codefix=/usr/local
make
make install
cd ..

Allrighty then. We’re moving now.
Continue reading ‘Installing Ruby on Rails with mod_fcgi for Apache 2′

linux系统下的多文件替换

又是一个老问题,不过对刚刚接触Unix/Linux的人来说还是非常管用的

1
find . -name "*.c" | xargs sed -i 's/xxx/yyy/g'

以安全的方式更改文件中的大小写

1
2
$cat toc.html |  tr '[:upper:]' '[:lower:]' > toc1.html
$mv toc1.html toc.html

使用rewrite实现永久重定向

blogit.3322.org在DreamHost上不能使用,怎么办?使用301永久重定向吧,找个可以使用rewrite的空间,把blogit.3322.org指向那里(保持fred.oracle1.comblogit.3322.org相同的目录结构),在根目录下.htaccess写入下面内容,这样如果有人从搜索引擎比如Google访问

1
<a href="http://blogit.3322.org/weblog/2006/11/10/dreamhost-now/">http://blogit.3322.org/weblog/2006/11/10/dreamhost-now/</a>

那就会自动重定向到

1
http://fred.oracle1.com/weblog/2006/11/10/dreamhost-now/
1
2
3
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*) http://fred.oracle1.com/$1 [R=301,L]
相关资料

301 redirect: 301代表永久性转移(Permanently Moved),301重定向是网页更改地址后对搜索引擎友好的最好方法,只要不是暂时搬移的情况,都建议使用301来做转址。

302 redirect: 302代表暂时性转移(Temporarily Moved ),在前些年,不少Black Hat SEO曾广泛应用这项技术作弊,目前,各大主要搜索引擎均加强了打击力度,象Google前些年对Business.com以及近来对BMW德国网站的惩罚。即使网站客观上不是spam,也很容易被搜寻引擎容易误判为spam而遭到惩罚。

meta fresh: 这在2000年前比较流行,不过现在已很少见。其具体是通过网页中的meta指令,在特定时间后重定向到新的网页,如果延迟的时间太短(约5秒之內),会被判断为spam。

SSH term problem

redhat rhel4SSH登录RedHat后使用一些命令出现

unknown terminal “rxvt-unicode”

是因为远程服务器 TERM 不能识别“rxvt-unicode”
$HOME/.bash_profile 中加入下面这样的(当然还有其他地方啦)就ok了。

1
2
3
4
5
export PATH
if [ "$TERM" = "rxvt-unicode" ]; then
       TERM="rxvt"
       export TERM
fi

rxvt-unicode 改为服务器识别的就是一个道理。

HOT PERL ONLINERS

Just enough perl to do most everything! Tom Christianson (spelling?)
once posted a canonical list of one line perl programs to do many common
command-line tasks.
It included:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# run contents of "my_file" as a program
perl my_file

# run debugger "stand-alone"
perl -d -e 42

# run program, but with warnings
perl -w my_file

# run program under debugger
perl -d my_file

# just check syntax, with warnings
perl -wc my_file

# useful at end of "find foo -print"
perl -nle unlink

# simplest one-liner program
perl -e 'print "hello world!\n"'

# add first and penultimate columns
perl -lane 'print $F[0] + $F[-2]'

# just lines 15 to 17
perl -ne 'print if 15 .. 17' *.pod

# in-place edit of *.c files changing all foo to bar
perl -p -i.bak -e 's/\bfoo\b/bar/g' *.c

# command-line that prints the first 50 lines (cheaply)
perl -pe 'exit if $. > 50' f1 f2 f3 ...

# delete first 10 lines
perl -i.old -ne 'print unless 1 .. 10' foo.txt

# change all the isolated oldvar occurrences to newvar
perl -i.old -pe 's{\boldvar\b}{newvar}g' *.[chy]

# command-line that reverses the whole file by lines
perl -e 'print reverse <>' file1 file2 file3 ....

# find palindromes
perl -lne 'print if $_ eq reverse' /usr/dict/words

# command-line that reverse all the bytes in a file
perl -0777e 'print scalar reverse <>' f1 f2 f3 ...

# command-line that reverses the whole file by paragraphs
perl -00 -e 'print reverse <>' file1 file2 file3 ....

# increment all numbers found in these files
perl i.tiny -pe 's/(\d+)/ 1 + $1 /ge' file1 file2 ....

# command-line that shows each line with its characters backwards
perl -nle 'print scalar reverse $_' file1 file2 file3 ....

# delete all but lines beween START and END
perl -i.old -ne 'print unless /^START$/ .. /^END$/' foo.txt

# binary edit (careful!)
perl -i.bak -pe 's/Mozilla/Slopoke/g' /usr/local/bin/netscape

# look for dup words
perl -0777 -ne 'print "$.: doubled $_\n" while /\b(\w+)\b\s+\b\1\b/gi'

# command-line that prints the last 50 lines (expensively)
perl -e 'lines = <>; print @@lines[ $#lines .. $#lines-50' f1 f2 f3 ...