灌溉梦想,记录脚步

双线机房配置IIS 6.0的HTTP压缩节省带宽

现在双线机房托管服务器,普遍带宽小,价格贵,采用http压缩可以有效节省带宽。
HTTP 压缩的好处:

静态网页采用HTTP 压缩,大约可以减少20%的传输量。
用户端使用IE 5.0浏览器连线到已经启用HTTP压缩IIS 5.0之Web伺服器,才有HTTP压缩功能。如今,绝大多数的现代浏览器支持压缩技术,但是,具体的压缩方式取决于浏览器。不过你无需对此担心,因为只有浏览器指示支持一种压缩方式时,Web服务器才会发送压缩内容。尽管如此,了解一下这种处理机制和不同浏览器支持的压缩类型也是一件有意义的事。

浏览器在要求一个网址时,会把支持的压缩格式通过Accept-Encoding的HTTP头提交给服务器,IIS或其它Web服务器则从HTTP_ACCEPT_ENCODING环境变量读取这个信息,这个过程无需你人为干预,IIS在浏览器支持压缩的情况下会自动对发送的内容进行合适的编码。

下表列出了常见的浏览器和它们支持的编码类型:

浏览器 支持的编码
Firefox 1.0, Mozilla 1.x, Camino gzip, deflate
OmniWeb 5.x bzip2, gzip, deflate
Safari gzip, deflate
Internet Explorer gzip, deflate

使用 HTTP 压缩:

如果您的站点使用了很大的带宽,或者您希望更加有效地使用带宽,请考虑启用 HTTP 压缩。HTTP 压缩在启用压缩的浏览器和 IIS 之间提供了更短的传输时间。既可以只压缩静态文件,又可以同时压缩静态文件和应用程序响应。如果网络带宽受到限制,使用 HTTP 压缩会很有用(至少对于静态文件来说),除非处理器利用率已经很高。

动态处理会影响 CPU 资源。对动态响应启用压缩后,每次请求动态响应时都会进行压缩。这意味着并不缓存动态响应,每次请求动态响应时,服务器可能需要更多的 CPU 周期来压缩和发送响应。已压缩的静态响应可以被缓存,因此不会像动态响应那样影响 CPU 资源。

HTTP 压缩的工作原理:

IIS 在接收到请求时,将检查浏览器是否允许压缩。然后 IIS 会检查文件扩展名,以确定请求的文件是否为静态文件或包含动态内容。如果文件包含静态内容,IIS 将查看以前是否请求过该文件并且已将该文件以压缩格式存储在临时压缩目录中。如果文件没有以压缩格式存储,IIS 会将未压缩的文件发送到浏览器,并在临时压缩目录中添加此文件的压缩副本。如果文件以压缩格式存储,IIS 会将压缩过的文件发送给浏览器。在浏览器首次请求之前,所有文件都不压缩。

如果文件包含动态内容,IIS 将在生成此响应时进行压缩并将压缩后的响应发送给浏览器。不存储此文件的副本。

压缩静态文件的性能代价较小,而且通常只压缩一次,因为该文件随后被存储在临时压缩目录中。压缩动态生成的文件的代价要高一些,因为它们并不存储,并且每次请求时都必须重新生成。在浏览器上展开文件的代价非常小。压缩文件的下载速度更快,所以对于提高使用有限带宽的网络连接(如调制解调器连接)的所有浏览器的性能特别有好处。

默认情况下,压缩文件的截止日期是 1997 年 1 月 1 日,以防止服务器将缓存的压缩文件副本发送到未启用压缩的浏览器。这也意味着浏览器在下一次用户请求时并不显示文件的缓存副本,而是返回服务器请求新副本。

启用 HTTP 压缩:

如果服务器生成大量的动态内容,则需要考虑压缩造成的额外处理代价是否值得付出。如果 % 处理器时间计数器已经达到或超过 80%,则不建议启用 HTTP 压缩。

测试 HTTP 压缩:

要创建一个基线,请使用系统监视器记录几天内“处理器”对象的 % 处理器时间计数器的值。此计数器有一个总实例以及系统中每个处理器的单独实例。(如果服务器有多个处理器,应该同时观察单个处理器和总的处理器情况,以发现工作量分配不平衡之处)此外,还应该记录“网络接口”对象的发送的字节数/秒计数器。 启用压缩并继续在一段时间内记录这些计数器的值,最好是几天,这样就能得到好的对比依据。 将未压缩时的值和压缩过的值相比较。

现在引入正题,

如何配置 Microsoft Internet Information Server 6.0 实现 HTTP 压缩:

有很多第三方工具可以实现 HTTP 压缩,但都是需要购买的,价格在 100 到 300 美圆不等,如:http://www.port80soft.com/的 HTTPZip,如果不希望额外花钱实现这一功能的话,只好自己辛苦一下,接着看吧:

1.首先备份 IIS 的配置文件,

复制 C:\Windows\system32\inetsrv\metabase.xml 到另外的备份文件夹中.

C:\Windows\system32\inetsrv\metabase.xml 是 IIS 的核心配置文件,该文件的完整性一但被破坏,IIS 将无法正常运行,严重到需要重新安装系统.

2. 在开始菜单中启动 Internet 信息服务(IIS)管理器,右键点击“网站”属性,打开“服务”选项卡,勾选“HTTP 压缩”的两个选项。“临时目录”和“临时目录最大容量”可根据需要自行设置。设置完成后点击确定。

3.右键点击“网站”下方的 “Web服务扩展”,添加一个新的Web服务扩展,扩展名填写为“HTTP Compression”或其他,都可以。“要求的文件”添加:c:\windows\system32\inetsrv\gzip.dll ,并勾选“设置扩展状态为允许”,完成后点击确定。

4.下面的步骤有些复杂,如果没有确定的把握能理解,最好不要尝试,右键点击“Internet 信息服务的”“本地计算机”属性,勾选“允许直接编辑配置数据库”并确定。

5. 在开始菜单中运行 notepad C:\Windows\system32\inetsrv\metabase.xml ,打开metabase.xml 文件,请在任何改动前再次确认该文件已经备份。

6. 搜索并找到 metabase.xml 文件中的 


注意“Compression/deflate”和“Compression/gzip”两个片段都需要修改。动态压缩等级,HcDynamicCompressionLevel 建议设置为“9”

7. 保存并关闭 metabase.xml 文件。

8. 重新启动 IIS 服务,运行“IISReset”或重新启动 WWW 服务。

9. 其他:

如果你的服务器上某一个Web站点不希望启用 IIS 压缩,请运行以下脚本:

cscript. C:\Inetpub\AdminScripts\adsutil.vbs set w3svc/site#/root/DoStaticCompression False
cscript. C:\Inetpub\AdminScripts\adsutil.vbs set w3svc/site#/root/DoDynamicCompression False

如果想增加启用 HTTP 压缩的文件类型,请运行以下脚本:

"" 中为文件扩展名,别忘了把原有的扩展名加上。

静态文件压缩:

CSCRIPT.EXE ADSUTIL.VBS SET W3Svc/Filters/Compression/GZIP/HcFileExtensions "htm" "html" "txt" "doc" "ppt" "xls"

CSCRIPT.EXE ADSUTIL.VBS SET W3Svc/Filters/Compression/DEFLATE/HcFileExtensions "htm" "html" "txt" "doc" "ppt" "xls"

动态文件压缩:

CSCRIPT.EXE ADSUTIL.VBS SET W3Svc/Filters/Compression/GZIP/HcScriptFileExtensions "asp" "aspx" "asmx" "dll" "exe" "php"

CSCRIPT.EXE ADSUTIL.VBS SET W3Svc/Filters/Compression/DEFLATE/HcScriptFileExtensions "asp" "aspx" "asmx" "dll" "exe" "php"

