`
猫太的鱼
  • 浏览: 233018 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

CentOS 服务器安装

阅读更多
先声明,我绝对是个Linux的菜鸟,以下的这些文字个人的安装笔记,是参考了网上许多高手的成功经验组合而成的,说实话我自己的东西不多 :)我想把这些经验写下来,既可以对其他跟我一样摸索的兄弟一个经验,也可以防止以后自己都忘记了,嘿嘿。

所以如果某个大虾看到我借用了你的资源,请你不要生气。也欢迎大家进行指点。

1、下载centos 4.4
我是下载的DVD版本,大家也可以下载服务器CD安装版本,其实都差不多。大家可以到这儿下载,速度很快的。
http://ftp.iasi.roedu.net/...

下载后当然就刻录成光盘。我建议你刻录DVD啦,如果是菜鸟,也可以在图形界面进行学习,不会这么抓不住头脑。

2、安装CentOS4.4
作为服务器,不安装不需要的组件,所以在选择组件的时候,除了选择FTP SERVER外取消所有组件的选择。也不要选web服务器。因为我们后面要手动编译安装。


系统约定RPM包和源码包存放位置

RPM包和源码包存放位置 /usr/local/src
源码包编译安装位置(prefix) /usr/local/xxx
脚本以及维护程序存放位置 /usr/local/sbin
MySQL 数据库位置 /var/lib/mysql
Apache 网站根目录 /home/www
Apache 虚拟主机日志根目录 /data/logs/www
yum RPM包信息文件 /etc/yum.list



3、系统环境部署及调整

(1). 检查系统是否正常
# more /var/log/messages //检查有无系统内核级错误信息
# demesg //检查硬件设备是否有错误信息
# ifconfig //检查网卡设置是否正确
# ping www.163.com // 检查网络是否正常

(2). 关闭不需要的服务
# export LANG='en_US' //设置语言
# setup //选择启动的服务
进入system service 选项。
以space 键选定所需服务。
以下仅列出需要启动的服务,未列出的服务一律关闭:
crond
irqbalance 仅当服务器CPU为S.M.P架构或支持双核心、HT技术时,才需开启,否则关闭。
microcode_ctl
network
vsftpd
sshd
syslog

(3)、修改/etc/yum.repos.d/CentOS-Base.repo,将镜象站点地址改为在中国的镜象站点地址。不然我们通过yum安装软件速度会极慢。修改如下:

# CentOS-Base.repo
#
# This file uses a new mirrorlist system developed by Lance Davis for CentOS.
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base
baseurl=http://mirror.vmmatrix.net/CentOS/$releasever/os/$basearch/
http://mirror.be10.com/cen...
http://centos.hostlink.com...
http://ftp.hostrino.com/pu...
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos4

#released updates
[update]
name=CentOS-$releasever - Updates
baseurl=http://mirror.vmmatrix.net/CentOS/$releasever/os/$basearch/
http://mirror.be10.com/cen...
http://centos.hostlink.com...
http://ftp.hostrino.com/pu...
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos4

#packages used/produced in the build but not released
[addons]
name=CentOS-$releasever - Addons
baseurl=http://mirror.vmmatrix.net/CentOS/$releasever/os/$basearch/
http://mirror.be10.com/cen...
http://centos.hostlink.com...
http://ftp.hostrino.com/pu...
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos4

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=http://mirror.vmmatrix.net/CentOS/$releasever/os/$basearch/
http://mirror.be10.com/cen...
http://centos.hostlink.com...
http://ftp.hostrino.com/pu...
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos4

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos4

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
baseurl=http://mirror.centos.org/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos4

保存。
然后导入key升级相应yum数据

# rpm --import /usr/share/doc/centos-release-4/RPM-GPG-KEY-centos4
# yum list | tee /etc/yum.list //读取yum list 数据,将其输出到 /etc/yum.list。


(4)、定时校正服务器时间
# yum install ntp
# crontab -e
0 23 * * * root /usr/sbin/ntpdate 210.72.145.44 > /dev/null 2>&1

以上命令设置好后存盘。您的机器将在每天的23:00根据中国国家授时中心的NTP服务器时间自动校准时间。

(5). 对TCP/IP网络参数进行调整,加强抗SYN Flood能力
# echo 'net.ipv4.tcp_syncookies = 1' >> /etc/sysctl.conf //将net.ipv4.tcp_syncookies = 1写入sysctl.conf 文件
# sysctl -p //查看

(6)、FTP服务器的配置
vi /etc/vsftpd/vsftpd.conf
把anonymous_enable=YES注释掉不允许匿名登录。
把chroot_list_enable=YES
chroot_list_file=/etc/vsftpd.chroot_list
前的注释去掉。
把ftpd_banner=*前的注释去掉。后面改成你的欢迎信息(这样设置可以避免显示ftp服务器的版本信息)
然后保存,service vsftpd start就可以了。

这时应当添加用户,因为root默认不能通过FTP方式登录。

# adduser username
# passwd userpassword

这样对于我们上传一些文件到系统中很方便。


4. 重新启动系统
# init 6


5. 使用 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

#这里我们将编译GD所必须的一些小软件比如 libpng,libtiff,freetype,libjpeg等先用RPM的方式一并安装好,避免手动编译浪费时间,同时也能避免很多错误,这几个小软件的编译很麻烦。这几个小软件编译错误了,GD当然安装不了,php5的编译当然也没戏了。所以我们抓大放小,对这些小牛鬼蛇神采取快速简洁的方式进行安装。并且对服务器的性能也不能产生什么影响。

6. 源码编译安装所需包 (Source)
(1) GD2
# cd /usr/local/src
# wget http://www.boutell.com/gd/...
# tar xzvf gd-2.0.33.tar.gz
# cd gd-2.0.33
# ./configure --prefix=/usr/local/gd2 --mandir=/usr/share/man //./configure 配置。
# make //make 是用来编译的,它从 Makefile 中读取指令,然后编译。
# make install //make install 是用来安装的,它也从 Makefile 中读取指令,安装到指定的位置。

(2) Apache 日志截断程序
# cd /usr/local/src
# wget http://cronolog.org/downlo...
# tar xzvf cronolog-1.6.2.tar.gz
# cd cronolog-1.6.2
# ./configure --prefix=/usr/local/cronolog
# make
# make install

(3) libxml 库程序
# cd /usr/local/src
# wget http://ftp.gnome.org/pub/g...
# tar zjvf libxml2-2.6.26.tar.gz
# cd libxml2-2.6.26
# ./configure --prefix=/usr/local/libxml2
# make
# make install

7、编译mysql 5.0.27
cd /usr/local/src
# wget http://mysql.oss.eznetsols...
# tar xzvf mysql-5.0.27.tar.gz
# cd mysql-5.0.27
# CHOST="i686-pc-linux-gnu" CFLAGS="-O3 -msse2 -mmmx -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" CXXFLAGS="-O3 -msse2 -mmmx -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" ./configure --prefix=/usr/local/mysql --localstatedir=/var/lib/mysql --with-comment=Source --with-server-suffix=-Community --with-mysqld-user=mysql --without-debug --with-big-tables --with-charset=latin1 --with-collation=latin1_swedish_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-innodb --without-ndb-debug


配置成功会提示:

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

编译安装完成后执行后续操作:
# 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-huge.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
# /etc/rc.d/init.d/mysqld start //启动 MySQL
# bin/mysqladmin -u root password "password_for_root"
# service mysqld stop //关闭 MySQL

8. 编译安装 Apache
# cd /usr/local/src
# wget http://www.ip97.com/apache...
# tar zxvf httpd-2.2.3.tar.gz
# cd httpd-2.2.3
# CHOST="i686-pc-linux-gnu" CFLAGS="-O3 -msse2 -mmmx -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" ./configure --prefix=/usr/local/apache2 --enable-module=so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --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 --disable-userdir --with-mpm=worker --enable-authn-dbm=shared --enable-authn-anon=shared --enable-authn-dbd=shared --enable-auth-basic=shared

# make
# make install
# echo '/usr/local/apache2/bin/apachectl start ' >> /etc/rc.local //将 apachectl 的调用加入到你的系统启动文件中。


注解:
./configure //配置源代码树
--prefix=/usr/local/apache2 //体系无关文件的顶级安装目录PREFIX ,也就Apache的安装目录。
--enable-module=so //打开 so 模块,so 模块是用来提 DSO 支持的 apache 核心模块
--enable-deflate=shared //支持网页压缩
--enable-expires=shared //支持 HTTP 控制
--enable-rewrite=shared //支持 URL 重写
--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
--disable-userdir //禁止用户从自己的主目录中提供页面
--with-mpm=worker // 让apache以worker方式运行
--enable-authn-dbm=shared // 对动态数据库进行操作。Rewrite时需要。

将apache设置成开机自启动:

在/etc/rc.d/rc.local文件中加入一行
/usr/local/apache/bin/apachectl start
这样每次重新启动系统以后,apache也会随系统一起启动.
或者
# cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd
然后 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


9、编译php 5.2.0

# cd /usr/local/src
# wget http://cn.php.net/get/php-...
# tar zxvf php-5.2.0.tar.gz
# cd php-5.2.0

# CHOST="i686-pc-linux-gnu" CFLAGS="-O3 -msse2 -mmmx -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" CXXFLAGS="-O3 -msse2 -mmmx -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-zlib-dir --with-bz2 --with-tiff-dir --with-libxml-dir=/usr/local/libxml2 --with-gd=/usr/local/gd2 --with-freetype-dir --with-jpeg-dir --with-png-dir --with-ttf --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

# make && make install

10 、整合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 //在 WEB 目录不到默认文件,httpd 就会执行 /var/www/error/noindex.html

找到这一段:
# 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

11. 查看确认 L.A.M.P 环境信息
# echo ' ' > /home/www/phpinfo.php
# chmod 755 /home/www/phpinfo.php
用浏览器打开 http://127.0.0.1/phpinfo.p...
# echo ' ' > /home/www/testdb.php
# chmod 755 /home/www/testdb.php
# service mysqld start
用浏览器打开 http://127.0.0.1/testdb.ph...
检查 phpinfo 中的各项信息是否正确。


12、安装 Zend Optimizer
# cd /usr/local/src
# wget http://downloads.zend.com/...
# tar xzvf ZendOptimizer-3.2.0-linux-glibc21-i386.tar.gz
# ./ZendOptimizer-3.2.0-linux-glibc21-i386/install.sh
按照它的提示一步步进行就行了。
13、安装eaccelerator // eaccelerator是php的加速软件,使用后php的执行效率会有较大幅度的提升。目前eaccelerator 0.9.5已经和ZendOptimizer-3.2.0能够很好兼容啦。不过我个人觉得,ZendOptimizer-3.2.0没有加速的功能,只不过起到了执行zend加密的作用而已。闲话不多说了,大家有兴趣的。可以去google下。

# cd /usr/local/src
# wget http://bart.eaccelerator.n...
# tar -jxvf eaccelerator-0.9.5.tar.bz2
# cd eaccelerator-0.9.5

export PHP_PREFIX="/usr/local/php"
$PHP_PREFIX/bin/phpize //指定一下php的目录

# ./configure --enable-eaccelerator=shared --with-php-config=$PHP_PREFIX/bin/php-config // 设置

# make & make install

编译安装后我们会看到屏幕提示的eaccelerator.so所在的目录,比如我得到的是/usr/local/php/lib/php/extensions/no-debug-zts-20060613/eaccelerator.so,记住这个路径,待会要用到。

修改php.ini(安装完zend之后,php.ini存放于/usr/local/Zend/etc)
在文件最后,zend之前,注意,这部分内容务必放在zend之前,不然可能会出现不可预期的服务器问题。添加下列信息:

extension="/usr/local/php/lib/php/extensions/no-debug-zts-20060613/eaccelerator.so"
eaccelerator.shm_size="32"
eaccelerator.cache_dir="/tmp/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"

解释:
zend_extension 是安装完程序自动指示给我们的
eaccelerator.shm_size="32" 缓存大小单位MB
eaccelerator.cache_dir="/tmp/eaccelerator" 缓存路径

# mkdir /tmp/eaccelerator // 建立目录
# chmod 0777 /tmp/eaccelerator // 修改目录属性

最后重新启动apachectl

重启apache,phpinfo显示:
This program makes use of the Zend Scripting Language Engine:
Zend Engine v2.2.0, Copyright (c) 1998-2006 Zend Technologies
with eAccelerator v0.9.5, Copyright (c) 2004-2006 eAccelerator, by eAccelerator
with Zend Extension Manager v1.0.11, Copyright (c) 2003-2006, by Zend Technologies
with Zend Optimizer v3.2.0, Copyright (c) 1998-2006, by Zend Technologies

也会有eAccelerator的具体信息。





经过这几个步骤,我们的LAMP服务器就环境基本建立成功啦。感觉上也不是很难,是吧?
当然对于打造基于动态IP的网站,以上的信息还不够,还有建立ADSL拨号,NAT,动态域名更新,防火墙,安装论坛程序等一系列的工作,我会慢慢地写出自己的心得与大家分享。毕竟这对我来说,也是个学习的过程。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics