参考http://www.osyunwei.com/archives/2696.html
先配置yum源
安装优先级插件,yum install yum-plugin-priorities.noarch(noarch 平台无关意思,noarch即no architectures)
修改/ect/yum.repos.d/CentOS-Base.repo,[base] 、[updates]、[extras]添加priority=1;[centosplus]、[contrib]添加priority=2
系统保留1-10,第三方源用11-99,1为最高级
安装epel, rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-7.noarch.rpm
导入key,rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
vi /etc/yum.repos.d/epel.repo,[epel]下面增加priority=11
一、配置好ip、DNS、网关,确保使用远程连接工具能够连接服务器
centos设置ip地址、网关、DNS教程:http://www.osyunwei.com/archives/423.html
二、配置防火墙,开启80端口、3306端口
vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT(允许80端口通过防火墙)
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT(允许3306端口通过防火墙)
特别提示:很多网友把这两条规则添加到防火墙配置的最后一行,导致防火墙启动失败,正确的应该是添加到默认的22端口这条规则的下面
添加好之后防火墙规则如下所示:
#########################################################
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
#########################################################
/etc/init.d/iptables restart #最后重启防火墙使配置生效
三、关闭SELINUX
vi /etc/selinux/config
#SELINUX=enforcing #注释掉
#SELINUXTYPE=targeted #注释掉
SELINUX=disabled #增加
:wq 保存,关闭
shutdown -r now #重启系统
四 、系统约定
软件源代码包存放位置:/usr/local/src
源码包编译安装位置:/usr/local/软件名字
五、下载软件包
1、下载apache
httpd-2.4.2.tar.bz2
2、下载MySQL
mysql-5.5.24.tar.gz
3、下载php
php-5.3.13.tar.bz2
4、下载cmake(MySQL编译工具)
http://www.cmake.org/files/v2.8/cmake-2.8.7.tar.gz
5、下载libmcrypt(PHPlibmcrypt模块)
ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
6、下载apr(Apache库文件)
http://mirror.bit.edu.cn/apache/apr/apr-1.4.6.tar.gz (还要安装apr-devel)
7、下载apr-util(Apache库文件)
http://mirror.bit.edu.cn/apache/apr/apr-util-1.4.1.tar.gz (还要安装apr-util-devel)
用WinSCP远程连接到服务器,把下载好的软件上传到服务器/usr/local/src下面
六、安装编译工具及库文件(使用CentOS yum命令安装)
在安装某个软件时先用rpm -qa | grep 软件名,看是否已经安装
可以用rpm -ivh 软件名 --test ,测试安装查看依赖关系
centos6.2已经安装了apache2.2.1,libxml,zlib,libpng, freetype, autoconf,
有些还要安装它到开发包,如上面的libpng-devel,freetype-devel
可以用./configure --help | grep 选项,查看该选项配置方式
安装libmcrypt
./configure --prefix=/usr/local/libmcrypt/ #加密解密库
./configure --enable-ltdl-install ## libltdl在libmcrypt包中(也可以用./configure --help | grep ltdl 查找该选项配置方式)
安装jpeg
先创建目录bin,lib,include,man/man1 ,./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static
安装gd
./configure --prefix=/usr/local/gd2/ --with-jpeg=/usr/local/jpeg6/
安装apache
安装apache前先安装apr和apr-util
./configure --prefix=/usr/local/apr
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config
接着cd /usr/local/src/
mv apr httpd/srclib/apr
mv apr-util httpd/srclib/apr-util
./configure --prefix=/usr/local/apache2/ --sysconfdir=/etc/httpd/ --with-included-apr --disable-userdir --enable-so --enable-deflate-shared --enable-expires-shared --enable-rewrite-shared --enable-static-support
/usr/local/apache2/bin/apachectl -k start #启动
vi /etc/httpd/httpd.conf
修改: #ServerName 127.0.01:80
DirectoryIndex index.html index.php
Options FollowSymLinks #不显示目录结构
AllowOverride All #开启apache支持伪静态,有三处都做修改
LoadModule rewrite_module modules/mod_rewrite.so #取消前面的注释,开启apache支持伪静态
vi /etc/profile #添加apache服务系统环境变量
在最后添加下面这一行
export PATH=$PATH:/usr/local/apache2/bin
cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd #把apache加入到系统启动
vi /etc/init.d/httpd #编辑文件
在#!/bin/sh下面添加一下两行
#chkconfig:2345 10 90
#description:Activates/Deactivates Apache Web Server
chown 用户组.用户名 -R /usr/local/apache2/htdocs #更改目录所有组
chmod 700 /usr/local/apache2/htdocs -R #更改apache网站目录权限
chkconfig httpd on #设置开启启动
/etc/init.d/httpd start
service httpd restart
安装mysql
安装mysql前先安装ncurses ,系统本身安装了ncurses,但还有装ncurses-devel
groupadd mysql #添加mysql组
useradd -g mysql mysql -s /bin/false #创建用户mysql并加入到mysql组,不允许mysql用户直接登录系统(/bin/false)
mkdir -p /data/mysql/ #创建mysql数据库存放目录
chown -R mysql:mysql /data/mysql #设置mysql数据目录权限
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc/ #配置
cd /usr/local/mysql
cp ./support-files/my-huge.cnf /etc/my.cnf #拷贝配置文件(注意:/etc目录下面默认有一个my.cnf,直接覆盖即可)
vi /etc/my.cnf #编辑配置文件,在[mysqld]部分增加下面一行
datadir=/data/mysql #添加mysql数据库路径
./scripts/mysql_install_db --user=mysql #生成mysql系统数据库
cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld #把mysql加入系统启动
chmod 755 /etc/init.d/mysqld
chkconfig mysqld on
vi /etc/rc.d/init.d/mysqld
basedir=/usr/local/mysql
datadir=/data/mysql
service mysqld start
vi /etc/profile #把mysql服务加入系统环境变量:在最后添加下面这一行
export PATH=$PATH:/usr/local/mysql/bin
mysql_secure_installation # 设置mysql密码
或者直接修改密码/usr/local/mysql/bin/mysqladmin -u root -p password "123456" #修改密码
service mysqld restart
安装php
./configure --prefix=/usr/local/php/ --with-config-file-path=/usr/local/php/etc/ --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-gd=/usr/local/gd2/ --with-iconv --with-jpeg-dir=/usr/local/jpeg6/ --with-zlib --enable-xml --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curlwrappers --enable-mbstring=all --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt=/usr/local/libmcrypt/
注意这里容易出现 make: *** [ext/phar/phar.php] 错误 127
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/
或
ln -s /usr/local/mysql/lib/libmysqlclient.so /usr/lib/
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18
apache libltdl.so.3:cannot open shared object file:No such file or directory异常
ln -s /usr/local/lib/libltdl.so.3 /usr/lib/libltdl.so.3
make: [ext/phar/phar.phar] 错误 1 (忽略)
解决方法在编译的时候加--without-pear参数