Zookeeper 陷阱

1、如何解决session失效问题
Sync(init());
while( register()) {
watch();
sleep();
}
2、为什么zookeeper_init设置recv_timeout较长却没有效果
关注 2 * tickTime ~ 20 * tickTime 的意义
3、zookeeper 日志大小 你控制好了吗?
多大的业务量,决定了多大的日志量。
4、zoo_get_children 内存泄露
int deallocate_String_vector(struct String_vector *v){
if (v->data)
{
int32_t i;
for(i = 0; i < v->count; i++)
{
deallocate_String(&v->data[i]);
}
free(v->data);
v->data = 0;
}
return 0;
}

5、zookeeper 最大链接数问题
正确设置fd limited
设置127.0.0.1;127.0.0.2;127.0.0.3;127.0.0.4;127.0.0.5 链接参数时,每个客户端设置最好不要一样。
最好分成一组一组不同去设置,防止雪崩效应。

文件系统cache

在 Linux 的实现中,文件 Cache 分为两个层面,一是 Page Cache ,另一个 Buffer Cache ,每一个 Page Cache 包含若干 Buffer Cache 。内存管理系统和 VFS 只与 Page Cache 交互,内存管理系统负责维护每项 Page Cache 的分配和回收。buffer cache 是块设备的读写缓冲区,更靠近存储设备,或者直接就是disk 的缓冲区。
磁盘操作有逻辑级(文件系统)和物理级(磁盘块),这两种缓存分别是缓存逻辑和物理级数据的。如我们进行的是文件系统操作,那么文件被缓存到Page Cache ,如需要刷新文件的时候,Page Cache 将交给Buffer Cache 去完成,因为Buffer Cache 是缓存磁盘块的。即直接去操作文件就是使用Page Cache ,用dd 等命令直接操作磁盘块,就是buffer cache 缓存。

The Linux Kernel’s VFS Layer
The Virtual File System (VFS) layer [1] provides a uniform interface for the kernel to deal with various I/O requests and specifies a standard interface that each file system must support. Through this layer, one kernel can mount several different types of file systems (e.g. EXT2FS,ISO9660FS, NFS, …) into the same tree structure. We worked with version 2.2.12 of the Linux kernel and confined our changes to the VFS layer. By doing all of our changes in the VFS layer we kept our predictive prefetching totally independent of the underlying file system.
Arguably, the most important service the VFS layer provides is a uniform I/O data cache. Linux maintains four caches of I/O data: page cache, i-node cache, buffer cache and directory cache. Figure 5 shows these caches and how they interact with the kernel, each other and user level programs. The page cache combines virtual memory and file data. The i-node cache keeps recently accessed file i-nodes. The buffer cache interfaces with block devices, and caches recently used meta-data disk blocks. The Linux kernel reads file data through the buffer cache, but keeps the data in the page cache for reuse on future reads. The directory cache (d-cache) keeps in memory a tree that represents a portion of the file system’s directory structure. This tree maps a file’s path name to an i-node structure and speeds up file path name look up. The basic element of the d-cache is a structure called the d-entry.
We implemented our methods of modeling file access patterns by adding one field to the d-entry structure. The various models would attach their modeling data structure to this pointer. For the last successor model this consisted of just a device and inode number. For the partitioned models this was a pointer to the partition that began with the file that the d-entry identified. After each file access the model would update its predictions. The prefetch engine was then called and would use these predictions to prefetch file data.

Image
Figure: The Linux kernel’s I/O caches.
Image1

tcp checksum offload导致的发送、接收数据不一致问题

线上几千台存储服务器,你会发现总有那么几台硬件有莫名其妙的故障,这次我们就遇到这样的问题:
只要我用xshell ssh上去执行dmesg,就出现SSH sessions terminate abruptly with message: Corrupted MAC on input. Disconnect,百试不爽!我猜想是因为ssh服务出现问题。
同时线上的三副本文件出现了不一致的情况,头一次出现这种情况,猜想与上面这个问题有关,经过问强大google,发现是内存有点问题(可以通过blos自检内存方式)。
通常我们认为tcp 数据传输是可靠的,但是我们忽略了从应用层–网卡缓存的copy的可靠性,默认我们交由网卡进行tcp checksum offload,节省cpu资源,但是这样也带来了从应用层–网卡缓存的copy的数据可靠性问题,比如内存和cpu等硬件故障。

**当然我们在设计协议时可以添加自己的数据检验方式。

Note: 在编写socket程序时,我们在send或write时,通常是在做内存copy动作,应用数据被分割成TCP认为最适合发送的数据块(MTU)。开启tcp checksum offload交由网卡来计算checksum节省cpu计算资源。

linode vps上安装blog

1、因为我选用的操作系统centos,blog选用的WordPress ,话不多说,开始捣鼓,ssh登陆到vps

2、安装所有需要的服务包

yum -y install pcre-devel mysql mysql-server mysql-devel mysql-client  php-mysql

yum -y install lrzsz dstat wget unzip gcc


 

wget http://www.lighttpd.net/download/spawn-fcgi-1.6.3.tar.bz2

zip2 -d spawn-fcgi-1.6.3.tar.bz2 && tar -xvf  spawn-fcgi-1.6.3.tar && cd spawn-fcgi-1.6.3

./configure && make && make install

spawn-fcgi -a 127.0.0.1 -p 53214 -P /var/run/fastcgi-php.pid /usr/bin/php-cgi


 

wget http://nginx.org/download/nginx-1.6.2.tar.gz && tar -xzvf nginx-1.6.2.tar.gz

cd  nginx-1.6.2.tar.gz && ./configure && make && make install

3、启动数据库、创建数据库

service mysqld restart

登陆到msyql 上去以后,创建数据库和账户密码(问google或度娘)

4、下载wordpress,并配置

wget http://cn.wordpress.org/wordpress-4.0-zh_CN.tar.gz

tar -xzvf wordpress-4.0-zh_CN.tar.gz && cp -R wordpress /data/www/blog

cd /data/www/blog

cp wp-example-config.php wp-config.php

vim wp-config.php 进入修改,数据库账户密码、字符集,同时在https://api.wordpress.org/secret-key/1.1/salt/生成身份校验码。

5、修改nginx配置、并启动nginx

server {
listen 80; # your server’s public IP address
server_name dumaba.com www.dumaba.com; # your domain name
root /data/www/blog;
index index.php index.html index.htm

try_files $uri $uri/ /index.php;

location ~ \.php$ {
include fastcgi_params;
fastcgi_pass localhost:53214;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}

启动nginx : /usr/loca/nginx/sbin/nginx

6、去域名管理中心,配置域名解析记录,比如你的域名是:dumaba.com,当然没有就直接vps 公网IP直接访问了。

7、使用浏览器访问http://www.dumaba.com/, 接下来你看到的页面就很容易操作,也很容易明白了。