分页: 1/1 第一页 1 最后页 [ 显示模式: 摘要 | 列表 ]
  [文章作者:张宴 本文版本:v1.0 最后修改:2008.11.30 转载请注明原文链接:http://blog.zyan.cc/post/384/]

  首先,需要了解Memcached协议,如果不清楚可参考《Memcached 协议中英文对照》。

  1、数据存储(假设key为zhangyan,value为12345)
printf "set zhangyan 0 0 5\r\n12345\r\n" | nc 127.0.0.1 11211
 STORED

  2、数据取回(假设key为zhangyan)
printf "get zhangyan\r\n" | nc 127.0.0.1 11211
 VALUE zhangyan 0 5
 12345
 END


  3、数值增加1(假设key为zhangyan,并且value为正整数)
printf "incr zhangyan 1\r\n" | nc 127.0.0.1 11211
 12346
Tags: ,
  [文章作者:张宴 本文版本:v1.0 最后修改:2008.11.28 转载请注明原文链接:http://blog.zyan.cc/post/382/]

  今天在配置Nginx + PHP + MediaWiki中,发现一个问题:MediaWiki所在的Nginx虚拟主机绑定了多个域名,但是不管通过什么域名访问MediaWiki首页,都会被跳转到其中的一个域名上。Nginx配置文件中没有相关的rewrite跳转规则,那么就应该是MediaWiki的PHP程序做的跳转,但是,遍历了MediaWiki目录下的所有文件以及查询了MySQL数据库中的每个表,都没有发现记录有这个域名。后来,通过查看源代码发现MediaWiki是根据$_SERVER['SERVER_NAME']做的跳转,顺藤摸瓜,发现了下列问题:

  在一个Nginx虚拟主机中,可以绑定多个server_name,例如:
  点击在新窗口中浏览此图片

  而server_name的先后顺序的不同,对PHP程序中使用$_SERVER["SERVER_NAME"]或getenv('SERVER_NAME')获取服务器域名是有影响的:
Tags: ,
  High Performance MySQL Second Edition

点击在新窗口中浏览此图片  作者: Baron Schwartz / Peter Zaitsev / Vadim Tkachenko / Jeremy Zawodny / Arjen Lentz / Derek Balling

  副标题: Optimization, Backups, Replication, and More
  ISBN: 9780596101718
  页数: 708
  定价: USD 49.99
  出版社: O'Reilly Media, Inc.
  装帧: Paperback
  出版年: 2008-06-18

  High Performance MySQL is the definitive guide to building fast, reliable systems with MySQL. Written by noted experts with years of real-world experience building very large systems, this book covers every aspect of MySQL performance in detail, and focuses on robustness, security, and data integrity.

  High Performance MySQL teaches you advanced techniques in depth so you can bring out MySQL's full power. Learn how to design schemas, indexes, queries and advanced MySQL features for maximum performance, and get detailed guidance for tuning your MySQL server, operating system, and hardware to their fullest potential. You'll also learn practical, safe, high-performance ways to scale your applications with replication, load balancing, high availability, and failover.

  This second edition is completely revised and greatly expanded, with deeper coverage in all areas. Major additions include:
  * Emphasis throughout on both performance and reliability
  * Thorough coverage of storage engines, including in-depth tuning and optimizations for the InnoDB storage engine
  * Effects of new features in MySQL 5.0 and 5.1, including stored procedures, partitioned databases, triggers, and views
  * A detailed discussion on how to build very large, highly scalable systems with MySQL
  * New options for backups and replication
  * Optimization of advanced querying features, such as full-text searches
  * Four new appendices
  The book also includes chapters on benchmarking, profiling, backups, security, and tools and techniques to help you measure, monitor, and manage your MySQL installations.
Tags:
  [文章作者:张宴 本文版本:v1.0 最后修改:2008.11.20 转载请注明原文链接:http://blog.zyan.cc/post/380/]

  Linux下限制网卡的带宽,可用来模拟服务器带宽耗尽,从而测试服务器在此时的访问效果。

  1、安装iproute
yum -y install iproute


  2、限制eth0网卡的带宽为50kbit:
/sbin/tc qdisc add dev eth0 root tbf rate 50kbit latency 50ms burst 1000


  3、限制带宽为50kbit后,在百兆局域网中wget下载一个大文件:
[root@localhost ~]# wget http://192.168.1.7/test.zip
--19:40:27--  http://192.168.1.7/test.zip
Connecting to 192.168.1.7:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 23862312 (23M) [application/zip]
Saving to: `test.zip'

37% [=======>   ] 8,994,816    457K/s  eta 27s

  下载速度为457K/s,限制效果达到。

  4、解除eth0网卡的带宽限制:
/sbin/tc qdisc del dev eth0 root tbf


  5、对比:未作带宽限制情况下,在百兆局域网中wget下载一个大文件:
[root@localhost ~]# wget http://192.168.1.7/test.zip    
--19:44:33--  http://192.168.1.7/test.zip
Connecting to 192.168.1.7:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 23862312 (23M) [application/zip]
Saving to: `test.zip'

100%[==========>] 23,862,312  6.14M/s   in 3.7s  

19:44:36 (6.16 MB/s) - `test.zip' saved [23862312/23862312]

  下载速度为6.16MB/s。

Tags: , ,
  [文章作者:张宴 本文版本:v1.0 最后修改:2008.11.19 转载请注明原文链接:http://blog.zyan.cc/post/379/]

  在生产应用中,某台“Nginx+PHP+MySQL”接口数据服务器,扮演的角色十分重要,如果服务器硬件或Nginx、MySQL发生故障,而短时间内无法恢复,后果将非常严重。为了避免单点故障,我设计了此套方案,编写了failover.sh脚本,实现了双机互备、全自动切换,故障转移时间只需几十秒。

  一、双机互备、全自动切换方案:
  1、拓扑图:
  点击在新窗口中浏览此图片

  2、解释:
  (1)、假设外网域名blog.zyan.cc解析到外网虚拟IP 72.249.146.214上,内网hosts设置db10对应内网虚拟IP 192.168.146.214

  (2)、默认情况下,由主机绑定内、外网虚拟IP,备机作为备份,当主机的MySQL、Nginx或服务器出现故障无法访问时,备机会自动接管内、外网虚拟IP。两台服务器都启动负责监控、自动切换虚拟IP的守护进程/usr/bin/nohup /bin/sh /usr/local/webserver/failover/failover.sh 2>&1 > /dev/null &

  (3)、主机和备机上的MySQL服务器互为主从,互相同步。在主机处于活动状态(即由主机绑定虚拟IP)时,读写主机的MySQL,写到主机的数据会同步到备机;在备机处于活动状态时,读写备机的MySQL,写到备机的数据会同步到主机(如果主机上的MySQL死掉暂时无法同步,主机上的MySQL恢复后,数据会自动从备机上同步过来,反之亦然)。

  (4)、主机处于活动状态时,每20秒会把/data0/htdocs/(网页、程序、图片存放目录)、/usr/local/webserver/php/etc/(php.ini等配置文件目录)、/usr/local/webserver/nginx/conf/(Nginx配置文件目录)三个目录下的文件通过rsync推送到备机服务器上的对应目录(增量推送,两台服务器上一样的文件不会重复推送),反之如果备机处于活动状态时,每20秒会尝试把文件推送到主机。rsync的配置文件见两台服务器的/etc/rsyncd.conf,rsync守护进程的启动命令为rsync --daemon

  3、自动切换流程
  (1)、主机默认绑定内、外网虚拟IP,当主机的MySQL、Nginx无法访问或服务器宕机,主机上的failover.sh守护进程会自动摘除自己绑定的内、外网虚拟IP(如果主机上的failover.sh死掉,无法摘除自己绑定的虚拟IP也没关系),备机上的failover.sh守护进程会自动接管备机原来绑定的内、外网虚拟IP,并发送ARPing包给内、外网网关更新MAC,强行接管。
Tags: , , , ,
  [文章作者:张宴 本文版本:v1.0 最后修改:2008.11.02 转载请注明原文链接:http://blog.zyan.cc/post/378/]

  早上,一台Linux服务器出故障,SSH连上去后,ls、reboot、shutdown等命令都无法执行。提示:
引用
/bin/bash: ls: Input/output error


  执行echo "test" > test.txt,显示磁盘不能写,我怀疑是磁盘坏了。

  在Google上搜索了一下,发现有人遇到相同的问题,也有人怀疑“you most likely have a failing disc”。

  让机房重启了一下服务器,服务器发出报警声,无法启动。打的到机房一看:这台服务器的一块磁盘闪黄灯报警,在RAID控制面板中显示为FAIL,而另一块硬盘显示的是READY正常状态。看来,果然是硬盘坏掉了。

  点击在新窗口中浏览此图片
分页: 1/1 第一页 1 最后页 [ 显示模式: 摘要 | 列表 ]