您的位置:首页 > 运维架构 > Linux

Centos5.5下安装LAMP完整版

2010-07-25 15:53 337 查看
[align=center]Centos5.5下安装LAMP完整版[/align]
Centos5.5(32bit)

Author:hx10

Date: 2010/7/25 hangzhou

Blog :http://hi.baidu.com/hx10
下载软件包(截至2010/7/25软件为最新稳定版本)

http://www.libgd.org/releases/gd-2.0.35.tar.gz

ftp://xmlsoft.org/libxml2/libxml2-2.7.7.tar.gz

http://ftp.devil-linux.org/pub/devel/sources/1.2/libmcrypt-2.5.8.tar.bz2

http://cronolog.org/download/cronolog-1.6.2.tar.gz

http://labs.renren.com/apache-mirror/httpd/httpd-2.2.15.tar.gz

http://gd.tuwien.ac.at/db/mysql/Downloads/MySQL-5.1/mysql-5.1.49.tar.gz

http://cn.php.net/distributions/php-5.2.14.tar.gz

http://xcache.lighttpd.net/pub/Releases/1.3.0/xcache-1.3.0.tar.gz

http://downloads.zend.com/optimizer/3.3.9/ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz
保存为down.txt

# cd /usr/local/src

# wget -i down.txt

cd /usr/local/src

vim init.sh

#!/bin/bash

#disable ipv6

echo "alias net-pf-10 off" >> /etc/modprobe.conf

echo "alias ipv6 off" >> /etc/modprobe.conf

/sbin/chkconfig --level 35 ip6tables off

echo "ipv6 is disabled!"

#disable selinux

sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config

echo "selinux is disabled,you must reboot!"

#vim

sed -i "8 s/^/alias vi='vim'/" /root/.bashrc

echo 'syntax on' > /root/.vimrc

#zh_cn

sed -i -e 's/^LANG=.*/LANG="zh_CN.GB18030"/' /etc/sysconfig/i18n

#tunoff services

for i in `ls /etc/rc3.d/S*`

do

CURSRV=`echo $i|cut -c 15-`
echo $CURSRV

case $CURSRV in

crond | irqbalance | microcode_ctl | network | random | sendmail | sshd | syslog | local | mysqld | httpd )

echo "Base services, Skip!"

;;

*)

echo "change $CURSRV to off"

chkconfig --level 235 $CURSRV off

service $CURSRV stop

;;

esac

done
# sh init.sh

# reboot
二、编译安装基本环境

1. 安装准备

1) 系统约定

操作系统:Centos5.5 i386

IP:192.168.1.103

软件源代码包存放位置 /usr/local/src

源码包编译安装位置(prefix) /usr/local/software_name

脚本以及维护程序存放位置 /usr/local/sbin

MySQL 数据库位置 /data/mysql/data(可按情况设置)

Apache 网站根目录 /data/www/wwwroot(可按情况设置)

Apache 虚拟主机日志根目录 /data/www/logs(可按情况设置)

Apache 运行账户 www:www

useradd -d /data/www/

chown www.www /data/www/wwwroot
2) 系统环境部署及调整

检查系统是否正常

# tail -n100 /var/log/messages (检查有无系统级错误信息)

# dmesg (检查硬件设备是否有错误信息)

# ifconfig(检查网卡设置是否正确)

# ping www.baidu.com (检查网络是否正常)
3) 使用 yum 程序安装所需开发包(以下为标准的 RPM 包名称)

#rpm --import http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#

yum -y install ntp vim-enhanced gcc gcc-c++ gcc-g77 flex bison autoconf automake bzip2-devel \

ncurses-devel zlib-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel libXpm-devel \

gettext-devel pam-devel libtool libtool-ltdl openssl openssl-devel fontconfig-devel

解释如下:

安装基本的编译工具 # yum install -y gcc gcc-c++ flex bison autoconf automake libtool bzip2-devel zlib-devel ncurses-devel pam-devel

