WEB开发网
开发学院操作系统CentOS CentOS编译安装开发包与相关环境构架 阅读

CentOS编译安装开发包与相关环境构架

 2010-05-28 00:45:18 来源:WEB开发网   
核心提示:特别值得一提的是CentOS编译安装有很多值得学习的地方,这里我们主要介绍CentOS编译安装相关系统,CentOS编译安装开发包与相关环境构架,包括介绍CentOS开发包等方面,CentOS编译安装mysql, apache, php, Zend Optimizer等基本环境,功能越多,越容易出错,1. 使用 yum

特别值得一提的是CentOS编译安装有很多值得学习的地方,这里我们主要介绍CentOS编译安装相关系统,包括介绍CentOS开发包等方面。CentOS编译安装mysql, apache, php, Zend Optimizer等基本环境。

1. 使用 yum 程序安装所需开发包(以下为标准的rpm包名称)
# yum install gcc gcc-c++ gcc-g77 flex bison autoconf automake bzip2-devel zlib-devel ncurses-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel pam-devel openssl-devel libxml2-devel gettext-devel pcre-devel
#这里我们将CentOS编译安装GD所必须的一些小软件比如libpng,libtiff,freetype,libjpeg,gettext-devel等先用RPM 的方式一并安装好,避免手动CentOS编译安装浪费时间,同时也能避免很多错误,这几个小软件的编译很麻烦。这几个小软件编译错误了,GD当然安装不了,php5的编译当然也没戏了。所以我们抓大放小,对这些小牛鬼蛇神采取快速简洁的方式进行安装。并且对服务器的性能也不能产生什么影响。
另外libxml2系统已经默认安装了,所以我们不需要手工编译了,直接安装它的开发包就行了。

2. 源码CentOS编译安装所需包 (Source)
(1) GD2
# cd /usr/local/src
# wget http://www.libgd.org/releases/gd-2.0.35.tar.gz
# tar xzvf gd-2.0.35.tar.gz
# cd gd-2.0.35
# yum install libtool libtool-ltdl
# aclocal
# CHOST="i686-pc-linux-gnu" CFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" CXXFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -felide-constructors -fno-exceptions -fno-rtti -fomit-frame-pointer" ./configure --prefix=/usr/local/gd2 --mandir=/usr/share/man
// 注意,CHOST="i686-pc-linux-gnu" CFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" CXXFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -felide-constructors -fno-exceptions -fno-rtti -fomit-frame-pointer" 这个环境参数只针对intel P4 芯片,如果你的CPU是AMD的,注意不能使用。请查看相应的编译优化参数。否则程序会无法编译,即使编译成功也无法运行,嘿嘿。
关于其他CPU的优化参见我的BLOG的一篇转贴:
http://www.cnprint.org/bbs/blogs/1/blog43.html
//./configure 配置。
# make //make 是用来编译的,它从 Makefile 中读取指令,然后编译。
# make install //make install 是用来对CentOS编译安装的,它也从 Makefile 中读取指令,安装到指定的位置。
(2) Apache 日志截断程序
# cd /usr/local/src
# wget http://cronolog.org/patches/cronolog-1.7.0-beta.tar.gz
# tar cronolog-1.7.0-beta.tar.gz
# cd cronolog-1.7.0-beta
#CHOST="i686-pc-linux-gnu" CFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" CXXFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -felide-constructors -fno-exceptions -fno-rtti -fomit-frame-pointer" ./configure --prefix=/usr/local/cronolog && make && make install

