WEB开发网
开发学院操作系统CentOS CentOS LEMP系统安装编译安装基本环境 阅读

CentOS LEMP系统安装编译安装基本环境

 2010-05-07 13:02:27 来源:WEB开发网   
核心提示:在向大家详细介绍CentOS LEMP之前,首先让大家了解下CentOS LEMP,CentOS LEMP系统安装编译安装基本环境,然后全面介绍CentOS LEMP,希望对大家有用,编辑php.ini把disable_functions里的phpinfo去掉,仍后重启服务,CentOS LEMP构建高性能WEB服务器

在向大家详细介绍CentOS LEMP之前,首先让大家了解下CentOS LEMP,然后全面介绍CentOS LEMP,希望对大家有用。CentOS LEMP构建高性能WEB服务器(第三版).

一、CentOS LEMP系统安装

1. 系统分区建议/boot 100M (大约100左右)SWAP     物理内存的2倍(如果你的物理内存大于4G,分配4G即可)/ 分区15~20G/usr/local 20G   (用于安装软件)/data 剩余所有空间.【注】具体分区请根据相关业务划分,具体安装本文不作介绍安装过程中选择最少的包,采用文本模式安装请不要安装图形。

2.系统初始化系统初始化脚本(根据具体需求关闭不需要的服务)# shinit_network.sh       //下载本文提供的scripts.tar.gz包,即可找到此脚本.

二、CentOS LEMP编译安装基本环境

1. CentOS LEMP安装准备

1.1CentOS LEMP系统软件包安装规范系统约定软件源代码包存放位置    /usr/local/src源码包编译安装位置(prefix)   /usr/local/software_name脚本以及维护程序存放位置  /usr/local/sbinMySQL 数据库位置   /data/mysql/data(可按情况设置)网站根目录         /data/www/wwwroot(可按情况设置)虚拟主机日志根目录   /data/logs(可按情况设置)Nginx运行账户www:wwwinstall_software_name.sh     //存放编译参数脚本习惯将所有编译脚本存放在install_software_name.sh便于升级和更新软件.

创建网站账号及相关存放目录#add_user.sh /usr/sbin/groupadd www/usr/sbin/useradd -g www wwwmkdir -p /data/www/wwwrootchmod +w /data/www/wwwrootchown www:www /data/www/wwwroot -R 复制代码

1.2CentOS LEMP系统环境部署及调整检查系统是否正常#tail -n100 /var/log/messages(检查有无系统级错误信息)#dmesg (检查硬件设备是否有错误信息)#ifconfig(检查网卡设置是否正确)#ping www.linuxtone.org  (检查网络是否正常)

1.3CentOS LEMP使用 yum 程序安装所需开发包(以下为标准的 RPM 包名称)添加国内镜像源加速软件安装下载速度请参照:http://bbs.linuxtone.org/thread-158-1-1.html
yum -y install ntp vim-enhanced gcc gcc-c++gcc-g77 flex bison autoconf automake bzip2-devel  "ncurses-devel openssl-devel libtool*zlib-devel libxml2-devel libjpeg-devel libpng-devel libtiff-devel  "fontconfig-devel freetype-devel libXpm-develgettext-devel curl curl-devel pam-devel "e2fsprogs-devel krb5-devel libidnlibidn-devel 复制代码

1.4定时校正服务器时钟,定时与中国国家授时中心授时服务器同步#crontab -e加入一行: 15 3 * * * /usr/sbin/ntpdate 210.72.145.44> /dev/null 2>&1 复制代码

1.5下载编译相关的源码包.#vi list 在list文件里填入以后下载地址列表.官方下载软件包名: #nginxftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.8.tar.gzhttp://sysoev.ru/nginx/nginx-0.7.30.tar.gz#PHP-GD-LIB
http://www.libgd.org/releases/gd-2.0.35.tar.bz2
http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.12.tar.gz
http://jaist.dl.sourceforge.net/sourceforge/mcrypt/libmcrypt-2.5.8.tar.bz2
http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?modtime=1228695303&big_mirror=0
http://jaist.dl.sourceforge.net/sourceforge/mcrypt/mcrypt-2.6.7.tar.gz

#MySQLhttp://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.30.tar.gz/from/http://mysql.cdpa.nsysu.edu.tw/

#phphttp://cn.php.net/get/php-5.2.8.tar.bz2/from/cn2.php.net/mirror
http://php-fpm.anight.org/downloads/head/php-5.2.8-fpm-0.5.10.diff.gz

#PHP-EXThttp://pecl.php.net/get/memcache-2.2.4.tgz
http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
http://bart.eaccelerator.net/source/0.9.5.3/eaccelerator-0.9.5.3.tar.bz2复制代码#wget -i list

2. 编译安装软件包 源码编译安装所需包(Source)

