CentOS5.2出来已经有一段时间了,我装了几次,发现和5.1还是有不少的区别。至少你会发现如果你采用文本安装,最小化安装,才安装150个包,比以前少了一半都不止。
很多以前类似图形化命令,setup, ntsysv 等配置工具都没有安装。这其实比较符合linux的特点。按需来安装软件。
现在采用yum的方式来安装软件,也比较方便。缺少什么就用yum来安装。
linux下安装软件,有编译安装和rpm包安装,对性能有影响的是那些大软件,例如apache,php,mysql这些。一般的小的都采用yum的方式进行安装。
不过有些软件,如果采用yum的方式安装,编译php的时候,就会无法找到或者报错,所以这些软件,还是需要采用编译的方式进行安装。
下面的安装过程,是我在vm里进行配置的全部过程,整个过程,我已经反复的多次。如果照着配置,肯定是不会有任何的问题。
整个文档是参考linuxtone.rog 版主的文档,这个文档的一个好处,就是把大量手工操作的地方,采用脚本,这样可以减少出错的机会。
我去掉文档里xcache的配置,别的基本都是一样,把它脚本分布运行,这样比较适合初学者。还有就是原文出于安全考虑,禁止了phpinfo这个函数,搞得我还以为自己配置出了问题,我下面的文档没有禁止这个函数。原文有几个地方错误。(http://bbs.linuxtone.org/thread-122-1-1.html)
下面的配置过程,可能有不完善的地方,不过我已经重复了2遍,把错误的地方都改了,相信不会有错误。我自己学linux的时候,最希望就有一个针对初学者的配置文档,我对着做,就可以成功,为什么这样做,可以慢慢理解。
下面这个文档,也算是我自己的一个总结吧。这个是我用goolge的doc来总结的。发现google的doc比较适合编辑这些代码,比word强很多啊。
一:系统约定
采用Centos5.2光盘,
软件源代码包存放位置 /usr/local/src
源码包编译安装位置(prefix) /usr/local/software_name
MySQL 数据库位置 /data/mysql/data
Apache 网站根目录 /data/www/wwwroot(虚拟主机在这个目录下)
Apache 虚拟主机日志根目录 /data/www/logs
Apache 运行账户 www:www
创建一个虚拟主机 linuxtone.org
二:系统基本设置
diabe IPV6
cp /etc/modprobe.conf /etc/modprobe.conf.save
echo "alias net-pf-10 off" >> /etc/modprobe.conf
echo "alias ipv6 off" >> /etc/modprobe.conf
SSH
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.save
sed -i '/#PermitRootLogin/s/#PermitRootLogin/PermitRootLogin/' /etc/ssh/sshd_config
sed -i -e '74 s/^/#/' -i -e '76 s/^/#/' /etc/ssh/sshd_config
sed -i "s/#UseDNS yes/UseDNS no/" /etc/ssh/sshd_config
sed -i -e '44 s/^/#/' -i -e '48 s/^/#/' /etc/ssh/sshd_config
/etc/init.d/sshd restart
stop the “beep"
cp /etc/inputrc /etc/inputrc.save
sed -i '/#set bell-style none/s/#set bell-style none/set bell-style none/' /etc/inputrc
SElinux
cp /etc/sysconfig/selinux /etc/sysconfig/selinux.save
sed -i '/SELINUX=enforcing/s/SELINUX=enforcing/SELINUX=disabled/' /etc/sysconfig/selinux
停止没有必要的服务
chkconfig --list |grep 3:on |awk '{print $1}' |egrep -v 'sshd|network|syslog' |xargs -i{} chkconfig --level 3 {} off
chkconfig --list | grep 3:on | cut -f1
重新启动
init 6
加载光驱
mkdir /mnt/cdrom
mount /dev/cdrom /mnt/cdrom
设置yum使用本地光盘
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.save
mv /etc/yum.repos.d/CentOS-Media.repo /etc/yum.repos.d/CentOS-Media.repo.save
vi /etc/yum.repos.d/dvdiso.repo
###############
[DVDISO]
name=DVD ISO
baseurl=file:///mnt/cdrom/
enabled=1
gpgcheck=0
################
yum list
yum list installed
yum list installed | wc -l
三:安装必须的软件
采用yum的方式安装
yum -y install gcc wget make ntp patch
ntpdate 210.72.145.44 && clock -w
yum -y install vim-enhanced gcc gcc-c++ gcc-g77 flex bison autoconf automake bzip2-devel \
ncurses-devel libtool* zlib-devel libxml2-devel libjpeg-devel libpng-devel libtiff-devel \
fontconfig-devel freetype-devel libXpm-devel gettext-devel curl curl-devel pam-devel kernel pcre-devel
如何寻找下载的软件,
在google
httpd-2.2.8.tar.gz intitle:index
四:下载软件
如何寻找下载的软件,
在google
httpd-2.2.8.tar.gz intitle:index
cd /usr/local/src
vi list
http://download.filehat.com/apache/httpd/httpd-2.2.8.tar.gz
http://opensource.nchc.org.tw/COSA/CNS4/cronolog-1.6.2.tar.gz
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://jaist.dl.sourceforge.net/sourceforge/mcrypt/mcrypt-2.6.7.tar.gz
http://www.openssl.org/source/openssl-0.9.8h.tar.gz
http://openbsd.md5.com.ar/pub/OpenBSD/OpenSSH/portable/openssh-5.0p1.tar.gz
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.7.tar.gz
http://sysoev.ru/nginx/nginx-0.6.31.tar.gz
http://mysql.byungsoo.net/Downloads/MySQL-5.0/mysql-5.0.51b.tar.gz
http://cn2.php.net/get/php-5.2.6.tar.bz2/from/this/mirror
http://php-fpm.anight.org/downloads/head/php-5.2.6-fpm-0.5.8.diff.gz
http://pecl.php.net/get/memcache-2.2.3.tgz
http://xcache.lighttpd.net/pub/Releases/1.2.2/xcache-1.2.2.tar.gz
http://downloads.phpchina.com/zend/optimizer/3.3.3/ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz
ftp://ftp.cac.washington.edu/mail/imap.tar.Z
http://ftp.isc.org/isc/bind9/9.4.2/bind-9.4.2.tar.gz
http://puzzle.dl.sourceforge.net/sourceforge/phpmyadmin/phpMyAdmin-2.11.8.1-all-languages-utf-8-only.tar.gz
wget -i list
五:编译安装软件
openssl
tar zxvf openssl-0.9.8h.tar.gz
cd openssl-0.9.8h
./config --prefix=/usr/local/openssl
make
make test
make install
cd ..
openssh
tar xvf openssh-5.0p1.tar.gz
cd openssh-5.0p1
./configure \
"--prefix=/usr" \
"--with-pam" \
"--with-zlib" \
"--sysconfdir=/etc/ssh" \
"--with-ssl-dir=/usr/local/openssl" \
"--with-md5-passwords"
make
ake install
cd ..
service sshd restart
ssh -v
GD
tar jxvf gd-2.0.35.tar.bz2
cd gd-2.0.35
aclocal
./configure --prefix=/usr/local/gd2
make && make install
cd ..
libmcrypt
tar jxvf libmcrypt-2.5.8.tar.bz2
cd libmcrypt-2.5.8
./configure --prefix=/usr/local/libmcrypt && make && make install
cd ..
libiconv
tar zxvf libiconv-1.12.tar.gz
cd libiconv-1.12
./configure --prefix=/usr && make && make install
cd ..
cronolog
tar xvf cronolog-1.6.2.tar.gz
cd cronolog-1.6.2
./configure --prefix=/usr/local/cronolog
make && make install
cd ..
imap
tar zxf imap.tar.Z
cd imap-2007b
make lr5 PASSWDTYPE=std SSLTYPE=unix.nopwd IP6=4
echo "set disable-plaintext nil" > /etc/c-client.cf
mkdir /usr/local/imap-2007b
mkdir /usr/local/imap-2007b/include/
mkdir /usr/local/imap-2007b/lib/
chmod -R 077 /usr/local/imap-2007b
rm -rf /usr/local/imap-2007b/include/*
rm -rf /usr/local/imap-2007b/lib/*
rm -rf /usr/sbin/imapd
cp imapd/imapd /usr/sbin/
cp c-client/*.h /usr/local/imap-2007b/include/
cp c-client/*.c /usr/local/imap-2007b/lib/
cp c-client/c-client.a /usr/local/imap-2007b/lib/libc-client.a
cd ..
MYSQL
tar zxvf mysql-5.0.51b.tar.gz
cd mysql-5.0.51b
vi in_mysql.sh
####
CFLAGS="-O3" CXX=gcc CXXFLAGS="-O3 -felide-constructors \
-fno-exceptions -fno-rtti -fomit-frame-pointer -ffixed-ebp"
./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" \
"--without-isam" \
"--without-innodb" \
"--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 .
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 in_mysql.sh
cd..
mysqladmin -u root password chenshake
Apache
tar zxvf httpd-2.2.8.tar.gz
cd httpd-2.2.8
./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
vi /etc/init.d/httpd
####################
#!/bin/bash
#
# Startup script for the Apache Web Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server. It is used to serve \
# HTML files and CGI.
# processname: httpd
# pidfile: /usr/local/apache2/logs/httpd.pid
# config: /usr/local/apache2/conf/httpd.conf
# Source function library.
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/httpd ]; then
. /etc/sysconfig/httpd
fi
# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""
# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache2/bin/apachectl
httpd=/usr/local/apache2/bin/httpd
pid=/usr/local/apache2/logs/httpd.pid
prog=httpd
RETVAL=0
# The semantics of these two functions differ from the way apachectl does
# things -- attempting to start while running is a failure, and shutdown
# when not running is also a failure. So we just do it the way init scripts
# are expected to behave here.
start() {
echo -n $"Starting $prog: "
daemon $httpd $OPTIONS
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/httpd
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc $httpd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/httpd $pid
}
reload() {
echo -n $"Reloading $prog: "
killproc $httpd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status $httpd
RETVAL=$?
;;
restart)
stop
start
;;
condrestart)
if [ -f $pid ] ; then
stop
start
fi
;;
reload)
reload
;;
graceful|help|configtest|fullstatus)
$apachectl $@
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|reload|status"
echo $"|fullstatus|graceful|help|configtest}"
exit 1
esac
exit $RETVAL
######################################
chmod +x /etc/rc.d/init.d/httpd
chkconfig --add httpd
cd ..
PHP
tar jxvf php-5.2.6.tar.bz2
cd php-5.2.6
./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-curl-dir " \
"--with-openssl=/usr/local/openssl" \
"--with-mcrypt=/usr/local/libmcrypt" \
"--with-imap-ssl" \
"--with-imap=/usr/local/imap-2007b" \
"--enable-soap" \
"--enable-gd-native-ttf" \
"--enable-ftp" \
"--enable-mbstring" \
"--enable-exif" \
"--disable-ipv6" \
"--disable-cgi" \
"--disable-cli"
make
make install
mkdir /usr/local/php/etc
cp php.ini-dist /usr/local/php/etc/php.ini
cd ..
安装Zend Optimizer (安装Zend Optimizer过程的最后不要选择重启Apache。)
tar xzvf ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz
cd ZendOptimizer-3.3.3-linux-glibc23-i386
./install.sh
cd ..
六:配置apache,php
groupadd www -g 48
useradd -u 48 -g www www
mkdir -p /data/www/wwwroot/linuxtone.org
mkdir -p /data/logs
chmod +w /data/www/wwwroot
chown -R www:www /data/www/wwwroot
cp /usr/local/apache2/conf/httpd.conf /usr/local/apache2/conf/httpd.conf.save
编辑httpd.conf
sed -i -e '121 s/^/#/' -i -e '122 s/^/#/' /usr/local/apache2/conf/httpd.conf
sed -i -e "s/User daemon/User www/" -i -e "s/Group daemon/Group www/" /usr/local/apache2/conf/httpd.conf
sed -i 's/DirectoryIndex index.html/ DirectoryIndex index.php index.html index.htm/g' /usr/local/apache2/conf/httpd.conf
sed -i -e '374 s/^#//g' -i -e '389 s/^#//g' -i -e '392 s/^#//g' -i -e '401 s/^#//g' /usr/local/apache2/conf/httpd.conf
sed -i 's/#ServerName www.example.com:80/ ServerName www.example.com:80/g' /usr/local/apache2/conf/httpd.conf
vi /usr/local/apache2/conf/httpd.conf
搜索
LoadModule php5_module modules/libphp5.so
在这一行下,添加下面两行
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
编辑php.ini
cp /usr/local/php/etc/php.ini /usr/local/php/etc/php.ini.save
sed -i '205 s#;open_basedir =#open_basedir = /data/www/wwwroot:/tmp#g' /usr/local/php/etc/php.ini
sed -i '/expose_php/s/On/Off/' /usr/local/php/etc/php.ini
sed -i '/display_errors/s/On/Off/' /usr/local/php/etc/php.ini
配置虚拟主机
mv /usr/local/apache2/conf/extra/httpd-vhosts.conf /usr/local/apache2/conf/extra/httpd-vhosts.conf.save
mv /usr/local/apache2/conf/extra/httpd-default.conf /usr/local/apache2/conf/extra/httpd-default.conf.save
mv /usr/local/apache2/conf/extra/httpd-mpm.conf /usr/local/apache2/conf/extra/httpd-mpm.conf.save
vi /usr/local/apache2/conf/extra/httpd-vhosts.conf
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin cnseek@gmail.com
DocumentRoot "/data/www/wwwroot/linuxtone.org"
ServerName www.linuxtone.org
ServerAlias bbs.linxutone.org
ErrorLog "logs/linuxtone.org-error_log"
CustomLog "|/usr/local/cronolog/sbin/cronolog /data/logs/access_www.linuxtone.org.%Y%m%d" combined
</VirtualHost>
vi /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
vi /usr/local/apache2/conf/extra/httpd-mpm.conf
<IfModule mpm_prefork_module>
ServerLimit 2000
StartServers 10
MinSpareServers 10
MaxSpareServers 15
MaxClients 2000
MaxRequestsPerChild 10000
</IfModule>
七:测试php
cd /data/www/wwwroot/linuxtone.org
vi index.php
<?
phpinfo()
?>
修改本地hosts文件
192.168.1.200 www.linuxtone.org
启动Apache
service httpd start
service httpd restart
/usr/local/apache2/bin/apachectl start
这个时候,就能看到php的信息
安装phpmyadmin
cd /usr/local/src
tar zxvf phpMyAdmin-2.11.8.1-all-languages-utf-8-only.tar.gz
cp -rf phpMyAdmin-2.11.8.1-all-languages-utf-8-only /data/www/wwwroot/linuxtone.org/phpmyadmin
cd /data/www/wwwroot/linuxtone.org/phpmyadmin
cp config.sample.inc.php config.inc.php
vi config.inc.php
$cfg['blowfish_secret'] = ''
改为
$cfg['blowfish_secret'] = 'dd'
访问虚拟主机
这个时候,你会发现你可用域名访问,也可以用ip来访问。如果你有多个虚拟主机,那么就是第一个主机。
日志的位置
虚拟主机的web访问日志,/data/logs/ 下,可以看到每个虚拟主机访问log
错误日志的位置 /usr/local/apache2/logs
大家可以看httpd-vhosts.conf 的设置就明白了。(http://9ng.cn/1/viewspace-27212)