3、CentOS编译安装mysql 5.0.50
mysql 5.0.50是企业版本,貌似双数版本都是企业版本了。个人觉得代码质量要比社区版本要好一些。大家可以下载,免费使用。并不需要向mysql公司交钱。
#cd /usr/local/src
# wget http://mirror.provenscaling.com/mysq...-5.0.50.tar.gz
# tar xzvf mysql-5.0.50.tar.gz
# cd mysql-5.0.50
修改mysql 客户端最大连接数, 默认的只有100,远远达不到我们的要求。
# vi sql/mysqld.cc
搜索找到下面一行:
{"max_connections", OPT_MAX_CONNECTIONS,
"The number of simultaneous clients allowed.", (gptr*) &max_connections,
(gptr*) &max_connections, 0, GET_ULONG, REQUIRED_ARG, 100, 1, 16384, 0, 1,
0},
将其中的100改为1500, 当然小点也可以,根据你的需要来,不建议改的太大。
{"max_connections", OPT_MAX_CONNECTIONS,
"The number of simultaneous clients allowed.", (gptr*) &max_connections,
(gptr*) &max_connections, 0, GET_ULONG, REQUIRED_ARG, 1500, 1, 16384, 0, 1,
0},
保存。
# CHOST="i686-pc-linux-gnu" CFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" CXXFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -felide-constructors -fno-exceptions -fno-rtti -fomit-frame-pointer" ./configure --prefix=/usr/local/mysql --localstatedir=/var/lib/mysql --with-comment=Source --with-server-suffix=-enterprise-gpl --with-mysqld-user=mysql --without-debug --with-big-tables --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=gbk,latin1 --with-pthread --enable-static --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --enable-assembler --without-innodb --without-ndb-debug --without-isam --enable-local-infile --with-readline --with-raid
配置成功会提示:
MySQL has a Web site at http://www.mysql.com/ which carries details on the
latest release, upcoming features, and other information to make your
work or play with MySQL more productive. There you can also find
information about mailing lists for MySQL discussion.
Remember to check the platform specific part of the reference manual for
hints about installing MySQL on your platform. Also have a look at the
files in the Docs directory.
Thank you for choosing MySQL!
# make
编译的时间可能会比较长,毕竟优化的比较厉害。
# make install
CentOS编译安装完成后执行后续操作:
# useradd mysql //添加 mysql 用户
# cd /usr/local/mysql
# bin/mysql_install_db --user=mysql
# chown -R root:mysql . //设置权限,注意后面有一个 "."
# chown -R mysql /var/lib/mysql //设置 mysql 目录权限
# chgrp -R mysql . //注意后面有一个 "."
# cp share/mysql/my-medium.cnf /etc/my.cnf
# cp share/mysql/mysql.server /etc/rc.d/init.d/mysqld //开机自动启动 mysql。
# chmod 755 /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld
#添加LIB PATH
echo "/usr/local/mysql/lib" >> /etc/ld.so.conf && ldconfig
vi /etc/my.cnf
修改 MySQL 配置,增加部分优化参数,如下:
[mysqld]
ft_min_word_len=2
运行以下命令即可启动 MySQL 服务器:
# /etc/rc.d/init.d/mysqld start //启动 MySQL
# bin/mysqladmin -u root password "password_for_root"
# service mysqld stop //关闭 MySQL