安装编译 GD 需要的库# yum install -y xorg-x11-server-Xorg fontconfig-devel libXpm-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel

安装mysql需要的库# yum install -y libxml2-devel curl-devel

4) 定时校正服务器时钟,定时与中国国家授时中心授时服务器同步

# crontab -e

加入一行:

30 * * * * /usr/sbin/ntpdate 210.72.145.44 > /dev/null 2>&1

service crond restart

2. 编译安装软件包
1)GD2

cd /usr/local/src

tar -zxvf gd-2.0.35.tar.gz

cd gd-2.0.35

./configure --prefix=/usr/local/libxml2

make && make install
2) LibXML2

tar -zxvf libxml2-2.7.7.tar.gz

cd libxml2-2.7.7

./configure --prefix=/usr/local/libxml2

make && make install
3) LibMcrypt

tar xvf libmcrypt-2.5.8.tar.bz2

cd libmcrypt-2.5.8

./configure --prefix=/usr/local/libmcrypt

make && make install
4) Apache日志截断程序

tar zxvf cronolog-1.6.2.tar.gz

cd cronolog-1.6.2

./configure --prefix=/usr/local/cronolog

make && make install
这几步可以放到脚本里面安装

vim install_1.sh

cd /usr/local/src

tar -zxvf gd-2.0.35.tar.gz

cd gd-2.0.35

./configure --prefix=/usr/local/gd2

make && make install

cd ..

tar -zxvf libxml2-2.7.7.tar.gz

cd libxml2-2.7.7

./configure --prefix=/usr/local/libxml2

make && make install

cd ..

tar xvf libmcrypt-2.5.8.tar.bz2

cd libmcrypt-2.5.8

./configure --prefix=/usr/local/libmcrypt

make && make install

cd ..

tar zxvf cronolog-1.6.2.tar.gz

cd cronolog-1.6.2

./configure --prefix=/usr/local/cronolog

make && make install

cd..

exit

# sh install_1.sh
5) 安装mysql

查看分析你的CPU型号

http://en.gentoo-wiki.com/wiki/Safe_Cflags

查找您的GCC编译参数

确定系统CPU类型

# cat /proc/cpuinfo | grep "model name"

model name : Intel(R) Core(TM)2 Duo CPU T6570 @ 2.10GHz

执行后会看到系统中CPU的具体型号,记下CPU型号。

查到CPU的参数为

64 bit profile (amd64) for < GCC 4.3

CHOST="x86_64-pc-linux-gnu"

CFLAGS="-march=nocona -O2 -pipe"

CXXFLAGS="${CFLAGS}"

tar -zxvf mysql-5.1.49.tar.gz
cd mysql-5.1.49

修改mysql的最大连接数,默认是100

vim sql/mysqld.cc

搜索max_connections,找到REQUIRED_ARG后面的100,改成1500,当然小点也可以,根据你的需要来,不建议改的太大,然后保存

vim install_mysql.sh

CHOST="x86_64-pc-linux-gnu"

CFLAGS="-march=nocona -O2 -pipe"

CXXFLAGS="${CFLAGS}"

./configure \

"--prefix=/usr/local/mysql" \

"--localstatedir=/data/mysql/data" \

"--with-comment=Source" \

"--with-server-suffix=-hx10" \

"--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" \

"--without-isam" \

"--without-innodb" \

"--without-ndb-debug"

make && make install

mkdir -p /data/mysql/data

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 .

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

然后执行脚本 sh install_mysql.sh
# mysql -u root -p

mysql> select version();

+----------------------+

| version() |

+----------------------+

| 5.1.49-hx10-log |

+----------------------+

1 row in set (0.00 sec)
mysql>
6)安装apache

groupadd httpd

useradd -g httpd -s /sbin/nologin -M httpd
tar -zxvf httpd-2.2.15.tar.gz

