仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 744|回复: 9
打印 上一主题 下一主题

[其他Linux] linux教程之nginx+apache+mysql+php+memcached+squid搭建集群web情况

[复制链接]
简单生活 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-16 12:01:46 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
要多google,因为我不可能,也不可以给你解答所有内容,我只能告诉你一些关键点,甚至我会故意隐瞒答案,因为在寻找答案的过程中。
服务器的年夜用户量的承载计划
1、媒介
2、编译安装
3、安装MySQL、memcache
4、安装Apache、PHP、eAccelerator、php-memcache
5、安装Squid
6、跋文


1、媒介,筹办事情
以后,LAMP开辟形式是WEB开辟的首选,怎样搭建一个高效、牢靠、不乱的WEB服务器一向是个抢手主题,本文就是这个主题的一次实验。
我们接纳的架构图以下:

援用----------------------------------------------------
|客户端|===>|负载平衡器|===>|反向代办署理/缓存|===>|WEB服务器|===>|数据库服务器|
----------------------------------------------------
NginxSquidApache,PHPMySQL
eAccelerator/memcache筹办事情:
援用服务器:Intel(R)Xeon(TM)CPU3.00GHz*2,2GBmem,SCISC硬盘
操纵体系:CentOs4.4,内核版本2.6.9-22.ELsmp,gcc版本3.4.4
软件:
Apache2.2.3(能利用MPM形式)
PHP5.2.0(选用该版本是由于5.2.0的引擎绝对更高效)
eAccelerator0.9.5(减速PHP引擎,同时也能够加密PHP源程序)
memcache1.2.0(用于高速缓存经常使用数据)
libevent1.2a(memcache事情机制所需)
MySQL5.0.27(选用二进制版本,省往编译事情)
Nginx0.5.4(用做负载平衡器)
squid-2.6.STABLE6(做反向代办署理的同时供应专业缓存功效)

2、编译安装
1、)安装Nginx
1.)安装
Nginx发音为[enginex],是由俄罗斯人IgorSysoev创建的项目,基于BSD允许。听说他现在是F5的成员之一,英文主页:http://nginx.net。俄罗斯的一些年夜网站已利用它凌驾两年多了,一向体现非凡。
Nginx的编译参数以下:

[root@localhost]#./configure--prefix=/usr/local/server/nginx--with-openssl=/usr/include
--with-pcre=/usr/include/pcre/--with-http_stub_status_module--without-http_memcached_module
--without-http_fastcgi_module--without-http_rewrite_module--without-http_map_module
--without-http_geo_module--without-http_autoindex_module
在这里,必要申明一下,因为Nginx的设置文件中我想用到正则,以是必要pcre模块的撑持。我已安装了pcre及pcre-devel的rpm包,可是Ngxin其实不能准确找到.h/.so/.a/.la文件,因而我略微变通了一下:

[root@localhost]#mkdir/usr/include/pcre/.libs/
[root@localhost]#cp/usr/lib/libpcre.a/usr/include/pcre/.libs/libpcre.a
[root@localhost]#cp/usr/lib/libpcre.a/usr/include/pcre/.libs/libpcre.la
然后,修正objs/Makefile也许在908行的地位上,正文失落以下内容:

./configure--disable-shared
接上去,就能够一般实行make及makeinstall了。

2.)修正设置文件/usr/local/server/nginx/conf/nginx.conf
以下是我的nginx.conf内容,仅供参考:

#运转用户
usernobodynobody;
#启动历程
worker_processes2;
#全局毛病日记及PID文件
error_loglogs/error.lognotice;
pidlogs/nginx.pid;
#事情形式及毗连数下限
events{
useepoll;
worker_connections1024;
}
#设定http服务器,使用它的反向代办署理功效供应负载平衡撑持
http{
#设定mime范例
includeconf/mime.types;
default_typeapplication/octet-stream;
#设定日记格局
log_formatmain$remote_addr-$remote_user[$time_local]
"$request"$status$bytes_sent
"$http_referer""$http_user_agent"
"$gzip_ratio";
log_formatdownload$remote_addr-$remote_user[$time_local]
"$request"$status$bytes_sent
"$http_referer""$http_user_agent"
"$http_range""$sent_http_content_range";
#设定哀求缓冲
client_header_buffer_size1k;
large_client_header_buffers44k;
#开启gzip模块
gzipon;
gzip_min_length1100;
gzip_buffers48k;
gzip_typestext/plain;
output_buffers132k;
postpone_output1460;
#设定accesslog
access_loglogs/access.logmain;
client_header_timeout3m;
client_body_timeout3m;
send_timeout3m;
sendfileon;
tcp_nopushon;
tcp_nodelayon;
keepalive_timeout65;
#设定负载平衡的服务器列表
upstreammysvr{
#weigth参数暗示权值,权值越高被分派到的概率越年夜
#本机上的Squid开启3128端口
server192.168.8.1:3128weight=5;
server192.168.8.2:80weight=1;
server192.168.8.3:80weight=6;
}
#设定假造主机
server{
listen80;
server_name192.168.8.1www.360mini.com;
charsetgb2312;
#设定本假造主机的会见日记
access_loglogs/www.360mini.com.access.logmain;
#假如会见/img/*,/js/*,/CSS/*资本,则间接取当地文件,欠亨过squid
#假如这些文件较多,不保举这类体例,由于经由过程squid的缓存效果更好
location~^/(img|js|css)/{
root/data3/Html;
expires24h;
}
#对"/"启用负载平衡
location/{
proxy_passhttp://mysvr;
proxy_redirectoff;
proxy_set_headerHost$host;
proxy_set_headerX-Real-IP$remote_addr;
proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;
client_max_body_size10m;
client_body_buffer_size128k;
proxy_connect_timeout90;
proxy_send_timeout90;
proxy_read_timeout90;
proxy_buffer_size4k;
proxy_buffers432k;
proxy_busy_buffers_size64k;
proxy_temp_file_write_size64k;
}
#设定检察Nginx形态的地点
location/NginxStatus{
stub_statuson;
access_logon;
auth_basic"NginxStatus";
auth_basic_user_fileconf/htpasswd;
}
}
}
备注:conf/htpasswd文件的内容用apache供应的htpasswd工具来发生便可,内容大抵以下:
3.)检察Nginx运转形态
输出地点http://192.168.8.1/NginxStatus/,输出考证帐号暗码,便可看到相似以下内容:
Activeconnections:328
serveracceptshandledrequests
9309898228890
Reading:1Writing:3Waiting:324

第一行暗示今朝活泼的毗连数
第三行的第三个数字暗示Nginx运转到以后工夫承受到的总哀求数,假如快到达了下限,就必要加年夜下限值了。
第四行是Nginx的行列形态

3、安装MySQL、memcache



1.)安装MySQL,步骤以下:
[root@localhost]#tarzxfmysql-standard-5.0.27-linux-i686.tar.gz-C/usr/local/server
[root@localhost]#mv/usr/local/server/mysql-standard-5.0.27-linux-i686/usr/local/server/mysql
[root@localhost]#cd/usr/local/server/mysql
[root@localhost]#./scripts/mysql_install_db--basedir=/usr/local/server/mysql
--datadir=/usr/local/server/mysql/data--user=nobody
[root@localhost]#cp/usr/local/server/mysql/support-files/my-large.cnf
/usr/local/server/mysql/data/my.cnf

2.)修正MySQL设置,增添部分优化参数,以下:
[root@localhost]#vi/usr/local/server/mysql/data/my.cnf

次要内容以下:
[mysqld]
basedir=/usr/local/server/mysql
datadir=/usr/local/server/mysql/data
user=nobody
port=3306
socket=/tmp/mysql.sock
wait_timeout=30
long_query_time=1
#log-queries-not-using-indexes=TRUE
log-slow-queries=/usr/local/server/mysql/slow.log
log-error=/usr/local/server/mysql/error.log
external-locking=FALSE
key_buffer_size=512M
back_log=400
table_cache=512
sort_buffer_size=2M
join_buffer_size=4M
read_buffer_size=2M
read_rnd_buffer_size=4M
myisam_sort_buffer_size=64M
thread_cache_size=32
query_cache_limit=2M
query_cache_size=64M
thread_concurrency=4
thread_stack=128K
tmp_table_size=64M
binlog_cache_size=2M
max_binlog_size=128M
max_binlog_cache_size=512M
max_relay_log_size=128M
bulk_insert_buffer_size=8M
myisam_repair_threads=1
skip-bdb
#假如不必要利用innodb就封闭该选项
#skip-innodb
innodb_data_home_dir=/usr/local/server/mysql/data/
innodb_data_file_path=ibdata1:256M;ibdata2:256M:autoextend
innodb_log_group_home_dir=/usr/local/server/mysql/data/
innodb_log_arch_dir=/usr/local/server/mysql/data/
innodb_buffer_pool_size=512M
innodb_additional_mem_pool_size=8M
innodb_log_file_size=128M
innodb_log_buffer_size=8M
innodb_lock_wait_timeout=50
innodb_flush_log_at_trx_commit=2
innodb_file_io_threads=4
innodb_thread_concurrency=16
innodb_log_files_in_group=3