1.1 编译安装Nginx tar zxvf pcre-7.8.tar.gzcd pcre-7.8./configure && make && makeinstall 复制代码tar zxvf nginx-0.7.30.tar.gzcd nginx-0.7.30./configure --user=www --group=www--prefix=/usr/local/nginx/ --with-http_stub_status_module--with-openssl=/usr/lib make && make install 复制代码

1.2编译安装GD及相关的LIB. tar jxvf gd-2.0.35.tar.bz2cd gd-2.0.35./configure --prefix=/usr/local/gd2&& make && make installtar zxvf libiconv-1.12.tar.gz 复制代码cd libiconv-1.12./configure --prefix=/usr && make&& make installtar jxvf libmcrypt-2.5.8.tar.bz2 复制代码cd libmcrypt-2.5.8./configure --prefix=/usr && make&& make install

复制代码tar zxvf mhash-0.9.9.tar.gzcd mhash-0.9.9./configure --prefix=/usr && make&& make install 复制代码# vi /etc/ld.so.conf添加/usr/lib include ld.so.conf.d/*.conf/usr/lib 复制代码# ldconfig

【注】ldconfig 命令的用途,主要是在默认搜寻目录(/lib和/usr/lib)以及动态库配置文件/etc/ld.so.conf内所列的目录, 而当用户安装了一个新的动态链接库时,就需要手工运行这个命令。 tar zxvf mcrypt-2.6.7.tar.gz[code]cd mcrypt-2.6.7/configure --prefix=/usr && make&& make install 复制代码

1.3 编译安装MySQL#sh install_mysql.sh//具体脚本如下: CHOST="x86_64-pc-linux-gnu"CFLAGS="-march=nocona -O3 -pipe"CXXFLAGS="${CFLAGS}"./configure "
"--prefix=/usr/local/mysql" "
"--localstatedir=/data/mysql/data" "
"--with-comment=Source" "
"--with-server-suffix=-Linuxtone.Org" "
"--with-mysqld-user=mysql" "
"--without-debug" "
"--with-big-tables" "
"--with-charset=gbk" "
"--with-collation=gbk_chinese_ci" "
"--with-extra-charsets=all" "
"--with-pthread" "
"--enable-static" "
"--enable-thread-safe-client" "
"--with-client-ldflags=-all-static" "
"--with-mysqld-ldflags=-all-static" "
"--enable-assembler" "
"--with-plugins=all" "
"--without-ndb-debug"

make
make install
useradd mysql -d /data/mysql -s/sbin/nologin
/usr/local/mysql/bin/mysql_install_db--user=mysql
cd /usr/local/mysql
chown -R root:mysql .
mkdir -p /data/mysql/data
chown -R mysql /data/mysql/data
cp share/mysql/my-huge.cnf /etc/my.cnf
cp share/mysql/mysql.server/etc/rc.d/init.d/mysqld
chmod 755 /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
/etc/rc.d/init.d/mysqld start
cd /usr/local/mysql/bin

for i in *; do ln -s /usr/local/mysql/bin/$i/usr/bin/$i; done 复制代码【注】编译mysql前请正确配置好主机名,否则不能正常启动.
例如:[[email protected]]# cat /etc/hosts # Do not remove the following line, or various programs# that require network functionality will fail.127.0.0.1  localhost.localdomainlocalhost192.168.1.104  lemp.linuxtone.org

复制代码【注】将本文提供下载的scripts.tar.gz包中的my.cnf替换你的/etc/my.cnf,并根据你的硬件参数做相关调整,并可以利用包中的tuning-primer.sh 做初步性能调优。

1.4 编译安装PHP-FastCGI tar jxvf php-5.2.8.tar.bz2gzip -cd php-5.2.8-fpm-0.5.10.diff.gz| patch -d php-5.2.8 -p1cd php-5.2.8 复制代码#sh install_php.sh//具体脚本如下 CHOST="i686-pc-linux-gnu"CFLAGS="-march=prescott-O3 -pipe -fomit-frame-pointer"CXXFLAGS="${CFLAGS}"./configure "
"--prefix=/usr/local/php-fcgi" "
"--enable-fastcgi" "
"--enable-fpm" "
"--enable-discard-path" "
"--enable-force-cgi-redirect""
"--with-config-file-path=/usr/local/php-fcgi/etc" "
"--enable-zend-multibyte" "
"--with-mysql=/usr/local/mysql" "
"--with-libxml-dir" "
"--with-xmlrpc" "
"--with-gd=/usr/local/gd2" "
"--with-jpeg-dir" "
"--with-png-dir" "
"--with-bz2" "
"--with-freetype-dir" "
"--with-iconv-dir" "
"--with-zlib-dir" "
"--with-curl" "
"--with-curlwrappers" "
"--with-openssl" "
"--with-mcrypt" "
"--with-mhash" "
"--enable-pcntl" "
"--enable-sockets" "
"--enable-sysvsem" "