cd httpd-2.2.15

vim install_httpd.sh

./configure \

"--prefix=/usr/local/apache2" \

"--with-included-apr" \

"--enable-so" \

"--enable-deflate=shared" \

"--enable-expires=shared" \

"--enable-rewrite=shared" \

"--enable-static-support" \

"--disable-userdir"

make

make install

cd ..

exit

# sh install_httpd.sh
7)安装php

tar -zxvf php-5.2.14.tar.gz

cd php-5.2.14

vim install_php.sh

mkdir -p /usr/local/php/etc

./configure \

"--prefix=/usr/local/php" \

"--with-apxs2=/usr/local/apache2/bin/apxs" \

"--with-config-file-path=/usr/local/php/etc" \

"--with-mysql=/usr/local/mysql" \

"--with-libxml-dir=/usr/local/libxml2" \

"--with-gd=/usr/local/gd2" \

"--with-jpeg-dir" \

"--with-png-dir" \

"--with-bz2" \

"--with-freetype-dir" \

"--with-iconv-dir" \

"--with-zlib-dir " \

"--with-openssll" \

"--with-mcrypt=/usr/local/libmcrypt" \

"--enable-soap" \

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

"--enable-ftp" \

"--enable-mbstring" \

"--enable-exif" \

"--disable-ipv6" \

"--disable-cgi" \

"--disable-cli"

make

make install

cp php.ini-dist /usr/local/php/etc/php.ini

#sh install_php.sh

7)安装Xcache

tar -zxvf xcache-1.3.0.tar.gz

cd xcache-1.3.0

/usr/local/php/bin/phpize \

./configure --enable-xcache \

--enable-xcache-coverager \

--with-php-config=/usr/local/php/bin/php-config \

--enable-inline-optimization --disable-debug

vim /usr/local/php/etc/php.ini

在最后添加以下内容

[xcache-common]

zend_extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/xcache.so

[xcache.admin]

xcache.admin.user = "admin"

;create md5 password: echo -n "password"| md5sum

xcache.admin.pass = "f3dfd37a03b1356d6380b41e524f903b" #password is hx10.com

[xcache]

; Change xcache.size to tune the size of the opcode cache

xcache.size = 24M

xcache.shm_scheme = "mmap"

xcache.count = 4

xcache.slots = 8K

xcache.ttl = 0

xcache.gc_interval = 0

; Change xcache.var_size to adjust the size of variable cache

xcache.var_size = 8M

xcache.var_count = 1

xcache.var_slots = 8K

xcache.var_ttl = 0

xcache.var_maxttl = 0

xcache.var_gc_interval = 300

xcache.test = Off

xcache.readonly_protection = On

xcache.mmap_path = "/tmp/xcache"

xcache.coredump_directory = ""

xcache.cacher = On

xcache.stat = On

xcache.optimizer = Off
[xcache.coverager]

xcache.coverager = On

xcache.coveragedump_directory = ""

8)安装Zend Optimizer

tar -zxvf tar -zxvf ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz

mv ZendOptimizer-3.3.9-linux-glibc23-i386 /usr/local/Zend

cp /usr/local/Zend/data/5_2_x_comp/ZendOptimizer.so /usr/local/Zend/ (因为php是5.2)

vim /usr/local/php/etc/php.ini 最后一行加入以下内容

zend_optimizer.optimization_level=15

zend_extension=/usr/local/Zend/ZendOptimizer.so

9)整合Apache与PHP及系统初化配置

vim /usr/local/apache2/conf/httpd.conf

查找AddType application/x-gzip .gz .tgz,在该行下面添加

AddType application/x-httpd-php .php

查找DirectoryIndex index.html 把该行修改成

DirectoryIndex index.html index.htm index.php

找到

#Include conf/extra/httpd-mpm.conf

#Include conf/extra/httpd-info.conf

#Include conf/extra/httpd-vhosts.conf
#Include conf/extra/httpd-default.conf