以上设置参数请依据详细的必要稍作修正。运转以下命令便可启动MySQL服务器:
/usr/local/server/mysql/bin/mysqld_safe
--defaults-file=/usr/local/server/mysql/data/my.cnf&

因为MySQL不是安装在尺度目次下,因而必需要修正mysqld_safe中的my_print_defaults文件地点地位,才干经由过程
mysqld_safe来启动MySQL服务器。
3.)memcache+libevent安装编译安装:
[root@localhost]#cdlibevent-1.2a
[root@localhost]#./configure--prefix=/usr/&&make&&makeinstall
[root@localhost]#cd../memcached-1.2.0
[root@localhost]#./configure--prefix=/usr/local/server/memcached--with-libevent=/usr/
[root@localhost]#make&&makeinstall

备注:假如libevent不是安装在/usr目次下,那末必要把libevent-1.2a.so.1拷贝/链接到/usr/lib中,不然
memcached没法一般加载。运转以下命令来启动memcached:
[root@localhost]#/usr/local/server/memcached/bin/memcached
-l192.168.8.1-d-p10000-unobody-m128

暗示用daemon的体例启动memcached,监听在192.168.8.1的10000端口上,运转用户为nobody,为其分派
128MB的内存。

4、安装Apache、PHP、eAccelerator、php-memcache



4、)安装Apache、PHP、eAccelerator、php-memcache因为Apache
2下的php静态体例编译非常贫苦,因而在这里接纳静态模块(DSO)体例。1.)安装Apache2.2.3
[root@localhost]#./configure--prefix=/usr/local/server/apache--disable-userdir--disable-actions
--disable-negotiation--disable-autoindex--disable-filter--disable-include--disable-status
--disable-asis--disable-auth--disable-authn-default--disable-authn-file--disable-authz-groupfile
--disable-authz-host--disable-authz-default--disable-authz-user--disable-userdir
--enable-expires--enable-module=so

备注:在这里,作废了一些不用要的模块,假如你必要用到这些模块,那末请往失落部分参数。
2.)安装PHP5.2.0
[root@localhost]#./configure--prefix=/usr/local/server/php--with-mysql
--with-apxs2=/usr/local/server/apache/bin/apxs--with-freetype-dir=/usr/--with-png-dir=/usr/
--with-gd=/usr/--with-jpeg-dir=/usr/--with-zlib--enable-magic-quotes--with-iconv
--without-sqlite--without-pdo-sqlite--with-pdo-mysql--disable-dom--disable-simplexml
--enable-roxen-zts
[root@localhost]#make&&makeinstall

备注:假如不必要gd大概pdo等模块,请自行往失落。
3.)安装eAccelerator-0.9.5
[root@localhost]#cdeAccelerator-0.9.5
[root@localhost]#exportPHP_PREFIX=/usr/local/server/php
[root@localhost]#$PHP_PREFIX/bin/phpize
[root@localhost]#./configure--enable-eaccelerator=shared--with-php-config=$PHP_PREFIX/bin/php-config
[root@localhost]#make&&makeinstall

4.)安装memcache模块
[root@localhost]#cdmemcache-2.1.0
[root@localhost]#exportPHP_PREFIX=/usr/local/server/php
[root@localhost]#$PHP_PREFIX/bin/phpize
[root@localhost]#./configure--enable-eaccelerator=shared--with-php-config=$PHP_PREFIX/bin/php-config
[root@localhost]#make&&makeinstall

