centos apache php CentOS 5.0 编译安装 Apache+PHP...
发布日期:2021-08-15 20:51:59 浏览次数:2 分类:技术文章

本文共 23051 字,大约阅读时间需要 76 分钟。

CentOS 5.0 编译安装 Apache++Mysql+Zend Optimizer+Eaccelerator+MyAdmin 2009-05-06 12:47 CentOS是Community ENTerprise Operating System的简称,我们有很多人叫它社区企业操作系统,不管你怎么叫它,它都是Linux操作系统的一个发行版本。

CentOS并不是全新的Linux发行版,倘若一说到Red Hat这个大名,大家似乎都听过。在Red Hat家族中有企业版的产品,它是Red Hat Enterprise Linux(以下称之为RHEL),CentOS正是这个RHEL的克隆版本。RHEL是很多企业采用的Linux发行版本,需要向Red Hat付费才可以使用,并能得到付过费用的服务和技术支持和版本升级。CentOS可以像RHEL一样的构筑Linux系统环境,但不需要向Red Hat付任何的产品和服务费用,同时也得不到任何有偿技术支持和升级服务。
Red Hat公司的产品中,有Red Hat Linux(如Redhat8,9)和针对企业发行的版本Red Hat Enterprise Linux,都能够通过网络FTP免费的获得并使用,但是在2003年的时候,Red Hat Linux停止了发布,它的项目由Fedora Project这个项目所取代,并以Fedora Core这个名字发行并提供给普通用户免费使用。Fedora Core这个Linux发行版更新很快,大约半年左右就有新的版本发布。目前的版本是Fedora Core 6,这个Fedora Core试验的韵味比较浓厚,每次发行都有新的功能被加入到其中,得到的成功结果将被采用道RHEL的发布中。虽说这样,频繁的被改进更新的不安定产品对 于企业来说并不是最好的选择,大多数企业还是会选择有偿的RHEL产品(这里面有很深的含义,比如说企业用Linux赚钱,赚到的钱回报给企业,资金在企 业间流通,回报社会,提高服务水准等)。
在构成RHEL的大多数软件包中,都是基于GPL协议发布的,也就是我们常说的开源软件。正因为是这样,Red Hat公司也遵循这个协议,将构成RHEL的软件包公开发布,只要是遵循GPL协议,任何人都可以在原有的软件构成的基础上再开发和发布。CentOS就是这样在RHEL发布的基础上将RHEL的构成克隆再现的一个Linux发行版本。RHEL的克隆版本不只CentOS一个,还有White Box Enterprise Linux和TAO Linux 和Scientific Linux(其他的这些都没听说过,是吧?)。
虽然说是RHEL的克隆,但并不是一模一样,所说的克隆是具有100%的互换性(真的么?)。但并不保障对应RHEL的软件在CentOS上面也能够100%的正常工作。并且安全漏洞的修正和软件包的升级对应RHEL的有偿服务和技术支持来说,数日数星期数个月的延迟情况也有(其实也没看出来多慢)。
CentOS的特点
CentOS的全称里面我们可以看到Enterprise OS,也就是说企业系统,这个企业系统并不是企业级别的系统,而是它可以提供企业级应用所需要的要素。
例如:
稳定的环境
长期的升级更新支持
保守性强
大规模的系统也能够发挥很好的性能
CentOS满足以上的要素,满足上面要素的发行版还有Fedora 。Fedora和CentOS非常的相像,但是对CentOS来 说,Fedora提供更多的新的功能和软件,发布更新快等特点,这样在稳定性和管理方面就增加了很多工作。企业所需要的系统环境应该是,高效稳定的系统环 境,一次构建后能够长期使用的系统环境,所以Fedora那样的频繁更新发布的系统环境并不对应企业的应用。另一方面,CentOS却能够满足以上企业的需要,在众多的RHEL的克隆版本中,CentOS是很出众很优秀的。
官方网站:http://www.centos.org
中文社区:http://www.centospub.com/bbs
1、下载centos 5
我是下载的DVD版本,大家也可以下载服务器CD安装版本,其实都差不多。大家可以到这儿下载,速度很快的。
http://ftp.iasi.roedu.net/mirrors/ce…86-bin-DVD.iso
当然也可以在windows下用BT或迅雷下载,速度也很不错的。
下载后当然就刻录成光盘。我建议你刻录DVD啦,如果是菜鸟,也可以在图形界面进行学习,不会这么抓不住头脑。
2、(1)安装CentOS 5
作为服务器,不安装不需要的组件,所以在选择组件的时候,除了选择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.be10.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS -5
protect=1
#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=http://mirror.be10.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS -5
protect=1
#packages used/produced in the build but not released
[addons]
name=CentOS-$releasever - Addons
baseurl=http://mirror.be10.com/centos/$releasever/addons/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS -5
protect=0
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=http://mirror.be10.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS -5
protect=0
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=http://mirror.be10.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS -5
protect=1
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
baseurl=http://mirror.be10.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
protect=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS -5
#packages in testing
[testing]
name=CentOS-5 - Testing
baseurl=http://mirror.be10.com/centos/5/testing/i386/
gpgcheck=1
enabled=0
protect=0
保存。
(2)更新系统,我们使用yum,
然后执行:
# yum upgrade
建议更新所有列出的程序,rhel 5.X的稳定性还要继续努力呢。
(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 openssl-devel libxml2-devel
#这里我们将编译GD所必须的一些小软件比如libpng,libtiff,freetype,libjpeg,等先用RPM的方式一并安装好,避免手动编译浪费时间,同时也能避免很多错误,这几个小软件的编译很麻烦。这几个小软件编译错误了,GD当然安装不了,5的编译当然也没戏了。所以我们抓大放小,对这些小牛鬼蛇神采取快速简洁的方式进行安装。并且对服务器的性能也不能产生什么影响。
另外libxml2系统已经默认安装了,所以我们不需要手工编译了,直接安装它的开发包就行了。
6. 源码编译安装所需包 (Source)
(1) GD2
# cd /usr/local/src
# wget http://www.boutell.com/gd/http/gd-2.0.34.tar.gz
# tar xzvf gd-2.0.34.tar.gz
# cd gd-2.0.34
# CHOST=”i686-pc-linux-gnu” CFLAGS=”-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer” CXXFLAGS=”-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer” ./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/download/cronolog-1.6.2.tar.gz
# tar xzvf cronolog-1.6.2.tar.gz
# cd cronolog-1.6.2
# ./configure –prefix=/usr/local/cronolog
# make
# make install
7、编译mysql 5.0.46
mysql 5.0.46是企业版本,貌似双数版本都是企业版本了。个人觉得代码质量要比社区版本要好一些。大家可以下载,免费使用。并不需要向mysql公司交钱。
cd /usr/local/src
# wget http://mirror.provenscaling.com/mysq…-5.0.46.tar.gz
# tar xzvf mysql-5.0.46.tar.gz
# cd mysql-5.0.46
修改mysql 客户端最大连接数, 默认的只有100,远远达不到我们的要求。
# vi sql/mysqld.cc
搜索找到下面一行:
{”max_connections”, OPT_MAX_CONNECTIONS,
“The number of simultaneous clients allowed.”, (gptr*) &max_connections,
(gptr*) &max_connections, 0, GET_ULONG, REQUIRED_ARG, 100, 1, 16384, 0, 1,
0},
将其中的100改为1500, 当然小点也可以,根据你的需要来,不建议改的太大。
{”max_connections”, OPT_MAX_CONNECTIONS,
“The number of simultaneous clients allowed.”, (gptr*) &max_connections,
(gptr*) &max_connections, 0, GET_ULONG, REQUIRED_ARG, 1500, 1, 16384, 0, 1,
0},
保存。
# CHOST=”i686-pc-linux-gnu” CFLAGS=”-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer” CXXFLAGS=”-O3 -msse2 -mmmx -Wall -W -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=-enterprise-gpl –with-mysqld-user=mysql –without-debug –with-big-tables –with-charset=utf8 –with-collation=utf8_general_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 –without-isam
配置成功会提示:
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!
// 注意 ,CHOST=”i686-pc-linux-gnu” CFLAGS=”-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer” CXXFLAGS=”-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer” 这个环境参数只针对intel P4 芯片,如果你的CPU是AMD的,注意不能使用。请查看相应的编译优化参数。否则程序会无法编译,即使编译成功也无法运行,嘿嘿。
关于其他CPU的优化请看我的BLOG的一篇转贴:
http://www.cnprint.org/bbs/blogs/1/blog43.
# 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-medium.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.org/httpd/httpd-2.2.6.t ar.gz
# tar zxvf httpd-2.2.6.tar.gz
# cd httpd-2.2.6
依次安装apr和apr-util
# cd srclib/apr
# CHOST=”i686-pc-linux-gnu” CFLAGS=”-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer” CXXFLAGS=”-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer” ./configure –prefix=/usr/local/apr –enable-threads –enable-other-child –enable-static
# make && make install
# cd ../apr-util
# CHOST=”i686-pc-linux-gnu” CFLAGS=”-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer” CXXFLAGS=”-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer” ./configure –prefix=/usr/local/apr-util –with-apr=/usr/local/apr/ –with-mysql=/usr/local/mysql
# make && make install
cd /usr/local/src/httpd-2.2.6
# CHOST=”i686-pc-linux-gnu” CFLAGS=”-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer” CXXFLAGS=”-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer” ./configure –prefix=/usr/local/apache2 –enable-mods-shared=all –with-mysql=/usr/local/mysql –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 –with-apr=/usr/local/apr/ –with-apr-util=/usr/local/apr-util/ –enable-ssl –with-ssl=/usr/include/openssl
# 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-mods-shared=all //编译全部的模板,对于不需要我们可以在httpd.conf去掉。
–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 版本的
–enable-ssl // 编译 ssl模块。 我们不再使用worker模式编译apache,worker模式和貌似有一些不协调不稳定之处。所以使用了默认的perfork模式。
apache设置成开机自启动:
在/etc/rc.d/rc.local文件中加入一行
/usr/local/apache2/bin/apachectl start
这样每次重新启动系统以后,apache也会随系统一起启动.
或者
# cp /usr/local/apache2/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、编译 5.2.5-devel。
5.2.4有点小BUG,无法在centos 5上正常编译,官方已经在5.2.5中修复了。所以我们使用 5.2.5进行编译。
Suhosin是增强型安全补丁,可以编译到静态内核中,也可以编译成动态扩展。我个人强烈你建议安装成静态内核。Suhosin已经进入freebsd和gentoo的ports。下面的以下先说静态安装步骤。当然你也可以在安装后将它编译成的动态扩展。
# cd /usr/local/src
# wget http://cn..net/get/-5.2.5.tar.gz/from/this/m irror
wget http://www.hardened-.net/suhosin/…9.6.2.patch.gz
# tar zxvf -5.2.5.tar.gz
# gunzip suhosin-patch-5.2.1-0.9.6.2.patch.gz
# cd -5.2.5
# CHOST=”i686-pc-linux-gnu” CFLAGS=”-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer” CXXFLAGS=”-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer” ./configure –prefix=/usr/local/ –with-apxs2=/usr/local/apache2/bin/apxs –with-pear=/usr/share/ –with-zlib-dir –with-bz2 –with-libxml-dir=/usr –with-gd=/usr/local/gd2 –enable-gd-native-ttf –enable-gd-jis-conv –with-freetype-dir –with-jpeg-dir –with-png-dir –with-ttf=shared,/usr –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 –enable-maintainer-zts –enable-zend-multibyte –enable-inline-optimization –enable-zend-multibyte –enable-sockets –enable-soap –with-openssl
配置成功会提示:
+——————————————————————–+
| License: |
| This software is subject to the License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+——————————————————————–+
Thank you for using .
# make
# make install
# cp .ini-recommended /etc/.ini
在这里也顺便说一下将suhosin安装成为的动态扩展的方法。毕竟网上根本不见它的中文安装教程。
虽然我个人不推荐这种方式。
wget http://www.hardened-.net/suhosin/…sin-0.9.16.tgz
tar zxvf suhosin-0.9.16.tgz
cd suhosin-0.9.16
./configure –with--config=/usr/local//bin/-config
make
make install
会提示编译的模块存在的目录,记住它。
Installing shared extensions: /usr/local//lib//extensions/no-debug-non-zts -20060613/
然后在.ini中增加一行下列语句。
extension=/usr/local//lib//extensions/no-deb ug-non-zts-20060613/suhosin.so
10 、整合apache
# vi /usr/local/apache2/conf/httpd.conf
在最后一行加上:
AddType application/x-httpd- .
查找:(设置 WEB 默认文件)
DirectoryIndex index.
替换为:
DirectoryIndex index. index. index.htm //在 WEB 目录不到默认文件,httpd 就会执行 /var/www/error/noindex.
找到这一段:
# 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
# 监听443端口,支持https连接
取消注释 httpd.conf 中的 Include conf/extra/httpd-ssl.conf
保存httpd.conf,退出。
# /usr/local/apache2/bin/apachectl restart //重启 Apache
这时会出现错误:
/usr/local/apache2/bin/apachectl start
httpd: Syntax error on line 107 of /usr/local/apache2/conf/httpd.conf: Cannot load /usr/local/apache2/modules/lib5.so into server: /usr/local/apache2/modules/lib5.so: cannot restore segment prot after reloc: Permission denied
不急,我们慢慢解决。
先重启下机器:
reboot
这个Permission denied问题,在centos 5下面一般是Selinux引起的,作为生产用服务器,我建议你千万别草率地关掉Selinux一了百了。就像家里的防盗网,阻碍了你的猫自由进出窗户, 你不能为了猫方便,就把防盗网简单拆除是同样的道理。我看见网上许多人建议把Selinux简单关闭来解决这个问题,很不以为然。
我们可以这样操作:
# audit2allow -d
allow initrc_t usr_t:file execmod;
allow mount_t default_t:file execute;
# cd /etc/selinux/targeted/modules/
# audit2allow -M local -d
屏幕产生如下提示:
产生类型强制文件:local.te
正在编译策略
checkmodule -M -m -o local.mod local.te
semodule_package -o local.pp -m local.mod
********************重要 ***********************
为了在内核中加载这个新创建的策略软件包,
您需要执行
semodule -i local.pp
我们运行
# semodule -i local.pp
这样就让Selinux加载了新的规则。
更详细的内容请看我在BLOG上的转贴:
http://www.cnprint.org/bbs/blogs/1/blog48.
reboot
哈哈,apache不会再报错了吧?
这样我保留了selinux的功能,同时apache也能正常运行。
11. 查看确认 L.A.M.P 环境信息
vi /usr/local/apache2/htdocs/info.
新增加下面一行,并保存。
<? info(); ?>
# chmod 755 /usr/local/apache2/htdocs/info.
用浏览器打开 http://127.0.0.1/info.
# echo ‘‘ > /usr/local/apache2/htdocs/testdb.
# chmod 755 /usr/local/apache2/htdocs/testdb.
# service mysqld start
用浏览器打开 http://127.0.0.1/testdb.
检查 info 中的各项信息是否正确。
12、设置SSL并创建自己的CA
# cd /usr/share/ssl/misc
# ./CA -newca
屏幕上出现如下的提示:CA certificate filename (or enter to create)
这是要求输入要创建的CA的证书文件名, 可以直接回车或输入证书文件名。
Making CA certificate …
Generating a 1024 bit RSA private key
………++++++
…………………………..++++++
writing new private key to ‘./demoCA/private/./cakey.pem’
Enter PEM pass phrase:
Verifying password - Enter PEM pass phrase:-
此时要求输入和验证CA的私钥口令、国家代码(中国是CN)、省份、城市或地区、组织或企业名称、部门名称、CA的名称或服务器的主机名称、管理员电子邮件地址。
至此,在当前目录下生成了demoCA的目录,CA的证书就在该目录下,文件名为cacert.pem
生成服务器的证书请求
# ./CA -newreq
屏幕上出现如下的提示: Generating a 1024 bit RSA private key
……………………………………………..++++++
…..++++++
writing new private key to ‘newreq.pem’
Enter PEM pass phrase:
Verifying password - Enter PEM pass phrase:
此时要求输入和验证服务器的私钥口令、国家代码(中国是CN)、省份、城市或地区、组织或企业名称、部门名称、CA的名称或服务器的主机名称、管理员电子邮件地址。
Please enter the following ‘extra’ attributes
to be sent with your certificaterequest
A challenge password []:
An optional company name []:
.Request (and private key) is in newreq.pem
这是要求输入服务器的相关信息。
此时,在当前目录下生成了一个名为newreq.pem的文件,包含了要生成服务器数字证书的请求。
签署证书
# ./CA -sign
屏幕上出现如下的提示:
Using configuration from /usr/share/ssl/openssl.cnf
Enter PEM pass phrase:
此时一样需要输入CA的私钥口令、国家代码(中国是CN)、省份、城市或地区、组织或企业名称、部门名称、CA的名称或服务器的主机名称、管理员电子邮件地址。
Certificate is to be certified until Nov 19 13:46:19 2002 GMT (365 days)
Sign the certificate? [y/n]:y
这时显示证书请求文件中的各项信息,并询问是否要签署证书,回答y,进行签署。
1 out of 1 certificate requests certified, commit? [y/n]y
回答y,会显示已经签署的证书的信息,并在当前目录下生成服务器的证书文件newcert.pem。
# mkdir /usr/local/apache2/conf/ssl.crt/
# mkdir /usr/local/apache2/conf/ssl.key/
# cp newcert.pem /usr/local/apache2/conf/ssl.crt/server.pem
# cp newreq.pem /usr/local/apache2/conf/ssl.key/server.pem
更改服务器的证书文件的相关配置
# vi /usr/local/apache2/conf/extra/httpd-ssl.conf
查找并修改
# Server Certificate:
# Point SSLCertificateFile at a PEM encoded certificate. If
# the certificate is encrypted, then you will be prompted for a
# pass phrase. Note that a kill -HUP will prompt again. Keep
# in mind that if you have both an RSA and a DSA certificate you
# can configure both in parallel (to also allow the use of DSA
# ciphers, etc.)
SSLCertificateFile /usr/local/apache2/conf/ssl.crt/server.pem
#SSLCertificateFile /usr/local/apache2/conf/server-dsa.crt
# Server Private Key:
# If the key is not combined with the certificate, use this
# directive to point at the key file. Keep in mind that if
# you’ve both a RSA and a DSA private key you can configure
# both in parallel (to also allow the use of DSA ciphers, etc.)
SSLCertificateKeyFile /usr/local/apache2/conf/ssl.key/server.pem
#SSLCertificateKeyFile /usr/local/apache2/conf/server-dsa.key
示例文件
在SSL的根目录中生成一个index.,它是如下所示:
<>
这是SSL示例!
</>
测试
假如Web服务器的DNS名称是www.cnprint.org.
在浏览器的URL地址栏里输入 http://www.cnprint.org/,浏览器便会显示APACHE安装时确省的Test Page.
在浏览器的URL地址栏里输入 https://www.cnprint.org/,注意:是 https 而不是http !
浏览器会提示站点已经采用了SSL进行数据的加密传输.由于我们的CA证书不是浏览器缺省的信任的根证书,所以,浏览器会说无法确认服务器的证书可信。暂时不管,一直NEXT,最后,浏览器会显示:这是SSL示例!
可以把CA的证书放在非SSL的站点上,让浏览器下载并安装CA证书,并将其设置成可信任的根证书,便可解决上面的问题.8 解除HTTPD起动时的口令输入。
由于安全的原因,Web服务器的私钥是口令加密了的,每次重新起动HTTPD或Linux时,都会要求输入Web服务器的私钥的口令。
如果要解除HTTPD起动时的口令输入,可以这样:
# cd /usr/local/apache2/conf/ssl.key/
# cp server.pem server.pem.org
# openssl rsa -in server.pem.org -out server.pem
# chmod 400 server.pem
另外在网上看到一个方法,我没有试。有兴趣的可以试下。
创建SSL密码自动应答文件,否则每次Apache启动的时候,都会要求你输入SSL的密码.
创建 /usr/local/apache2/conf/ssl.key/sendsslpwd ,内容如下.
#!/bin/bash
SSLpasswd=”YOUR PASSPHRASE”
echo $SSLpasswd
chmod 755 /usr/local/apache2/conf/ssl.key/sendsslpwd
此时,Web服务器的私钥已经没有口令加密,一定要确保server.pem文件除root外,任何用户均无权读取它。
13、安装 Zend Optimizer
# cd /usr/local/src
# wget http://downloads.zend.com/optimizer/…21-i386.tar.gz
# tar xzvf ZendOptimizer-3.3.0-linux-glibc21-i386.tar.gz
# ./ZendOptimizer-3.3.0-linux-glibc21-i386/install.s h
按照它的提示一步步进行就行了。
总之一句话。如果你的服务器环境不需要ZendOptimizer,那么能不安就不安装这个。避免和eaccelerator冲突。
14、安装eaccelerator // eaccelerator是的加速软件,使用后的执行效率会有较大幅度的提升。目前eaccelerator 0.9.5.2已经和ZendOptimizer-3.3.0能够基本上兼容啦。不过我个人觉得,ZendOptimizer-3.3.0没有加速的功能,反而使运行变慢,只是起到了运行zend加密文件的作用而已。闲话不多说了,大家有兴趣的,可以去google下。
# cd /usr/local/src
# wget http://bart.eaccelerator.net/source/….9.5.2.tar.bz2
# tar -jxvf eaccelerator-0.9.5.2.tar.bz2
# cd eaccelerator-0.9.5.2
export _PREFIX=”/usr/local/
$_PREFIX/bin/ize //指定一下的目录
# ./configure –enable-eaccelerator=shared –with--config=$_PREFIX/bin/-config // 设置
# make & make install
编译安装后我们会看到屏幕提示的eaccelerator.so所在的目录,比如我得到的是/usr/local//lib//extensions/no-debug-zts-200 60613/eaccelerator.so,记住这个路径,待会要用到。
修改.ini(安装完zend之后,.ini存放于/usr/local/Zend/etc)
在文件最后,zend之前,注意,这部分内容务必放在zend之前,不然可能会出现不可预期的服务器问题。添加下列信息:
[eaccelerator]
extension=”/usr/local//lib//extensions/no-debug-zts-200 60613/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,info显示:
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.2, 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.3.0, Copyright (c) 1998-2006, by Zend Technologies
也会有eAccelerator的具体信息。
15、安装myadmin,管理mysql数据库
# cd /usr/local/apache2/htdocs/
# wget http://nchc.dl.sourceforge.net/sourc…-8-only.tar.gz
# tar zxvf MyAdmin-2.11.1-all-languages-utf-8-only.tar.gz
# mv MyAdmin-2.11.1-all-languages-utf-8-only myadmin
# cd myadmin/libraries
修改配置文件
# vi config.default. 找到这几行进行修改:
$cfg['Servers'][$i]['auth_type'] = ‘http’; // Authentication method (valid choices: config, http, HTTP, signon or cookie)
$cfg['Servers'][$i]['user'] = ‘root’; // MySQL user
$cfg['Servers'][$i]['password'] = ‘PASSWORD’; // MySQL password (only needed
经过这几个步骤,我们一个比较安全的LAMP服务器就环境基本建立成功啦。感觉上也不是很难,是吧?

转载于:https://www.cnblogs.com/myphoebe/archive/2011/11/01/2231036.html

转载地址:https://blog.csdn.net/weixin_30779691/article/details/98094380 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Linux流量监控工具 - iftop (最全面的iftop教程)
下一篇:Win10开启卓越性能

发表评论

最新留言

做的很好,不错不错
[***.243.131.199]2024年03月31日 21时45分26秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章