将site#替换为该 Web 站点的 ID。Web 站点的 ID 是什么到“日志记录属性”中看一下日志记录的“日志文件名”前面的路径就知道了。

运行以上脚本前务必备份,运行后再次执行“IISReset”使生效.

现在看一下 HTTP 压缩后的效果吧:

测试 HTTP 压缩效果的工具:

http://www.pipeboost.com/

http://www.seoconsultants.com/tools/compression.asp

各种程序的伪静态规则

顾名思义, 伪静态是相对真实静态来讲的.
  通常我们为了更好的缓解服务器压力,和增强搜索引擎的友好面.都将文章内容生成静态页面.
  但是有的朋友为了实时的显示一些信息.或者还想运用动态脚本解决一些问题.不能用静态的方式来展示网站内容.
  但是这就损失了对搜索引擎的友好面.怎么样在两者之间找个中间方法呢,这就产生了伪静态技术.
  就是展示出来的是以.html一类的静态页面形式,但其实是用ASP一类的动态脚本来处理的.
  我的一个思路是用IIS的404错误处理机制来实现的.这个比rewrite技术要灵活得多.
  首先,设置站点属性-自定意错误
  找到HTTP错误404,然后编辑属性->消息类型选中URL->URL填入“/index.asp”,或您的错误处理页面.
  这样,比如用户或蜘蛛访问http://tech.todo.net.cn/12345.html 时(12345为文章在数据库的ID).由于些页面不存在,所以触发了404错误.转向了index.asp
  在index.asp里加
  CurrDomain=Request.ServerVariables("HTTP_HOST") '当前访问域名
  CurrURL=Replace(Request.ServerVariables("QUERY_STRING"),"404;http://"&CurrDomain&":80","") '当前访问URL
  此时的CurrURL应该是:12345.html .
  这样,就得到用户正在试图访问的页面.然后提取里边的文章ID(应该为:12345),用正则,这里就不多说了.
  然后到数据库里提取出文章内容.输出到页面里,就OK了.
  这样.用户或蜘蛛看到的URL还是他访问的URL.而我们对内容的处理上可以用到了动态技术.这就是我们想要的结果.
  说得简单了一些.但是基本思路就是这样了.
[编辑本段]伪静态的利与弊
  当然犹如一篇文章的作者所说的:"如果流量稍大一些使用伪静态就出现CPU使用超负荷,我的同时在线300多人就挂了,而不使用伪静态的时候同时在线超500人都不挂,我的ISS数是1000。”
  确实是这样的,由于伪静态是用正则判断而不是真实地址,分辨到底显示哪个页面的责任也由直接指定转由CPU来判断了,所以CPU占有量的上升,确实是伪静态最大的弊病。
  我们应该选择伪静态还是真静态?
  1、使用真静态和假静态对SEO来说没有什么区别
  2、使用真静态可能将导致硬盘损坏并将影响论坛性能
  3、使用伪静态将占用一定量的CPU占有率,大量使用将导致CPU超负荷
  4、最重要的一点,我们要静态是为了SEO
  所以:
  1、使用真静态的方法可以直接排除了,因为无论怎么生成,对硬盘来说都是很伤的。
  2、既然真伪静态的效果一样,我们就可以选择伪静态了。
  3、但是伪静态大量使用会照成CPU超负荷。
  4、所以我们只要不大量使用就可以了。
  5、既然静态只是给SEO看的,我们只需要伪静态给SEO就行了,不需要给用户使用。
  6、所以我们只要在专门提供给SEO爬的Archiver中使用伪静态就可以了。
  7、谢谢大家耐心看我写的文章。
  8、有何不解的地方或是有不同的看法欢迎提出。
  关于伪静态和真静态的评论
  真正的静态化和伪静态还是有本质的区别的。为浏览用户处理一个纯粹htm和一个调用多个数据的php在CPU的使用率方面明显前者少。记得原来有个人说html下载硬盘读写频繁,他这么说好像读取数据库不用读写磁盘似的,何况还有一大堆缓存的零散php也是放在硬盘的,这些读取不用磁盘操作么?可笑。
  读取单个htm+图片Flash等附件就可以实现的目的,何苦要读数据库又要读php缓存文件又要重新整合数据输出再+图片Flash等附件这么大费周章呢?CMS首页不需要很多的互动的,论坛那一套不应该拿到这里来用,相反应该更多考虑的是:美观!兼容!信息的直观!性能!还有稳定!

