Chinaunix首页 | 论坛 | 博客
  • 博客访问: 744042
  • 博文数量: 280
  • 博客积分: 10106
  • 博客等级: 上将
  • 技术积分: 3052
  • 用 户 组: 普通用户
  • 注册时间: 2007-10-31 17:10
文章分类

全部博文(280)

文章存档

2011年(2)

2010年(4)

2009年(4)

2008年(62)

2007年(208)

我的朋友

分类: LINUX

2007-11-05 17:41:10

公司里的服务器系统用的都是Redhat AS 4,对与我这样习惯了Debian的人来说,别提多反感了,但是越反感越来事儿,这不,前几天公司一台测试机的系统崩溃了,我得把LAMP环境重新搭建起来,用惯了APT的我很是不习惯RPM,所以相关软件都选择源代码安装。

Redhat本身的安装很简单,不必多言。下面说说AMP三样软件的情况,其中:Apache(httpd-2.2.3.tar.gz);MySQL(mysql-5.0.24a.tar.gz);PHP(php-5.1.6.tar.gz)。

先说说Apache:

tar zxvf httpd-2.2.3.tar.gz
cd httpd-2.2.3
./configure --enable-so --enable-rewrite=shared
make
make install

这里要说明的是,测试机出于方便性的考虑,我们选择了把PHP编译为Apache动态模块的方式,所以Apache使用了enable-so的参数,实际服务器的使用中,出于效率最优化的考虑,通常将PHP静态编译到Apache中去。还有在上面的编译中,我们附带使用了enable-rewrite的参数,激活了重写功能,其中shared是一个有趣的参数,使用它的话,重写模块会按照动态模块的方式建立,也就是说,会生成一个mod_rewrite.so文件,不使用它的话(直接--enable-rewrite),重写模块会被静态编译到Apache里去。安装好Apache后,使用“httpd -l”命令可以查看安装了静态模块,如果要加载动态模块的话,就在httpd.conf文件里添加相应的LoadModule语句就可以了。

LoadModule rewrite_module modules/mod_rewrite.so

注意:每次修改httpd.conf文件后,先用“httpd -t”命令检查语法是否正确,得到肯定的答案后再重启apache服务。

如果你想用redhat的chkconfig命令来管理apache的启动,那么你需要执行一下步骤:

cp /usr/local/apache2/bin/apachectl /etc/init.d/apache
vi /etc/init.d/apache
加入一下注释,以便chkconfig识别相关信息:
# Comments to support chkconfig on RedHat Linux
# chkconfig: 2345 85 15
# description: Apache is a World Wide Web server

然后:
chkconfig --add apache

注意:确保apache脚本有可执行的属性,如果没有则:chmod +x apache

补充(2006-12-20):今天服务器的HTTPD进程竟然达到了好几千个,内存也消耗光了,修改了一下httpd.conf配置,把KeepAlive设置成Off,搞定了。

再说说MySQL:

groupadd mysql
useradd -g mysql mysql
tar zxvf mysql-5.0.24a.tar.gz
cd mysql-5.0.24a
./configure --prefix=/usr/local/mysql \
--with-charset=utf8 \
--with-collation=utf8_general_ci \
--with-extra-charsets=all
make
make install
cp support-files/my-medium.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
cd /usr/local/mysql
./bin/mysql_install_db --user=mysql
chown -R root .
chown -R mysql var
chgrp -R mysql .

/etc/init.d/mysql start #启动,呵呵

可以用“chkconfig --add mysql”把启动脚本加到chkconfig的管理范围内。当然写到rc.local里也可以,不过还是chkconfig专业点。

注释:chkconfig是redhat专有命令,如果你使用的是debian/ubuntu系统的话,对应的命令可以使用sysvconfig,如果没有的话可以使用“aptitude install sysvconfig”安装。

注意:确保mysql脚本有可执行的属性,如果没有则:chmod +x /etc/init.d/mysql

如果你是全新安装的话,那么缺省状态下不用修改my.cnf的内容MySQL就能正常运行,不过我这次属于升级安装,考虑到以前的数据库,还是需要重新写了一个my.cnf配置一下,如下:

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# If you have a very slow DNS and many hosts, you can get more
# performance by either disabling DNS lookups
skip-name-resolve

# The back_log value indicates how many requests can be stacked
# during this short time before MySQL momentarily stops answering
# new requests. You need to increase this only if you expect a large
# number of connections in a short period of time. 
back_log=500

# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1

[mysql.server]
user=mysql
basedir=/usr/local

[mysqld_safe]
err-log=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

当你连接MySQL服务器的时候,可能会出现找不到“/tmp/mysql.sock”文件的情况,这是因为MySQL默认把socket文件安装到了/var/lib/mysql/mysql.sock路径上,只要做一个符号链接就OK了。

ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

注:[mysqld]中的skip-name-resolve很重要,不然在“show processlist”的时候,可能会发现MySQL会出现大量类似“unauthenticated user”的信息。这主要是大量的网络连接,并且DNS反应慢造成的。类似的原因,back_log也很重要。

MySQL的系统变量设置是一个很重要的环节,具体查考此链接:http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html

最后看看PHP:

tar zxvf php-5.1.6.tar.gz
cd php-5.1.6
./configure \
--with-apxs2=/usr/local/apache2/bin/apxs \
--with-mysql=/usr/local/mysql
make
make install

附:本来想把GD也编译到PHP里去,虽然每次编译后phpinfo()中能看到GD的信息,但是在gd_info()中freetype始终是false,有空了再搞一下。唉!

附录:

今天上班把PHP的gd重新编译了一下,加入了freetype的支持,过程如下:

安装zlib支持:
tar zxvf zlib-1.2.3.tar.gz
cd zlib-1.2.3
./configure
make
make install

安装png支持:
tar zxvf libpng-1.2.12-no-config.tar.gz
cd libpng-1.2.12-no-config
cp scripts/makefile.linux makefile
make test
make install

安装jpg支持:
tar zxvf jpegsrc.v6b.tar.gz
cd jpeg-6b
./configure --enable-shared --enable-static
make
make install

安装freetype支持:
tar zxvf freetype-2.2.1.tar.gz
cd freetype-2.2.1
./configure
make
make install

安装gd支持:
tar zxvf gd-2.0.33.tar.gz
cd gd-2.0.33
./configure \
--with-png=/usr/local \
--with-jpeg=/usr/local \
--with-freetype=/usr/local
make
make install

把安装好的gd集成到php中去:
tar zxvf php-5.1.6.tar.gz
cd php-5.1.6
./configure \
--with-apxs2=/usr/local/apache2/bin/apxs \
--with-mysql=/usr/local/mysql \
--with-zlib=/usr/local \
--with-gd=/usr/local \
--with-jpeg-dir=/usr/local \
--with-png-dir=/usr/local \
--with-zlib-dir=/usr/local \
--with-freetype-dir=/usr/local \
--enable-gd-native-ttf \
--enable-mbstring \
--with-curl
make
make install

注意:Linux下采用源代码安装软件,一般解压缩后都会有一个INSTALL文件,里面会介绍安装的详细步骤。

相关软件:

zlib: 
pgn: 
jpg: 
freetype: 
gd: 

注意:软件安装完成后,相关源代码最好留着,以方便以后修改软件设置的时候重新编译使用,比如我一般建立一个“/usr/src/software”目录,把源代码都放到此目录中,并且最好记住每个软件的编译参数。还有一点要提醒一下,每次重新编译前,最好先执行一下“make clean”命令,以免以前的编译过程对现在产生影响。

阅读(442) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~