5.)修正php.ini设置然后修正php.ini,修正/到场相似以下内容:
extension_dir="/usr/local/server/php/lib/"
extension="eaccelerator.so"
eaccelerator.shm_size="32";设定eaccelerator的共享内存为32MB
eaccelerator.cache_dir="/usr/local/server/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter="*.php"
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="3600"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
eaccelerator.log_file="/usr/local/server/apache/logs/eaccelerator_log"
eaccelerator.allowed_admin_path="/usr/local/server/apache/htdocs/ea_admin"
extension="memcache.so"

在这里,最好是在apache的设置中增添默许文件范例的cache机制,即使用apache的expires模块,新增相似以下几行:
ExpiresActiveOn
ExpiresByTypetext/html"accessplus10minutes"
ExpiresByTypetext/css"accessplus1day"
ExpiresByTypeimage/jpg"access1month"
ExpiresByTypeimage/gif"access1month"
ExpiresByTypeimage/jpg"access1month"
ExpiresByTypeapplication/x-shockwave-Flash"accessplus3day"

这么设置是因为我的这些静态文件一般很少更新,因而我选择的是"access"划定规矩,假如更新绝对对照频仍,能够改用"modification"划定规矩;大概也能够用"access"划定规矩,可是在文件更新的时分,实行一下"touch"命令,把文件的工夫革新一下便可。



5、安装Squid



5、)安装Squid
[root@localhost]#./configure--prefix=/usr/local/server/squid--enable-async-io=100--disable-delay-pools--disable-mem-gen-trace--disable-useragent-log--enable-kill-parent-hack--disable-arp-acl--enable-epoll--disable-ident-lookups--enable-snmp--enable-large-cache-files--with-large-files
[root@localhost]#make&&makeinstall

或利用以下安装办法:
[root@localhost]#yuminstallsquid

假如是2.6的内核,才干撑持epoll的IO形式,旧版本的内核则只能选择poll或其他形式了;别的,记得带上撑持年夜文件的选项,不然在access
log等文件到达2G的时分就会报错。设定squid的设置也许以下内容:
#设定缓存目次为/var/cache1和/var/lib/squid,每次处置缓存巨细为128MB,当缓存空间利用到达95%时
#新的内容将代替旧的而不间接增加到目次中,直到空间又下落到90%才中断这一举动
#/var/cache1最年夜1024MB,/var/lib/squid最年夜5000MB,都是16*256级子目次
cache_diraufs/var/cache1102416256
cache_diraufs/var/lib/squid500016256
cache_mem128MB
cache_swap_low90
cache_swap_high95
#设置存储战略等
maximum_object_size4096KB
minimum_object_size0KB
maximum_object_size_in_memory80KB
ipcache_size1024
ipcache_low90
ipcache_high95
cache_replacement_policylru
memory_replacement_policylru
#设置超时战略
forward_timeout20seconds
connect_timeout15seconds
read_timeout3minutes
request_timeout1minutes
persistent_request_timeout15seconds
client_lifetime15minutes
shutdown_lifetime5seconds
negative_ttl10seconds
#限定一个ip最年夜只能有16个毗连
aclOverConnLimitmaxconn16
http_accessdenyOverConnLimit
#限定baiduspider会见
#aclAntiBaidureq_headerUser-AgentBaiduspider
#http_accessdenyAntiBaidu
#惯例设置
visible_hostnamecache.yejr.com
cache_mgr1638651355@qq.comclient_persistent_connectionsoff
server_persistent_connectionson
cache_effective_usernobody
cache_effective_groupnobody
tcp_recv_bufsize65535bytes
half_closed_clientsoff
#设定不缓存的划定规矩
hierarchy_stoplistcgi-bin
aclQUERYurlpath_regexcgi-bin
cachedenyQUERY
#不要信任ETag由于有gzip
aclapacherep_headerServer^Apache
broken_vary_encodingallowapache
#设置accesslog,而且令其格局和apache的格局一样,便利awstats剖析
emulate_httpd_logon
logformatapache%>a%ui%un[%tl]"%rm%ruHTTP/%rv"%Hs%

初始化和启动squid
[root@localhost]#/usr/local/server/squid/sbin/squid-z
[root@localhost]#/usr/local/server/squid/sbin/squid

第一条命令是先初始化squid缓存哈希子目次,只需实行一次便可。

6、跋文


