centOS 5.5下搭建LAMP环境.doc_第1页
centOS 5.5下搭建LAMP环境.doc_第2页
centOS 5.5下搭建LAMP环境.doc_第3页
centOS 5.5下搭建LAMP环境.doc_第4页
centOS 5.5下搭建LAMP环境.doc_第5页
已阅读5页,还剩6页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Cenos下搭建LAMP环境(其实最建党的方式就是利用yum来安装,可能是系统的原因(求指正)安装完之后版本比较低,所以老老实实卸载按下面步骤重装)一、web服务器的安装关闭selinuxvi /etc/selinux/config设置 SELINUX=disabled1、安装开发工具软件包组yum -y groupinstall Development Tools2、更新软件yum -y update3、安装mysql,从网站上下载最新的srpm包/downloads/mysql/#downloads3.1、安装mysql依赖库 yum -y install gperf ncurses-devel readline-devel zlib-devel cmake libaio-devel3.2、编译mysql rpm包rpmbuild -rebuild MySQL-5.5.20-1.linux2.6.src.rpm3.3、安装rpm包cd /usr/src/redhat/RPMS/x86_64/rpm -ivh MySQL*3.4、配置mysqlcp /usr/share/mysql/f /etc/f3.5、开启mysql 并开机运行service mysql startchkconfig mysql on3.6、设置mysql安全参数运行 mysql_secure_installation4、安装新版apr,从网站上下载源码包/apache/apr/4.1、编译apr为rpm包rpmbuild -ta apr-1.4.5.tar.bz2cd /usr/src/redhat/RPMS/x86_64/rpm -ivh apr*4.2、安装apr-util4.2.1、安装apr-util依赖包yum -y install expat-devel libuuid-devel db4-devel postgresql-devel sqlite-devel freetds-devel unixODBC-devel openldap-devel openssl-devel nss-devel4.2.2、编译apr-util为rpm包rpmbuild -ta apr-util-1.3.12.tar.bz2cd /usr/src/redhat/RPMS/x86_64/rpm -ivh apr-util*5、安装apache,从apache官网下载源码包/apache/httpd/5.1、安装依赖包yum -y install pcre-devel distcache*5.2、编译apache为rpm包,最高版本支持到2.2.21,如果要安装更高版本的apache软件,则要升级其他相关软件rpmbuild -ta httpd-2.2.21.tar.gz5.3、安装http rpm包cd /usr/src/redhat/RPMS/x86_64rpm -ivh httpd*rpm -ivh mod_ssl*5.4、开启httpd 并开机启动service httpd startchkconfig httpd on6、安装php,从网站上下载最新版本的srpm包6.1、安装依赖包yum -y install bzip2-devel curl-devel gmp-devel pam-devel libtool-ltdl-devel libevent-devel libc-client-devel libxml2-devel net-snmp-devel libxslt-devel libxml2-devel libjpeg-devel libpng-devel freetype-devel libXpm-devel libmcrypt-devel libtidy-devel aspell-devel recode-devel libicu-devel6.2、编译php为rpm包cp /usr/bin/mysql_config /usr/lib64/mysql/mysql_configrpmbuild -rebuild php-5.3.9-1.w5.src.rpm6.3、安装php rpm包cd /usr/src/redhat/RPMS/x86_64/rpm -ivh php*6.4、修改php 配置根据需要修改内存和执行时间的参数7、安装fastcgi 从网站下载apache相应版本(mod_fastcgi-SNAP-0910052141.tar.gz)tar zxf mod_fastcgi-SNAP-0910052141.tar.gzcd mod_fastcgi-SNAP-0910052141apxs -o mod_fastcgi.so -c *.ccp .libs/mod_fastcgi.so .apxs -i -a -n fastcgi mod_fastcgi.so7.1、编辑vi /etc/httpd/conf.d/fastcgi.conf ScriptAlias /fcgi-bin/ /var/fcgi-bin/ FastCgiExternalServer /var/fcgi-bin/php-cgi -host :9000 -appConnTimeout 1800 -idle-timeout 300 -pass-header Authorization SetHandler fastcgi-script Options FollowSymLinks Order allow,deny Allow from all AddType application/x-httpd-php .php AddHandler php-fastcgi .php Action php-fastcgi /fcgi-bin/php-cgicd /varmkdir fcgi-bincd fcgi-bincp /usr/bin/php-cgi .chown apache:apache php-cgi7.2、配置apache主配置文件 使之包含fastcgi.conf这个文件先禁用原有的proxy模块和cgi模块vi /etc/httpd/conf/httpd.conf在末尾加入如下行Include conf.d/fastcgi.conf7.3、开启php-fpm 并开机启动service php-fpm startchkconfig php-fpm on8、安装zendguard 从官网下载 ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gzvi /etc/php.d/zend.inizend_extension=/usr/lib64/php/modules/ZendGuardLoader.soservice php-fpm restart9、配置/etc/sysctl.conf,往该文件末尾添加如下内容vi /etc/sysctl.confnet.ipv4.tcp_max_syn_backlog = 65536dev_max_backlog = 32768net.core.somaxconn = 32768net.core.wmem_default = 8388608net.core.rmem_default = 8388608net.core.rmem_max = 16777216net.core.wmem_max = 16777216net.ipv4.tcp_timestamps = 0net.ipv4.tcp_synack_retries = 2net.ipv4.tcp_syn_retries = 2net.ipv4.tcp_tw_recycle = 1#net.ipv4.tcp_tw_len = 1net.ipv4.tcp_tw_reuse = 1net.ipv4.tcp_mem = 94500000 915000000 927000000net.ipv4.tcp_max_orphans = 3276800#net.ipv4.tcp_fin_timeout = 30#net.ipv4.tcp_keepalive_time = 120net.ipv4.ip_local_port_range = 1024 6553510、配置/etc/security/limits.conf ,往该文件末尾添加如下内容vi /etc/security/limits.conf * soft nofile 262144* hard nofile 262144* soft nproc 262144* hard nproc 26214411、新建http日志文件目录mkdir -p /var/log/webchown -R apache:apache /var/log/web12、修改apache配置和php的配置参考已经在运行的配置文件13、源码编译pureftpwget /pub/pure-ftpd/releases/pure-ftpd-1.0.32.tar.gzrpmbuild -ta pure-ftpd-1.0.32.tar.gzcd /usr/src/redhat/RPMS/x86_64rpm -ivh pure*以上所有配置可以参考已经在运行的服务器 以web22为准14、配置开机禁用防火墙chkconfig iptables off15、重启服务器reboot16、对于服务器排错,这里没办法列举,只能通过查看相关日志信息来解决,如果解决不了,通过网络上搜索,切忌在没有看清楚相关命令的作用的情况下,复制粘贴到服务器上进行操作,如果误操作,轻则重启相关服务或者整台服务器,重则损失大量数据17、要注意备份网站数据库和网站模板,目前每天都有定时备份这些数据到pr3,路径为/data/backup18、各服务的配置文件mysql: /etc/fhttpd: /etc/httpd/conf/http.conf /etc/httpd/conf/extra/ /etc/httpd/conf.d/ /etc/httpd/conf.d/vhosts/ 目录下php: /etc/php.ini /etc/php.d/ /etc/php-fpm.conf /etc/php-fpm.d/www.confpureftp: /etc/pure-ftpd.conf /etc/pure-ftpd/pureftpd-mysql.conf 18、需要定期整站备份到其他服务器上,一般半个月或者一个月整站备份一次二、反向代理服务器安装请参考如下链接/183345/166381第1部分:安装 1. 建立用户及组 /usr/sbin/groupadd www /usr/sbin/useradd -g www www 2. 安装pcre 让nginx支持rewrite 方便以后所需 wget ftp:/ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.8.tar.gz tar zxvf pcre-7.8.tar.gz cd pcre-7.8/ ./configure make & make install 3. 安装nginx wget http:/sysoev.ru/nginx/nginx-0.7.58.tar.gz tar zxvf nginx-0.7.58.tar.gz cd nginx-0.7.58/ ./configure -user=www -group=www -prefix=/usr/local/webserver/nginx -with- http_stub_status_module -with-http_ssl_module -with-cc-opt=-O2 -with-cpu-opt=opteron make & make install #注意上文中的-with-cc-opt=-O2 -with-cpu-opt=opteron 这是编译器优化,目前最常用的是-02 而不是3.后面对应CPU的型号,可参照:http:/wiki.gentoo.tw/index.php/HOWTO_CFLAG第2部分:配置及优化配置文件 1. nginx.conf 配置文件:user www www;worker_processes 4;# debug | info | notice | warn | error | crit error_log /usr/local/webserver/nginx/logs/nginx_error.log crit;pid /usr/local/webserver/nginx/nginx.pid;#Specifies the value for maximum file descriptors that can be opened by this process.worker_rlimit_nofile 51200;events use epoll; worker_connections 51200;http include mime.types; default_type application/octet-stream; source_charset GB2312; server_names_hash_bucket_size 256; client_header_buffer_size 256k; large_client_header_buffers 4 256k; #size limits client_max_body_size 50m; client_body_buffer_size 256k; client_header_timeout 3m; client_body_timeout 3m; send_timeout 3m;#参数都有所调整.目的是解决代理过程中出现的一些502 499错误 sendfile on; tcp_nopush on; keepalive_timeout 120; #参数加大,以解决做代理时502错误 tcp_nodelay on; include vhosts/upstream.conf; include vhosts/bbs.linuxtone.conf;2. upstream.conf 配置文件(这也是做负载的配置方法)upstream.conf upstream server :8099; 3. 站点配置文件bbs.linuxtone.confserver listen 80; server_name bbs.linuxtone.conf; charset GB2312; index index.html index.htm; root /date/wwwroot/linuxtone/; location /NginxStatus/ stub_status on; access_log off; location / root /date/wwwroot/linuxtone/; proxy_redirect off ; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 50m; client_body_buffer_size 256k; proxy_connect_timeout 30; proxy_send_timeout 30; proxy_read_timeout 60; proxy_buffer_size 256k; proxy_buffers 4 256k; proxy_busy_buffers_size 256k; proxy_temp_file_write_size 256k; proxy_next_upstream error timeout invalid_header http_500 http_503 http_404; proxy_max_temp_file_size 128m; proxy_pass ; #参数都有所调整.目的是解决代理过程中出现的一些502 499错误 #Add expires header for static content location * .(jpg|jpeg|gif|png|swf)$ if (-f $request_filename) root /date/wwwroot/linuxtone/; expires 1d; break; log_format access $remote_addr - $remote_user $time_local $request $status $body_bytes_sent $http_referer $http_user_agent $http_x_forwarded_for; access_log /exp/nginxlogs/bbs.linuxtone_access.log access; 注:第二种代理方式nginx 处理下图片,html等静态的东西.其它动态由apache处理.因此apache也需要做一些参数调整.设置图片等过期时间.缓解请求.如果源与nginx在同一台机器建议使用如下方法: location / proxy_pass :8099/; proxy_redirect default ; 针对不同的目录进行代理把下面的配置放到根目录代理的上面 location /linuxtone/ proxy_pass :8099/linuxtone/; proxy_redirect default ; 4 源配置 ServerAdmin liuyu105# DocumentRoot /date/wwwroot/linuxtone ServerName ErrorLog logs/linuxtone_error_log CustomLog |/usr/local/sbin/cronolog logs/linuxtone_access_log.%Y%m%d combined 第3部分:源的优化1 apache-mpm.conf StartServers 15 MinSpareServers 15 MaxSpareServers 30 ServerLimit 2536 MaxClients 2048 MaxRequestsPerChild 15002 apache-keepaliveTimeout 120 #与nginx的保持一至KeepAlive OnMaxKeepAliveRequests 400KeepAliveTimeout 7第4部分:PHP的优化优化一:将PHP由之前的xcache换成eaccelerator1 安装wget /source//eaccelerator-.tar.bz2tar jxvf eaccelerator-.tar.bz2cd eaccelerator-/usr/local/webserver/php/bin/phpize./configure -enable-eaccelerator=shared -with-php-config=/usr/local/php5/bin/php-configmakemake install注:PHP路径以安装为准!2 配置sed -i s#extension_dir = ./#extension_dir = /usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/nextension = memcache.son# /etc/php.inised -i s#output_buffering = Off#output_buffering = On# /etc/php.inised -i s#; always_populate_raw_post_data = On#always_populate_raw_post_data = On#g /etc/php.ini配置eAccelerator加速PHP:mkdir -p /usr/local/webserver/eaccelerator_cachevi /etc/php.ini按shift+g键跳到配置文件的最末尾,加上以下配置信息:eacceleratorzend_extension=/usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.soeaccel

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论