4. CentOS编译安装 Apache
# cd /usr/local/src
# wget http://www.ip97.com/apache.org/httpd/httpd-2.2.6.tar.gz
# tar zxvf httpd-2.2.6.tar.gz
# cd httpd-2.2.6
先依次安装apr和apr-util
# cd srclib/apr
# CHOST="i686-pc-linux-gnu" CFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" CXXFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -felide-constructors -fno-exceptions -fno-rtti -fomit-frame-pointer" ./configure --prefix=/usr/local/apr --enable-threads --enable-other-child --enable-static
# make && make install
# cd ../apr-util
# CHOST="i686-pc-linux-gnu" CFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" CXXFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -felide-constructors -fno-exceptions -fno-rtti -fomit-frame-pointer" ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/ --with-mysql=/usr/local/mysql
# make && make install
cd /usr/local/src/httpd-2.2.6
# CHOST="i686-pc-linux-gnu" CFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" CXXFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -felide-constructors -fno-exceptions -fno-rtti -fomit-frame-pointer" ./configure --prefix=/usr/local/apache2 --enable-mods-shared=all --with-mysql=/usr/local/mysql --enable-cache --enable-file-cache --enable-mem-cache --enable-disk-cache --enable-static-support --enable-static-htpasswd --enable-static-htdigest --enable-static-rotatelogs --enable-static-logresolve --enable-static-htdbm --enable-static-ab --enable-static-checkgid --disable-cgid --disable-cgi --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --enable-ssl --with-ssl=/usr/include/openssl --with-pcre
# make
# make install
注解:
./configure //配置源代码树
--prefix=/usr/local/apache2 //体系无关文件的顶级安装目录PREFIX ,也就Apache的安装目录。
--enable-module=so //打开 so 模块,so 模块是用来提 DSO 支持的 apache 核心模块
--enable-mods-shared=all //编译全部的模板,对于不需要我们可以在httpd.conf去掉。
--enable-cache //支持缓存
--enable-file-cache //支持文件缓存
--enable-mem-cache //支持记忆缓存
--enable-disk-cache //支持磁盘缓存
--enable-static-support //支持静态连接(默认为动态连接)
--enable-static-htpasswd //使用静态连接编译 htpasswd - 管理用于基本认证的用户文件
--enable-static-htdigest //使用静态连接编译 htdigest - 管理用于摘要认证的用户文件
--enable-static-rotatelogs //使用静态连接编译 rotatelogs - 滚动 Apache 日志的管道日志程序
--enable-static-logresolve //使用静态连接编译 logresolve - 解析 Apache 日志中的IP地址为主机名
--enable-static-htdbm //使用静态连接编译 htdbm - 操作 DBM 密码数据库
--enable-static-ab //使用静态连接编译 ab - Apache HTTP 服务器性能测试工具
--enable-static-checkgid //使用静态连接编译 checkgid
--disable-cgid //禁止用一个外部 CGI 守护进程执行CGI脚本
--disable-cgi //禁止编译 CGI 版本的 PHP
--enable-ssl // 编译 ssl模块。
我们不再使用worker模式编译apache,worker模式和php貌似有一些不协调不稳定之处。所以使用了默认的perfork模式。
将apache设置成开机自启动:
在/etc/rc.d/rc.local文件中加入一行
/usr/local/apache2/bin/apachectl start
这样每次重新启动系统以后,apache也会随系统一起启动.
或者将apache安装为系统服务
# cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd
然后 vi /etc/rc.d/init.d/httpd 添加(#!/bin/sh下面)
# chkconfig: 2345 50 90
# description: Activates/Deactivates Apache Web Server
最后,运行chkconfig把Apache添加到系统的启动服务组里面:
# chkconfig --add httpd
# chkconfig httpd on

5、CentOS编译安装php 5.2.5
Suhosin是php增强型安全补丁,可以编译到静态内核中,也可以编译成php动态扩展。我个人强烈你建议安装成静态内核。Suhosin已经进入 Gentoo Linux、FreeBSD、OpenSuSE Linux、Mandriva Linux、Debian Linux官方包。下面的以下先说静态安装步骤。当然你也可以在安装php后将它编译成php的动态扩展。
# cd /usr/local/src
# wget http://cn.php.net/get/php-5.2.5.tar.gz/from/this/mirror
wget http://www.hardened-php.net/suhosin/...9.6.2.patch.gz
# tar zxvf php-5.2.5.tar.gz
# gunzip suhosin-patch-5.2.5-0.9.6.2.patch.gz
# cd php-5.2.5
# patch -p 1 -i ../suhosin-patch-5.2.5-0.9.6.2.patch
# ./buildconf --force
# CHOST="i686-pc-linux-gnu" CFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" CXXFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -felide-constructors -fno-exceptions -fno-rtti -fomit-frame-pointer" ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-pear=/usr/share/php --with-zlib-dir --with-bz2 --with-libxml-dir=/usr --with-gd=/usr/local/gd2 --enable-gd-native-ttf --enable-gd-jis-conv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-ttf=shared,/usr --enable-mbstring --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-config-file-path=/etc --with-iconv --disable-ipv6 --enable-static --enable-zend-multibyte --enable-inline-optimization --enable-zend-multibyte --enable-sockets --enable-soap --with-openssl --with-gettext --enable-suhosin
配置成功会提示:
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+
Thank you for using PHP.
# make
# make test
# make install
# cp php.ini-recommended /etc/php.ini
# echo "/usr/local/php/lib" >> /etc/ld.so.conf && ldconfig
在这里也顺便说一下将suhosin安装成为php的动态扩展的方法。毕竟网上根本不见它的中文安装教程。
虽然我个人不推荐这种方式。
wget http://www.hardened-php.net/suhosin/...sin-0.9.20.tgz
tar zxvf suhosin-0.9.20.tgz
cd suhosin-0.9.20
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
会提示编译的模块存在的目录,记住它。
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20060613/
然后在php.ini中增加一行下列语句。
extension="/usr/local/php/lib/php/extensions/no-debug-zts-20060613/suhosin.so"

6、整合apache 与php
# vi /usr/local/apache2/conf/httpd.conf
在最后一行加上:
AddType application/x-httpd-php .php
查找:(设置 WEB 默认文件)
DirectoryIndex index.html
修改为:
DirectoryIndex index.php index.html index.htm
找到这一段:
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride none
更改为AllowOverride all
允许apache rewrite
保存httpd.conf,退出。
# /usr/local/apache2/bin/apachectl restart //重启 Apache
这时会出现错误:
/usr/local/apache2/bin/apachectl start
httpd: Syntax error on line 107 of /usr/local/apache2/conf/httpd.conf: Cannot load /usr/local/apache2/modules/libphp5.so into server: /usr/local/apache2/modules/libphp5.so: cannot restore segment prot after reloc: Permission denied
不急,我们慢慢解决。
这个Permission denied问题,在centos 5下面一般是Selinux引起的,作为生产用服务器,我建议你千万别草率地关掉Selinux一了百了。就像家里的防盗网,阻碍了你的猫自由进出窗户,你不能为了猫方便,就把防盗网简单拆除是同样的道理。我看见网上许多人建议把Selinux简单关闭来解决这个问题,这是削足适履的做法,不值得提倡。
我们可以这样操作:
# audit2allow -a //查看究竟问题出在什么地方
<no matches>
allow unconfined_t usr_t:file execmod;
allow useradd_t var_log_t:file { read write };
然后
# cd /etc/selinux/targeted/modules/
# audit2allow -M local -d
屏幕产生如下提示:
Generating type enforcment file: local.te
Compiling policy
checkmodule -M -m -o local.mod local.te
semodule_package -o local.pp -m local.mod
******************** IMPORTANT ***********************
In order to load this newly created policy package into the kernel,
you are required to execute
semodule -i local.pp
我们运行
# semodule -i local.pp
这样就让Selinux加载了新的规则。
更详细的内容请看我在BLOG上的转贴:
http://www.cnprint.org/bbs/blogs/1/blog48.html
重启apache
哈哈,apache不会再报错了吧?
这样我保留了selinux的功能,同时apache也能正常运行。
PHP5.1.x开始需要设置时区,默认时区与中国时区差8个小时,这种情况需要在php.ini中这么设置,找到date.timezone,去掉前面的分号,修改为以下值,大陆地区可用的值是:Asia/Chongqing ,Asia/Shanghai ,Asia/Urumqi (依次为重庆,上海,乌鲁木齐)
不然一些php程序的时间老是和中国标准时间相差8个小时。我的我的VBB论坛在windows上就是这样。这儿有亚洲地区的对应时区。
http://www.php.net/manual/en/timezones.asia.php

7、CentOS编译安装 Zend Optimizer
# cd /usr/local/src
# wget http://downloads.zend.com/optimizer/...21-i386.tar.gz
# tar xzvf ZendOptimizer-3.3.0-linux-glibc21-i386.tar.gz
# ./ZendOptimizer-3.3.0-linux-glibc21-i386/install.sh
按照它的提示一步步进行就行了。
总之一句话。如果你的服务器环境不需要ZendOptimizer,那么能不安就不安装这个。避免和eaccelerator冲突。

8. 查看确认CentOS编译安装 L.A.M.P 环境信息
vi /usr/local/apache2/htdocs/phpinfo.php
新增加下面一行,并保存。
<?php phpinfo(); ?>
# chmod 755 /usr/local/apache2/htdocs/phpinfo.php
用浏览器打开 http://192.168.9.150/phpinfo.php
检查 phpinfo中的各项信息是否正确。
测试php与mysql的连接
# vi /usr/local/apache2/htdocs/testdb.php
增加下面几行,并保存。
<?php
$link=mysql_connect('localhost','root','yourpassword');
if(!$link) echo "fail";
else echo "success";
mysql_close();
?>
# chmod 755 /usr/local/apache2/htdocs/testdb.php
# service mysqld start
用浏览器打开 http://192.168.9.150/testdb.php
如果输出success就OK了
到这一步,一个基本的lamp就建立完成了。如果你是初学者,下面的步骤根据需要参考,不必全部照做,记住一句话,功能越多,越容易出错,在任何领域都是这样。

Tags:CentOS 编译

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接