6、跋文1、)想要启用squid所需的改动想要更好的使用squid的cache功效,不是把它启用了就能够的,我们必要做以下几个调剂:
1、启用apache的mod_expires模块,修正httpd.conf,到场以下内容:
#expiresdefault"modificationplus2weeks"expiresactive
onexpiresbytypetext/html"accessplus10minutes"expiresbytype
image/gif"modificationplus1month"expiresbytypeimage/jpeg"modification
plus1month"expiresbytypeimage/png"modificationplus1
month"expiresbytypetext/css"accessplus1day"expiresbytype
application/x-shockwave-flash"accessplus3day"
以上设置的感化是划定各类范例文件的cache划定规矩,对那些图片/flash等静态文件老是cache起来,可依据各自的必要做得当调剂。
2、修正php.ini设置,以下:
session.cache_limiter=nocache
以上设置的感化是默许作废php中的cache功效,制止不一般的cache发生。
3、修正使用程序比方,有一个php程序页面static.php,它寄存着某些查询数据库后的了局,而且数据更新其实不频仍,因而,我们就能够思索对其cache。只需在static.php中到场相似以下代码:
header(Cache-Control:max-age=86400
,must-revalidate);header(Pragma:);header(Last-Modified:.
gmdate(D,dMYH:i:s).GMT);header("Expires:".gmdate(D,dMY
H:i:s,time()+86400).GMT);
以上代码的意义是,输入一个http头部信息,让squid晓得本页面默许缓存时长为一天。
2、)squidclient扼要先容
*获得squid运转形态信息:squidclient-p80mgr:info
*获得squid内存利用情形:squidclient-p80mgr:mem
*获得squid已缓存的列表:squidclient-p80mgr:objects.useitcarefully,itmaycrash
*获得squid的磁盘利用情形:squidclient-p80mgr:diskd
*强迫更新某个url:squidclient-p80-mPURGEhttp://www.360mini.com/static.php
*更多的请检察:squidclient-h大概squidclient-p80mgr:
按照它们在系统中的作用分成几个部分介绍给大家,通过这些基础命令的学习我们可以进一步理解Linux系统:
灵魂腐蚀 该用户已被删除
沙发
发表于 2015-1-16 18:07:08 | 只看该作者

linux教程之nginx+apache+mysql+php+memcached+squid搭建集群web情况

学习Linux半年了~个人认为不会的多在网上找资料网上有很多资料可以搜索到,LS那位说放手去搞。
兰色精灵 该用户已被删除
板凳
发表于 2015-1-18 20:32:11 | 只看该作者
放手去搞。尽量不要提问,运用搜索找答案,或者看wiki,从原理上理解操作系统的本质,而不是满足于使用几个技巧。尽量看英文资料。
活着的死人 该用户已被删除
地板
发表于 2015-1-27 20:48:44 | 只看该作者
这也正是有别的OS得以存在的原因,每个系统都有其自身的优点。?
再见西城 该用户已被删除
5#
发表于 2015-2-5 15:10:53 | 只看该作者
应对Linux的发展历史和特点有所了解,Linux是抢占式多任务多用户操作系统,Linux最大的优点在于其作为服务器的强大功能,同时支持多种应用程序及开发工具。
精灵巫婆 该用户已被删除
6#
发表于 2015-2-12 14:58:48 | 只看该作者
在学习linux的工程中,linux学习方法有很多种,这里是小编的学习心得,给大家拿出来分享一下。
老尸 该用户已被删除
7#
发表于 2015-3-3 03:52:00 | 只看该作者
任何人都可以根据自己的喜好来定制适合自己的操作系统,Linux?是抢占式多任务多用户操作系统.
小女巫 该用户已被删除
8#
发表于 2015-3-11 09:52:33 | 只看该作者
如果上面的措施没有解决问题,此时你就需要Linux社区的帮助了。 Linux的使用者一般都是专业人士,他们有着很好的电脑背景且愿意协助他人。
爱飞 该用户已被删除
9#
发表于 2015-3-18 09:26:39 | 只看该作者
在学习的过程中,我们用的是VM虚拟机,开始时真的不真的该怎么去做,特别是我的是命令窗口界面,别人的是图形界面,我都不知道怎么调过来。
不帅 该用户已被删除
10#
发表于 2015-3-25 21:41:06 | 只看该作者
掌握在Linux系统中安装软件,在安装Linux工具盘后大致日常所需的软件都会有,一般网络提供下载的软件都会有安装说明。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-16 10:17

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表