"--enable-inline-optimization" "

"--enable-soap" "

"--enable-gd-native-ttf" "

"--enable-ftp" "

"--enable-mbstring" "

"--enable-exif" "

"--disable-debug" "

"--disable-ipv6"

#sed -i 's#-lz -lm -lxml2-lz -lm -lxml2 -lz -lm -lcrypt#& -liconv#' Makefile

makeZEND_EXTRA_LIBS='-liconv'

make install

cp php.ini-dist/usr/local/php-fcgi/etc/php.ini
复制代码
1.5 编译安装PHP扩展


tar zxvf memcache-2.2.4.tgz

cd memcache-2.2.4

/usr/local/php-fcgi/bin/phpize

./configure--with-php-config=/usr/local/php-fcgi/bin/php-config

make && make install

复制代码
tar jxvf eaccelerator-0.9.5.3.tar.bz2

cd eaccelerator-0.9.5.3

/usr/local/php-fcgi/bin/phpize

./configure --enable-eaccelerator=shared--with-php-config=/usr/local/php-fcgi/bin/php-config

make && make install

复制代码
tar zxvf PDO_MYSQL-1.0.2.tgz

cd PDO_MYSQL-1.0.2

/usr/local/php-fcgi/bin/phpize

./configure --with-php-config=/usr/local/php-fcgi/bin/php-config--with-pdo-mysql=/usr/local/mysql

make && make install
复制代码


1.6 配置php.ini
#sh init_php.sh
//执行PHP配置脚本
【注】下载包中提供了此脚本.主要是添加自动添加PHP扩展及PHP安全相关设置,用户可以编辑此文件根据具体情况做调整。
#vi /usr/local/php-fcgi/etc/php.ini //在最后加上

[eAccelerator]

extension="eaccelerator.so"

eaccelerator.shm_size="32"

eaccelerator.cache_dir="/cache_tmpfs/eaccelerator"

eaccelerator.enable="1"

eaccelerator.optimizer="1"

eaccelerator.check_mtime="1"

eaccelerator.debug="0"

eaccelerator.filter=""

eaccelerator.shm_max="0"

eaccelerator.shm_ttl="0"

eaccelerator.shm_prune_period="0"

eaccelerator.shm_only="0"

eaccelerator.compress="1"

eaccelerator.compress_level="9"
复制代码


1.7 安装ZendOptimizer-3.3.3

tar zxvf ZendOptimizer-3.3.3-linux-glibc23-x86_64.tar.gz

cd ZendOptimizer-3.3.3-linux-glibc23-x86_64

./install
复制代码

解压后进入目录./install,安提示选择相关的目录及配置文件存放目录即可.


1.8 配置php-fpm.conf
rm -rf /usr/local/php-fcgi/etc/php-fpm.conf
将本文提供的php-fpm.conf文件上传此目录.
/usr/local/php-fcgi/sbin/php-fpm start //启动服务查看是否报错,不报错继续。

1.9 配置nginx/conf

#cd /usr/local/nginx

#mv conf conf_old

#mkdir -p conf/{vhost,conf_example}
复制代码

#将本文提供的conf目录替换成当前conf目录.在下载的scripts.tar.gz包里.

目录结构介绍:
/usr/local/nginx/conf    //存放主配置文件
/usr/local/nginx/conf/vhost    //存放虚拟主机配置文件.
/usr/local/nginx/conf/conf_example   //存放一些经典的配置示例{虚拟主机,防盗链,访问控制,重定向,负载均衡等}

[[email protected]]# /usr/local/nginx/sbin/nginx –t   //验证是否有配置语法错误.
2009/01/06 09:36:12 [info] 23353#0: the configuration file/usr/local/nginx//conf/nginx.conf syntax is ok

2009/01/06 09:36:12 [info] 23353#0: the configuration file/usr/local/nginx//conf/nginx.conf was tested successfully
复制代码
#chmod a+x /etc/init.d/nginx    //将文本提供的nginx脚本上传至/etc/init.d/目录下
【注】此脚本已经含有php-fpm的管理.直接利用此脚本即可管理所有服务.
# /etc/init.d/nginx stop  //停止nginx服务

# /etc/init.d/nginx start  //启动nginx服务
复制代码


2.0 验证服务环境
配置完成虚拟主机以后,编辑php.ini把disable_functions里的phpinfo去掉,仍后重启服务,利用Phpinfo函数查看环环配置。
编写phpinfo.php
<?php

phpinfo();

?>
复制代码
http://ip/phpinfo.php
即可查看当前配置环境. 查看完成后出于安全考虑请再将此函数禁掉.

1 2  下一页

Tags:CentOS LEMP

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