各种程序的伪静态规则

SSH、PUTTY远程LINUX 乱码

vi /etc/sysconfig/i18n
将内容改为
LANG="zh_CN.GB18030"
LANGUAGE="zh_CN.GB18030:zh_CN.GB2312:zh_CN"
SUPPORTED="zh_CN.GB18030:zh_CN:zh:en_US.UTF-8:en_US:en"
SYSFONT="lat0-sun16"
这样中文在SSH,telnet终端就可以正常显示了。
或者改成下面的,正常显示英文。
LANG="en_US.UTF-8"
SUPPORTED="en_US.UTF-8:en_US:en"
SYSFONT="latarcyrheb-sun16

linux对应PPPOE的sh脚本

#!/bin/bash
# 请先输入您的相关参数,不要输入错误了!
EXTIF="ppp0" # 这个是可以连上 Public IP 的网路介面
INIF="eth0" # 内部 LAN 的连接介面;若无请填 ""
INNET="10.0.0.0/8" # 内部 LAN 的网域,若没有内部 LAN 请设定为 ""
export EXTIF INIF INNET
# 第一部份,针对本机的防火墙设定!###########################
# 1. 先设定好核心的网路功能:
echo "1" > /proc/sys/net/ipv4/tcp_syncookies
echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
for i in /proc/sys/net/ipv4/conf/*/rp_filter; do
echo "1" > $i
done
for i in /proc/sys/net/ipv4/conf/*/log_martians; do
echo "1" > $i
done
for i in /proc/sys/net/ipv4/conf/*/accept_source_route; do
echo "0" > $i
done
for i in /proc/sys/net/ipv4/conf/*/accept_redirects; do
echo "0" > $i
done
for i in /proc/sys/net/ipv4/conf/*/send_redirects; do
echo "0" > $i
done
# 2. 清除规则、设定预设政策及开放 lo 与相关的设定值
PATH=/sbin:/usr/sbin:/bin:/usr/bin; export PATH
iptables -F
iptables -X
iptables -Z
iptables -P INPUT Drop
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -m state –state RELATED -j ACCEPT
# 3. 启动额外的防火墙 script 模组
if [ -f /usr/local/virus/iptables/iptables.deny ]; then
sh /usr/local/virus/iptables/iptables.deny
fi
if [ -f /usr/local/virus/iptables/iptables.allow ]; then
sh /usr/local/virus/iptables/iptables.allow
fi
if [ -f /usr/local/virus/httpd-err/iptables.http ]; then
sh /usr/local/virus/httpd-err/iptables.http
fi
iptables -A INPUT -m state –state ESTABLISHED -j ACCEPT
# 4. 允许某些类型的 ICMP 封包进入
AICMP="0 3 3/4 4 11 12 14 16 18"
for tyicmp in $AICMP
do
iptables -A INPUT -i $EXTIF -p icmp –icmp-type $tyicmp -j ACCEPT
done
# 5. 允许某些服务的进入,请依照您自己的环境开启
# iptables -A INPUT -p TCP -i $EXTIF –dport 22 -j ACCEPT # SSH
# iptables -A INPUT -p TCP -i $EXTIF –dport 25 -j ACCEPT # SMTP
# iptables -A INPUT -p UDP -i $EXTIF –sport 53 -j ACCEPT # DNS
# iptables -A INPUT -p TCP -i $EXTIF –sport 53 -j ACCEPT # DNS
# iptables -A INPUT -p TCP -i $EXTIF –dport 80 -j ACCEPT # WWW
# iptables -A INPUT -p TCP -i $EXTIF –dport 110 -j ACCEPT # POP3
# iptables -A INPUT -p TCP -i $EXTIF –dport 443 -j ACCEPT # HTTPS
# 第二部份,针对后端主机的防火墙设定!##############################
# 1. 先载入一些有用的模组
modules="ip_tables iptable_nat ip_nat_ftp ip_nat_irc ip_conntrack
ip_conntrack_ftp ip_conntrack_irc"
for mod in $modules
do
testmod=`lsmod | grep "${mod} "`
if [ "$testmod" == "" ]; then
modprobe $mod
fi
done
# 2. 清除 NAT table 的规则吧!
iptables -F -t nat
iptables -X -t nat
iptables -Z -t nat
iptables -t nat -P PREROUTING ACCEPT
iptables -t nat -P POSTROUTING ACCEPT
iptables -t nat -P OUTPUT ACCEPT
# 3. 开放成为路由器,且为 IP 分享器!
if [ "$INIF" != "" ]; then
/sbin/iptables -A INPUT -i $INIF -j ACCEPT
echo "1" > /proc/sys/net/ipv4/ip_forward
/sbin/iptables -t nat -A POSTROUTING -s $INNET -o $EXTIF -j MASQUERADE
fi
# 如果你的 MSN 一直无法连线,或者是某些网站 OK 某些网站不 OK,
# 可能是 MTU 的问题,那你可以将底下这一行给他取消注解来启动 MTU 限制范围
# iptables -A FORWARD -p tcp -m tcp –tcp-flags SYN,RST SYN -m tcpmss \
# –mss 1400:1536 -j TCPMSS –clamp-mss-to-pmtu
# 4. 内部伺服器的设定:
# iptables -t nat -A PREROUTING -p tcp -i $EXTIF –dport 80 \
# -j DNAT –to 192.168.1.210:80
# Deny All Other Connections
/sbin/iptables -A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT

mysql集群配置

Mysql Cluster: The definitive HOWTO
This guide was written over a year ago and is an excellent introduction however it has not been updated since! If you have any questions please email me or Buy my book (US).

Introduction
You MUST have a third server as a managment node but this can be shut down after the cluster starts. Also note that I do not recommend shutting down the managment server (see the extra notes at the bottom of this document for more information). You can not run a mysql cluster with just two servers And have true redundancy.

You should also disable SELinux or use the following rules (many thanks to Robin Bowes for letting me know of these):

allow mysqld_t port_t:tcp_socket name_connect;
allow mysqld_t var_lib_t:file append;
allow mysqld_t var_lib_t:sock_file create;
allow mysqld_t var_lib_t:file read;
allow mysqld_t var_lib_t:sock_file unlink;
allow mysqld_t var_lib_t:file { getattr write };
Although it is possible to set the cluster up on two physical servers you WILL NOT GET the ability to "kill" one server and for the cluster to continue as normal. For this you need a third server running the managment node.

I am going to talk about three servers,

mysql1.domain.com 192.168.0.1
mysql2.domain.com 192.168.0.2
mysql3.domain.com 192.168.0.3
Servers 1 and 2 will be the two that end up "clustered". This would be perfect for two servers behind a loadbalancer or using round robin DNS and is a good replacement for replication. Server 3 needs to have only minor changes made to it and does NOT require a mysql install. It can be a low-end machine and can be carrying out other tasks.

STAGE 1: Install mysql on the first two servers:
Complete the following steps on both mysql1 and mysql2:

groupadd mysql useradd -g mysql mysql cd /usr/local/ wget http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-max-5.0.15-linux-i686-glibc23.tar.gz /from/http://mirror.trouble-free.net/mysql_mirror/ tar -zxvf mysql-max-5.0.15-linux-i686-glibc23.tar.gz rm mysql-max-5.0.15-linux-i686-glibc23.tar.gz ln -s mysql-max-5.0.15-linux-i686-glibc23 mysql cd mysql scripts/mysql_install_db –user=mysql chown -R root . chown -R mysql data chgrp -R mysql . cp support-files/mysql.server /etc/rc.d/init.d/ chmod +x /etc/rc.d/init.d/mysql.server chkconfig –add mysql.server
Do not start mysql yet.

STAGE 2: Install and configure the managment server
You need the following files from the bin/ of the mysql directory: ndb_mgm and ndb_mgmd. Download the whole mysql-max tarball and extract them from the bin/ directory.

mkdir /usr/src/mysql-mgm cd /usr/src/mysql-mgm http://dev.mysql.com/get/Downloads/MySQL-4.1/mysql-max-5.0.15-pc-linux-gnu-i686.tar.gz/ from/http://www.signal42.com/mirrors/mysql/ tar -zxvf mysql-max-5.0.15-pc-linux-gnu-i686.tar.gz rm mysql-max-5.0.15-pc-linux-gnu-i686.tar.gz cd mysql-max-5.0.15-pc-linux-gnu-i686 mv bin/ndb_mgm . mv bin/ndb_mgmd . chmod +x ndb_mg* mv ndb_mg* /usr/bin/ cd rm -rf /usr/src/mysql-mgm
You now need to set up the config file for this managment:

mkdir /var/lib/mysql-cluster
cd /var/lib/mysql-cluster
vi [or emacs or any other editor] config.ini
Now, insert the following (changing the bits as indicated):

[NDBD DEFAULT]
NoOfReplicas=2
[MYSQLD DEFAULT]
[NDB_MGMD DEFAULT]
[TCP DEFAULT]
# Managment Server
[NDB_MGMD]
# the IP of THIS SERVER
HostName=192.168.0.3
# Storage Engines
[NDBD]
# the IP of the FIRST SERVER (STORAGE NODE)
HostName=192.168.0.1
DataDir= /var/lib/mysql-cluster
[NDBD]
# the IP of the SECOND SERVER (STORAGE NODE)
HostName=192.168.0.2
DataDir=/var/lib/mysql-cluster
# 2 MySQL Clients
# I personally leave this blank to allow rapid changes of the mysql clients;
# you can enter the hostnames of the above two servers here. I suggest you dont.
[MYSQLD]
[MYSQLD]
Now, start the managment server:

ndb_mgmd
This is the mysql managment server, not maganment console. You should therefore not expect any output (we will start the console later).

STAGE 3: Configure the storage/SQL servers and start mysql
On each of the two storage/SQL servers (192.168.0.1 and 192.168.0.2) enter the following (changing the bits as appropriate):

vi /etc/my.cnf
Enter i to go to insert mode again and insert this on both servers (changing the IP address to the IP of the managment server that you set up in stage 2):

[mysqld]
ndbcluster
# the IP of the MANAGMENT (THIRD) SERVER
ndb-connectstring=192.168.0.3
[mysql_cluster]
# the IP of the MANAGMENT (THIRD) SERVER
ndb-connectstring=192.168.0.3
Be aware that anything in the [mysql_cluster] section will override the defaults in [mysql], so if you introduce a nodeid and then try to run multiple daemons on the same machines you should be aware of this!

Now, we make the data directory and start the storage engine:

mkdir /var/lib/mysql-cluster
cd /var/lib/mysql-cluster
/usr/local/mysql/bin/ndbd –initial
/etc/rc.d/init.d/mysql.server start
If you have done one server now go back to the start of stage 3 and repeat exactly the same procedure on the second server.
NOTE that you should ONLY use –initial if you are either starting from scratch or have changed the config.ini file on the managment.

STAGE 4: Check its working
You can now return to the managment server (mysql3) and enter the managment console:

/usr/local/mysql/bin/ndb_mgm
Enter the command SHOW to see what is going on. A sample output looks like this:

[root@mysql3 mysql-cluster]# /usr/local/mysql/bin/ndb_mgm
— NDB Cluster — Management Client —
ndb_mgm> show
Connected to Management Server at: localhost:1186
Cluster Configuration
———————
[ndbd(NDB)] 2 node(s)
id=2 @192.168.0.1 (Version: 5.0.15, Nodegroup: 0, Master)
id=3 @192.168.0.2 (Version: 5.0.15, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.0.3 (Version: 5.0.15)

[mysqld(API)] 2 node(s)
id=4 (Version: 5.0.15)
id=5 (Version: 5.0.15)

ndb_mgm>
If you see

not connected, accepting connect from 192.168.0.[1/2/3]
in the first or last two lines they you have a problem. Please email me with as much detail as you can give and I can try to find out where you have gone wrong and change this HOWTO to fix it.

If you are OK to here it is time to test mysql. On either server mysql1 or mysql2 enter the following commands: Note that we have no root password yet.

mysql
use test;
Create TABLE ctest (i INT) ENGINE=NDBCLUSTER;
Insert INTO ctest () VALUES (1);
Select * FROM ctest;
You should see 1 row returned (with the value 1).

If this works, now go to the other server and run the same Select and see what you get. Insert from that host and go back to host 1 and see if it works. If it works then congratulations.

The final test is to kill one server to see what happens. If you have physical access to the machine simply unplug its network cable and see if the other server keeps on going fine (try the Select query). If you dont have physical access do the following:

ps aux | grep ndbd
You get an output like this:

root 5578 0.0 0.3 6220 1964 ? S 03:14 0:00 ndbd
root 5579 0.0 20.4 492072 102828 ? R 03:14 0:04 ndbd
root 23532 0.0 0.1 3680 684 pts/1 S 07:59 0:00 grep ndbd
In this case ignore the command "grep ndbd" (the last line) but kill the first two processes by issuing the command kill -9 pid pid:

kill -9 5578 5579
Then try the select on the other server. While you are at it run a SHOW command on the managment node to see that the server has died. To restart it, just issue

ndbd
NOTE no

–inital!

——————————————————————————–

Further notes about setup
I strongly recommend that you read all of this (and bookmark this page). It will almost certainly save you a lot of searching.

The Managment Server
I strongly recommend that you do not stop the managment server once it has started. This is for several resons:

The server takes hardly any server resources
If a cluster falls over, you want to be able to just ssh in and type ndbd to stat it. You dont want to have to start messing around with another server
If you want to take backups then you need the managment server up
The cluster log is sent to the management server so to check what is going on in the cluster or has happened since last this is an important tool
All commands from the ndb_mgm client is sent to the management server and thus no management commands without management server.
The managment server is required in case of cluster reconfiguration (crashed server or network split). In the case that it is not running, "split-brain" scenario will occure. The management server arbitration role is required for this type of setup to provide better fault tollerance.
However you are welcome to stop the server if you prefer.

Starting and stopping ndbd automatically on boot
To achieve this, do the following on both mysql1 and mysql2:

echo "ndbd" > /etc/rc.d/init.d/ndbd
chmod +x /etc/rc.d/init.d/ndbd
chkconfig –add ndbd
Note that this is a really quick script. You ought really to write one that at least checks if ndbd is already started on the machine.

Use of hostnames
You will note that I have used IP addresses exclusively throught this setup. This is because using hostnames simply increases the number of things that can go wrong. Mikael Ronström of MySQL AB kindly explains: "Hostnames certainly work with MySQL Cluster. But using hostnames introduces quite a few error sources since a proper DNS lookup system must be set-up, sometimes /etc/hosts must be edited and their might be security blocks ensuring that communication between certain machines is not possible other than on certain ports". I strongly suggest that while testing you use IP addresses if you can, then once it is all working change to hostnames.

RAM
Use the following formula to work out the amount of RAM that you need on each storage node:

(Size of database * NumberofReplicas * 1.1) / Number of storage nodes
NumberofReplicas is set to two by default. You can change it in config.ini if you want. So for example to run a 4GB database with NoOfReplicas set to 2 you need just under 9GB of RAM in total (4 * 2 * 1.1), so if you had two storage nodes you would need 4.5GB ram per storage node. For the SQL nodes and managment nodes you dont need much RAM at all.Bear in mind that if you have variable-width fields in MySQL Cluster 4.0 or 5.0 you will find that you will need a LOT more RAM than this formula predicts.

Note: A lot of people have emailed me querying the maths above! Remember that the cluster is fault tollerant, and each piece of data is stored on at least 2 nodes. (2 by default, as set by NumberOfReplicas). So you need TWICE the space you would need just for one copy, multiplied by 1.1 for overhead.

Adding storage nodes
If you decide to add storage nodes, bear in mind that 3 is not an optimal numbers. If you are going to move from two (above) then move to 4.

Adding SQL nodes
If you want to add another SQL node (i.e. you have another server that you want to add to the cluster but you dont need it to act as a storage node), then just add the following to /etc/my.cnf on the server (it must be a mysql-max server):

[mysqld]
ndbcluster
# the IP of the MANAGMENT (THIRD) SERVER
ndb-connectstring=192.168.0.3
[mysql_cluster]
# the IP of the MANAGMENT (THIRD) SERVER
ndb-connectstring=192.168.0.3
Then you need to make sure that there is another [MYSQLD] line at the end of config.ini on the managment server. Restart the cluster (see below for an important note) and restart mysql on the new API. It should be connected.

Important note on changing config.ini
If you ever change config.ini you must stop the whole cluster and restart it to re-read the config file. Stop the cluster with a SHUTDOWN command to the ndb_mgm package on the managment server and then restart all the storage nodes.

Some useful configuration options that you will need if you have large tables:

DataMemory: defines the space available to store the actual records in the database. The entire DataMemory will be allocated in memory so it is important that the machine contains enough memory to handle the DataMemory size. Note that DataMemory is also used to store ordered indexes. ordered indexes uses about 10 bytes per record. Default: 80MB
IndexMemory The IndexMemory is the parameter that controls the amount of storage used for hash indexes in MySQL Cluster. Hash indexes are always used for primary key indexes, unique indexes, and unique constraints. Default: 18MB
MaxNoOfAttributes This parameter defines the number of attributes that can be defined in the cluster. Default: 1000
MaxNoOfTables Obvious (bear in mind that each BLOB field creates another table for various reasons so take this into account). Default: 128

View this page at mysql.com for further information about the things you can put in the [NDBD] section of config.ini

A note about security
MySQL cluster is not secure. By default anyone can connect to your managment server and shut the whole thing down. I suggest the following precautions:

Install APF and block all ports except those you use (do NOT include any MySQL cluster ports). Add the IPs of your cluster machines to the /etc/apf/allow_hosts file.
Run MySQL cluster over a second network card on a second, isolated, network.
Other resources
I found the following resources very useful:

The MySQL cluster documentation. This is gradually being reworked and is really quite good now.
On-line Backup of MySQL Cluster.
Defining MySQL Cluster Storage Nodes for information that you will need to allow for bigger database memory or a larger number of tables, indexes, unique indexes
MySQL Cluster mailing list.
Google.
MySQL Forums
The #mysql IRC chanel on freenode and EFNet. If you need a free (open source) IRC client I recomment Bersirc.
Thanks
I must thank several others who have contributed to this: Mikael Ronström from MySQL AB for helping me to get this to work and spotting my silly mistake right at the end, Lewis Bergman for proof-reading this page and pointing out some improvements, as well as suffering the frustration with me and Martin Pala for explaining the final reason to keep the managment server up as well as a few other minor changes. Thanks also to Terry from Advanced Network Hosts who paid me to set a cluster up and at the same time produce a HOWTO.

Comments/Corrections
I would be delighted for you to send any corrections or comments you may have to alex@davz.net. If you are also really stuck I would be delighted to help you.

Please do not copy this document; please just link to it. This is simply to prevent yet more old information getting out onto the internet. I will keep this updated. If you want something changed please email me.