去掉这4行前面的#

注意:以上 4 个扩展配置文件中的设置请按照相关原则进行合理配置!
vim /usr/local/apache2/conf/extra/httpd-vhosts.conf

<VirtualHost *:80>

ServerAdmin webmaster@hx10.com

DocumentRoot "/www/wwwroot/"

ServerName mail.520.com

ServerAlias www.dummy-host.example.com

ErrorLog "logs/dummy-host.example.com-error_log"

CustomLog "logs/dummy-host.example.com-access_log" common

</VirtualHost>

新建一个虚拟主机

mkdir -p /www/wwwroot/

然后把探针放到这个目录
vim /usr/local/apache2/conf/httpd.conf

找到

<Directory />

Options FollowSymLinks

AllowOverride None

Order deny,allow

Deny from all //把这里的Deny改成Allow

</Directory>

找到

#ServerName www.example.com:80 在这一行后面加入下面一行

ServerName 127.0.0.1:80
找到

User httpd

Group httpd

把原来的daemon修改成httpd
Apache 运行账户 httpd:httpd

chown -R httpd:httpd /www/wwwroot

重启apache

# /usr/local/apache2/bin/apachectl restart

输入探针的地址访问

http://ip/php.php



10)安全和性能优化

vim /usr/local/php/etc/php.ini

查找disable_functions =

等号后面加入以下参数,注意不能换行

phpinfo,passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,
ini_alter,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,get_cfg_var

查找以下2项,把on改成off

expose_php = Off

display_errors = Off

vim /usr/local/apache2/conf/extra/httpd-default.conf 修改后的内容如下

Timeout 15

KeepAlive Off

MaxKeepAliveRequests 50

KeepAliveTimeout 5

UseCanonicalName Off

AccessFileName .htaccess

ServerTokens Prod

ServerSignature off

HostnameLookups Off

vim /usr/local/apache2/conf/extra/httpd-mpm.conf 修改一个模块后的内容如下

原来的配置如下:

<IfModule mpm_prefork_module>

ServerLimit 256

StartServers 5

MinSpareServers 5

MaxSpareServers 10

MaxClients 256

MaxRequestsPerChild 0

</IfModule>

修改后配置如下

<IfModule mpm_prefork_module>

ServerLimit 2000

StartServers 10

MinSpareServers 10

MaxSpareServers 15

MaxClients 2000

MaxRequestsPerChild 10000

</IfModule>

查看是什么模式

/usr/local/apache2/bin/apachectl -l

如果出现prefork.c那就说明是prefork模式

关于详细的参数调整,查看http://zhengdl126.javaeye.com/blog/450620
11)将apache,mysql安装为系统服务

# cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd

#cd /etc/rc.d/init.d

#vi /etc/rc.d/init.d/httpd

添加以下两行内容(在#!/bin/sh下面)

# chkconfig: 2345 10 90

# description: Activates/Deactivates Apache Web Server

最后,运行chkconfig 把Apache 添加到系统的启动服务组里面:

# chkconfig --add httpd

# chkconfig httpd on
mysql前面已经加入到服务启动,不需要此步骤

cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld

cd /etc/rc.d/init.d

chkconfig --add mysqld //ntsysv检查Mysql是否已经加载到服务启动

service mysqld start/stop

/usr/local/mysql/bin/mysqladmin -uroot -p shutdown //关闭mysql

补充知识点:

修改php.ini

date.timezone =添加PRC 去掉前面的;

--disable-MODULE

禁用MODULE模块(仅用于基本模块)

--enable-MODULE

启用MODULE模块(仅用于基本模块)

--prefix=/usr/local/php

指定 php 安装目录

--with-apxs2=/usr/local/apache/bin/apxs

整合 apache,apxs功能是使用mod_so中的LoadModule指令,加载指定模块到 apache,要求 apache 要打开SO模块

--with-config-file-path=/usr/local/php/etc

指定php.ini位置

--with-MySQL=mysqlnd

mysql安装目录,对mysql的支持

--with-mysqli=mysqlnd

mysqli扩展技术不仅可以调用MySQL的存储过程、处理MySQL事务,而且还可以使访问数据库工作变得更加稳定。

--enable-safe-mode 打开安全模式

--enable-ftp 打开ftp的支持

--enable-zip 打开对zip的支持

--with-bz2 打开对bz2文件的支持

--with-jpeg-dir 打开对jpeg图片的支持

--with-png-dir 打开对png图片的支持

--with-freetype-dir 打开对freetype字体库的支持

--without-iconv 关闭iconv函数,种字符集间的转换

--with-libXML-dir 打开libxml2库的支持

--with-XMLrpc 打开xml-rpc的c语言

--with-zlib-dir 打开zlib库的支持

--with-gd 打开gd库的支持

--enable-gd-native-ttf 支持TrueType字符串函数库

--with-curl 打开curl浏览工具的支持

--with-curlwrappers 运用curl工具打开url流

--with-ttf 打开freetype1.*的支持,可以不加了

--with-xsl 打开XSLT 文件支持,扩展了libXML2库 ,需要libxslt软件

--with-gettext 打开gnu 的gettext 支持,编码库用到

--with-pear 打开pear命令的支持,PHP扩展用的

--enable-calendar 打开日历扩展功能

--enable-mbstring 多字节,字符串的支持

--enable-bcmath 打开图片大小调整,用到zabbix监控的时候用到了这个模块

--enable-sockets 打开 sockets 支持

--enable-exif 图片的元数据支持

--enable-magic-quotes 魔术引用的支持

--disable-rpath 关闭额外的运行库文件

--disable-debug 关闭调试模式

--with-mime-magic=/usr/share/file/magic.mime 魔术头文件位置

CGI方式安装才用的参数

--enable-fpm

打上PHP-fpm 补丁后才有这个参数,CGI方式安装的启动程序

--enable-fastCGI

支持fastcgi方式启动PHP

--enable-force-CGI-redirect

重定向方式启动PHP

--with-ncurses

支持ncurses 屏幕绘制以及基于文本终端的图形互动功能的动态库

--enable-pcntl freeTDS需要用到的,可能是链接mssql 才用到

mhash和mcrypt算法的扩展

--with-mcrypt 算法

--with-mhash 算法

以上函数库需要安装

--with-gmp 应该是支持一种规范

--enable-inline-optimization 优化线程

--with-openssl openssl的支持,加密传输时用到的

--enable-dbase 建立DBA 作为共享模块

--with-pcre-dir=/usr/local/bin/pcre-config perl的正则库案安装位置

--disable-dmalloc

--with-gdbm dba的gdbm支持

--enable-sigchild

--enable-sysvsem

--enable-sysvshm

--enable-zend-multibyte 支持zend的多字节

--enable-mbregex

--enable-wddx

--enable-shmop

--enable-soap

指定了--with-apxs2=/usr/local/apache/bin/apxs以后,就不要再激活--enable-fpm和--enable-fastCGI,apxs是以php module的模式加载PHP的。

Mysql在编译了Mysql开发library以后,可以不用指定mysql的路径。

PHP编译存在基础的依赖的关系,编译PHP首先需要安装XML扩展,因为php5核心默认打开了XML的支持,其他的基础库,相应需要:

GD -> zlib, Png, Jpg, 如果需要支持其他,仍需要根据实际情况编译扩展库,ttf库需要freetype库的支持。

--enable-magic-quotes,是一个极其不推荐的参数,当然,如果你需要PHP为你做这些底下的工作,实际上他也没有很彻底的解决问题。

--with-openssl,需要openssl库。

本文出自 “无云安全技术站” 博客,请务必保留此出处http://hx100.blog.51cto.com/44326/359296
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: