默认的情况下,我们平时上网用的本地DNS服务器都是使用电信或者联通的,但是这样也导致了不少的问题,首当其冲的就是上网时经常莫名地弹出广告,或者莫名的流量被消耗掉导致网速变慢。其次是部分网站域名不能正常被解析,莫名其妙地打不开,或者时好时坏。

如果碰上不稳定的本地DNS,还可能经常出现无法解析的情况。除了要避免“坏”的DNS的影响,我们还可以利用DNS做些“好”事,例如管理局域网的DNS、给手机App Store加速、纠正错误的DNS解析记录、保证上网更加安全、去掉网页讨厌的广告等等。

这时候搭建一个属于自己的本地DNS服务器就十分必要了,本篇文章就来分享一下Dnsmasq安装与配置方法,利用Dnsmasq来搭建一个属于自己的本地DNS服务器,享受更干净无污染、更智能快速和没有广告干扰的DNS解析服务。

Dnsmasq安装与配置-搭建本地DNS服务器 享受更干净更快无广告DNS解析

一、Dnsmasq安装

1、执行以下命令在VPS上安装Dnsmasq:


yum install dnsmasq -y 
service dnsmasq start 

one size-full wp-image-38342" data-original="/app/get_remote_pic.php?file=http://img.freehao123.com/wp-content/uploads/2014/08/Dnsmasq_01.gif" alt="Dnsmasq安装" width="500" height="240" />

二、Dnsmasq配置

1、Dnsmasq的配置文件是放在 /etc/dnsmasq.conf 中。

one size-full wp-image-38343" data-original="/app/get_remote_pic.php?file=http://img.freehao123.com/wp-content/uploads/2014/08/Dnsmasq_02.gif" alt="Dnsmasq配置文件" width="500" height="240" />

2、打开编辑,配置:resolv-file=/etc/resolv.dnsmasq.conf,表示dnsmasq 会从这个指定的文件中寻找上游dns服务器。同时取消 strict-order 前面的注册#号。

one size-full wp-image-38344" data-original="/app/get_remote_pic.php?file=http://img.freehao123.com/wp-content/uploads/2014/08/Dnsmasq_03.gif" alt="Dnsmasq去除注释号" width="500" height="240" />

3、检查一下no-hosts前面是不是已经有了#号,默认的情况下是有的,dnsmasq 会首先寻找本地的 hosts 文件再去寻找缓存下来的域名, 最后去上游dns 服务器寻找。

one size-full wp-image-38346" data-original="/app/get_remote_pic.php?file=http://img.freehao123.com/wp-content/uploads/2014/08/Dnsmasq_05.gif" alt="Dnsmasq检查配置" width="500" height="240" />

4、设置:listen-address=127.0.0.1,表示这个 dnsmasq 本机自己使用有效。注意:如果你想让本机所在的局域网的其它电脑也能够使用上Dnsmasq,应该把本机的局域网IP加上去:listen-address=192.168.1.123,127.0.0.1

one size-full wp-image-38347" data-original="/app/get_remote_pic.php?file=http://img.freehao123.com/wp-content/uploads/2014/08/Dnsmasq_06.gif" alt="Dnsmasq局域网IP" width="500" height="240" />

5、修改好了dnsmasq.conf 后,就可以将它重新上传覆盖原文件了。

6、另外我们还需要修改/etc/resolv.conf这个文件,执行以下命令:


echo 'nameserver 127.0.0.1' > /etc/resolv.conf
cp /etc/resolv.conf /etc/resolv.dnsmasq.conf
echo 'nameserver 8.8.8.8' > /etc/resolv.dnsmasq.conf
echo 'nameserver 199.91.73.222' > /etc/resolv.dnsmasq.conf
cp /etc/hosts /etc/dnsmasq.hosts
echo 'addn-hosts=/etc/dnsmasq.hosts' >> /etc/dnsmasq.conf

one size-full wp-image-38345" data-original="/app/get_remote_pic.php?file=http://img.freehao123.com/wp-content/uploads/2014/08/Dnsmasq_04.gif" alt="Dnsmasq添加NS服务器IP" width="500" height="240" />

7、resolv.dnsmasq.conf中设置的是真正的Nameserver,可以用谷歌、V2EX等公共的DNS。

三、Dnsmasq启动

1、执行以下命令设置Dnsmasq开机启动并启动Dnsmasq服务:


chkconfig dnsmasq on
/etc/init.d/dnsmasq restart

one size-full wp-image-38348" data-original="/app/get_remote_pic.php?file=http://img.freehao123.com/wp-content/uploads/2014/08/Dnsmasq_07.gif" alt="Dnsmasq启动服务" width="500" height="240" />

2、执行命令:netstat -tunlp|grep 53 可以查看Dnsmasq是不是已经正常启动:

one size-full wp-image-38350" data-original="/app/get_remote_pic.php?file=http://img.freehao123.com/wp-content/uploads/2014/08/Dnsmasq_08.gif" alt="Dnsmasq检查是否正常启动" width="500" height="240" />

3、测试:dig www.freehao123.com,第一次是没有缓存,所以时间是200多。

one size-full wp-image-38350" data-original="/app/get_remote_pic.php?file=http://img.freehao123.com/wp-content/uploads/2014/08/Dnsmasq_09.gif" alt="Dnsmasq查询时间" width="500" height="240" />

4、第二次再次测试,因为已经有了缓存,所以查询时间已经变成了0.

one size-full wp-image-38351" data-original="/app/get_remote_pic.php?file=http://img.freehao123.com/wp-content/uploads/2014/08/Dnsmasq_10.gif" alt="Dnsmasq缓存生效" width="500" height="240" />

四、Dnsmasq使用

1、本地DNS。将Dnsmasq作为本地DNS服务器使用,直接修改电脑的本地DNS的IP地址即可。

one size-full wp-image-38352" data-original="/app/get_remote_pic.php?file=http://img.freehao123.com/wp-content/uploads/2014/08/Dnsmasq_11.gif" alt="Dnsmasq本地DNS服务器使用" width="500" height="240" />

2、应对ISP的DNS劫持。输入一个不存在的域名,正常的情况下浏览器是显示无法连接,DNS劫持会跳转到一个广告页面。先随便nslookup 一个不存在的域名,看看ISP商劫持的IP地址。

one size-full wp-image-38353" data-original="/app/get_remote_pic.php?file=http://img.freehao123.com/wp-content/uploads/2014/08/Dnsmasq_12.gif" alt="Dnsmasq检查DNS劫持" width="500" height="240" />

3、接着编辑/etc/dnsmasq.conf文件,将:bogus-nxdomain=123.123.123.123 加入进去,后面的IP是刚刚查询到的DNS劫持IP地址。

4、重启dnsmasq,再尝试打开不存在的域名,这时浏览器就会显示正常的无法连接页面了。

one size-full wp-image-38354" data-original="/app/get_remote_pic.php?file=http://img.freehao123.com/wp-content/uploads/2014/08/Dnsmasq_13.gif" alt="Dnsmasq无法显示网页" width="500" height="240" />

5、智能DNS加快解析速度。打开/etc/dnsmasq.conf文件,server=后面可以添加指定的DNS,例如国内外不同的网站使用不同的DNS。


#国内指定DNS
server=/cn/114.114.114.114
server=/taobao.com/114.114.114.114
server=/taobaocdn.com/114.114.114.114
#国外指定DNS
server=/google.com/223.5.5.5

6、server=/cn/表示所有的cn域名都使用114这个公共DNS,server=/taobao.com/表示所有的taobao.com域名都用114,223.5.5.5 是阿里云的公共DNS,你可以换成其它的。

7、屏蔽网页广告。将指广告的URL指定127这个IP,就可以将网页上讨厌的广告给去掉了。


address=/ad.youku.com/127.0.0.1
address=/ad.iqiyi.com/127.0.0.1

8、指定域名解析到特定的IP上。这个功能可以让你控制一些网站的访问,非法的DNS就经常把一些正规的网站解析到不正确IP上。


address=/freehao123.com/123.123.123.123

9、内网DNS。首先将局域网中的所有的设备的本地DNS设置为已经安装Dnsmasq的服务器IP地址。然后修改已经安装Dnsmasq的服务器Hosts文件:/etc/hosts,指定域名到特定的IP中。

10、例如想让局域网中的所有用户访问www.freehao123.com时跳转到192.168.0.2,添加:192.168.0.2 www.freehao123.com在Hosts文件中既可,整个过程也可以说是“DNS劫持”。

五、Dnsmasq小结

1、Dnsmasq作为本地DNS服务器安装方便,操作简单,改动的地方也不是很多,如果用国内的VPS来搭建本地DNS,响应的速度会更快,也更稳定。

2、Dnsmasq的功能强大,反DNS劫持、加快解析速度、屏蔽广告、控制内网DNS、强制域名跳转到特定IP上等这些功能在我们的实际的生活中都是很有用的。

使用方法:
putty左侧分类选择Connection->Data,右侧一目了然。填好账号密码后,可以在Session中保存。现在是明文保存,存在一定风险,请勿保存未做安全措施线上服务器信息。
修改方法:
0. 网上搜索了教程,基本都是针对putty0.6版本的,对于C++水平较弱的人来说,参考教程给的思路,整理了一下方法。大体思路就是利用ssh可以保存用户名的功能扩展成保存密码的功能,基本采用复制username修改为password的方式制作,目前只支持SSH2登录方式,对于大多数linux服务器来讲足够了。

1. 官网下载putty源码 http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
2. 使用VS2012以上C++编译项目
3. 修改config.c文件1952行,增加:

ctrl_editbox(s, "Auto-login password", 'w', 50,
HELPCTX(connection_password),
conf_editbox_handler, I(CONF_password), I(1));

4. 修改putty.h文件712行,增加:
X(STR, NONE, password) \
X(INT, NONE, password_from_env) \

5. 修改winhelp.h文件78行,增加:
#define WINHELP_CTX_connection_password "connection.password:config-password"
#define WINHELP_CTX_connection_password_from_env "connection.passwordfromenv:config-password-from-env"

6. 修改ssh.c文件,搜索Send the password packet
在注释下面增加:
oYeah:;

找到ssh2_pkt_addstring(s->pktout, s->password);
替换s->password为ssh->password

搜索Plain old password authentication.
在下面代码
add_prompt(s->cur_prompt, dupprintf("%s@%s's password: ",
ssh->username,
ssh->savedhost),
FALSE);
的后面增加:
ssh->password = conf_get_str(ssh->conf, CONF_password);
s->password = ssh->password;
if (strlen(ssh->password) == 0) {
ret = get_userpass_input(s->cur_prompt, NULL, 0);
while (ret < 0) {
ssh->send_ok = 1;
crWaitUntilV(!pktin);
ret = get_userpass_input(s->cur_prompt, in, inlen);
ssh->send_ok = 0;
}
}
else {
ret = 1;
goto oYeah;
}

dialog.c

增加

union control *ctrl_editpasswordbox(struct controlset *s, char *label, char shortcut,
int percentage,
intorptr helpctx, handler_fn handler,
intorptr context, intorptr context2)
{
union control *c = ctrl_new(s, CTRL_EDITBOX, helpctx, handler, context);
c->editbox.label = label ? dupstr(label) : NULL;
c->editbox.shortcut = shortcut;
c->editbox.percentwidth = percentage;
c->editbox.password = 1;
c->editbox.has_list = 0;
c->editbox.context2 = context2;
return c;
}

这里的c->editbox.password = 1;说明该文本框为密码类型

.config 引用的地方也要改为对应的函数

ctrl_editpasswordbox(s, "Auto-login password", 'w', 50,
HELPCTX(connection_password),
conf_editbox_handler, I(CONF_password), I(1));

点击下载:putty.0.64

Ext2、Ext3、Ext4、XFS、JFS、ReiserFS 和 Btrfs 的全面性能测试,对比结果如下:

完整表,请看: filesystem.html

one" cellspacing="0">
reclen write rewrite read reread random read random write bkwd read record rewrite stride read fwrite frewrite fread freread
Ext2real 27m23.545s
user 0m9.184s
sys 4m40.925s
4 218,554 218,662 668,245 245,208 85,235 175,284 101,864 1,911,579 74,368 215,014 217,680 583,169 244,831
8 216,064 220,489 618,661 243,444 146,695 215,002 176,908 2,314,305 129,333 215,772 218,571 605,436 241,144
16 218,874 219,173 609,563 242,592 246,442 220,306 292,114 2,438,520 218,357 216,497 219,774 596,211 244,652
32 219,584 217,859 611,712 244,445 372,023 224,151 442,629 2,423,574 334,999 218,829 219,553 606,186 244,346
64 216,320 219,400 622,218 243,761 478,747 227,018 580,960 2,633,117 439,129 215,956 220,166 608,210 243,950
128 219,286 218,318 614,559 243,862 579,724 224,346 690,945 2,467,787 537,440 219,420 218,330 607,326 244,337
256 216,027 220,509 635,633 245,385 614,120 227,099 842,220 2,567,169 614,753 217,744 219,897 617,728 243,780
Ext3real 27m26.675s
user 0m9.323s
sys 6m43.199s
4 215,478 218,294 604,858 246,148 86,758 151,858 102,113 1,618,769 74,979 214,446 218,569 568,659 242,772
8 217,695 218,777 609,377 244,520 148,608 190,313 171,903 1,830,365 128,957 218,752 217,501 603,465 246,861
16 215,683 219,822 643,396 248,815 252,255 202,374 290,681 1,915,488 219,805 216,519 219,033 568,086 243,985
32 219,341 217,364 603,462 245,273 379,512 208,740 435,756 2,069,791 335,303 218,578 219,086 604,572 245,578
64 216,192 220,186 665,646 244,234 481,101 212,185 567,750 2,106,710 442,926 217,075 220,042 618,134 244,870
128 218,503 219,151 616,479 244,711 589,927 212,355 683,943 2,080,136 541,597 219,271 218,514 600,308 244,782
256 217,255 219,213 637,417 248,555 636,309 211,793 839,907 2,125,314 618,958 218,424 218,954 600,894 245,523
Ext4real 26m15.771s
user 0m9.609s
sys 5m36.096s
4 225,586 224,616 532,721 270,174 82,398 180,231 102,935 1,683,476 74,990 224,893 224,186 277,025 584,868
8 226,896 221,965 274,314 629,603 239,913 219,223 156,964 2,026,184 127,553 226,382 227,019 292,566 593,154
16 222,929 229,392 272,022 599,360 390,533 223,951 256,831 2,114,002 212,773 227,728 225,332 602,317 269,289
32 223,703 221,025 566,981 262,980 380,787 227,198 435,774 2,157,610 338,629 226,208 225,816 591,102 268,725
64 222,236 223,813 593,481 268,002 522,365 227,268 582,830 2,216,225 457,252 228,294 223,269 614,376 269,657
128 221,681 222,859 285,304 623,990 915,430 231,380 663,383 2,276,039 573,624 226,616 224,477 583,965 271,159
256 220,129 221,608 279,101 657,815 889,963 232,256 770,220 2,212,083 610,074 225,877 224,642 288,852 603,933
XFSreal 28m43.957s
user 0m9.899s
sys 6m4.268s
4 217,459 214,348 244,600 239,647 78,424 161,673 107,643 1,711,976 74,828 218,638 216,903 227,675 240,492
8 220,514 219,994 241,854 951,125 248,623 207,750 161,175 2,214,681 127,363 218,892 211,613 219,749 240,286
16 220,776 220,740 226,186 242,746 224,486 219,963 318,503 2,480,826 223,664 221,106 221,694 669,693 262,346
32 218,481 216,919 255,232 799,715 593,083 225,213 408,816 2,278,034 337,026 222,153 213,330 226,093 241,351
64 216,921 210,031 228,877 244,161 430,479 225,432 612,872 2,568,460 448,155 224,650 209,745 221,768 239,888
128 216,341 218,284 232,550 242,283 559,400 227,915 768,251 2,545,859 568,945 222,605 216,060 714,911 258,397
256 221,444 220,462 469,309 321,275 757,895 225,641 806,251 2,689,152 609,077 219,703 219,815 226,021 240,108
JFSreal 26m53.990s
user 0m9.096s
sys 4m39.691s
4 196,819 218,121 455,194 258,062 85,910 169,163 142,814 1,949,282 92,246 212,270 217,272 450,996 258,928
8 211,794 215,030 445,452 258,082 147,556 208,623 236,197 2,214,516 159,402 213,076 218,146 451,013 258,767
16 209,028 214,714 455,795 257,989 248,145 218,747 399,935 2,587,176 269,527 214,271 215,626 439,736 258,830
32 210,454 218,204 448,067 258,568 380,325 220,682 591,781 2,379,845 409,061 213,292 217,683 439,114 259,160
64 214,862 215,636 450,430 258,413 487,982 222,660 750,139 2,613,574 522,050 216,365 217,830 444,546 259,553
128 213,152 218,084 449,185 258,775 592,912 148,064 933,583 2,728,229 667,878 219,155 213,461 466,396 262,608
256 213,119 213,514 477,804 258,508 631,376 129,060 1,055,205 2,727,762 717,814 213,771 217,569 463,931 258,291
ReiserFSreal 28m16.075s
user 0m10.134s
sys 7m38.726s
4 208,422 217,932 190,459 223,684 72,142 175,210 99,820 1,726,654 74,081 211,433 216,255 540,847 239,091
8 214,840 218,917 610,592 240,376 146,908 210,703 176,295 2,180,046 128,114 215,368 218,950 580,334 240,261
16 216,886 217,827 651,240 243,800 249,478 219,967 288,457 2,444,958 213,780 217,438 219,510 592,932 239,510
32 214,217 219,178 645,366 240,227 369,030 224,795 434,556 2,372,823 329,006 217,055 217,110 554,072 240,046
64 217,160 219,013 623,512 239,875 470,435 224,619 560,790 2,429,552 421,615 218,043 218,734 587,074 239,802
128 215,163 219,348 624,117 240,364 572,926 226,463 683,686 2,530,721 530,024 215,932 218,157 577,617 240,975
256 217,058 218,839 643,857 240,141 615,875 224,530 825,364 2,631,201 590,909 217,256 218,942 567,422 240,061
Btrfsreal 59m41.974s
user 0m10.382s
sys 18m40.804s
4 214,203 215,879 265,389 280,244 65,367 10,520 16,032 773,644 34,260 94,105 194,357 269,380 268,254
8 218,318 215,978 270,100 275,160 109,687 26,015 40,447 1,366,911 89,489 141,760 214,990 273,446 271,531
16 219,477 215,738 284,876 282,111 178,662 47,881 72,623 1,864,106 150,255 177,508 219,348 264,935 273,140
32 218,835 220,886 281,550 277,054 246,933 130,288 181,774 2,573,279 250,936 204,491 219,736 281,894 268,989
64 216,758 218,890 282,026 275,127 312,803 195,963 299,685 3,270,521 354,200 202,362 220,928 281,331 271,676
128 216,509 220,235 279,353 274,813 368,053 215,445 343,696 3,739,759 414,950 216,029 219,711 276,973 272,569
256 220,333 216,113 277,920 273,271 405,215 215,495 393,731 4,015,851 474,052 213,849 220,372 283,035 277,594
Kbytes/sec

本次测试所使用的 Linux kernel 版本为 2.6.29-rc3,文件系统性能测试工具为 IOzone 3.318。

从 测试结果可以看出,Ext4 的综合性能位居现有文件系统之首,JFS、ReiserFS 在读性能方面亦有不俗表现。Btrfs 的小块数据读写性能与平均水平相差甚远,是导致其本次测试总时间超出平均时间两倍的主要原因。较之其它成熟的文件系统,Btrfs 投入生产系统运作可能尚需时日。

 

 

摘自:http://www.kuqin.com/linux/20090204/34063.html

工具:add_swap.sh
所有执行的脚本都需要root身份来执行,执行方法:以root身执行命令:bash xxx.sh

功能:自动检测系统swap分区大小,交换分区大小不合理则自动新增并挂载上
适用系统版本:兼容线上所有linux版本
执行方法:以root身执行命令:bash add_swap.sh
解决了什么问题:一键式检测系统swap分区大小,如果低于物理内存的2倍则自动创建一个物理内存2倍大小的swap分区
备注:swap不是越大越好,由于磁盘速度相对于内存较为低下,所以大swap反而会造成业务响应更慢,通常为2至2.5倍就好,如果有特殊需求可以更大。
内存为32G以上则不考虑
内存在16G至32G之间,交换分区配置为8G
内存在4G至16G之间,交换分区配置为4G
内存小于4G的则配置交换分区为2G

 

#!/bin/bash
#########################################
#Function:    add a new swap partition
#Usage:       bash add_swap.sh
#Author:      Customer service department
#Company:     Alibaba Cloud Computing
#Version:     2.1
#########################################

check_os_release()
{
  while true
  do
    if cat /proc/version | grep redhat >/dev/null 2>&1
    then
      os_release=redhat
      echo "$os_release"
      break
    fi
    if cat /proc/version | grep centos >/dev/null 2>&1
    then
      os_release=centos
      echo "$os_release"
      break
    fi
    if cat /proc/version | grep ubuntu >/dev/null 2>&1
    then
      os_release=ubuntu
      echo "$os_release"
      break
    fi
    if cat /proc/version | grep -i debian >/dev/null 2>&1
    then
      os_release=debian
      echo "$os_release"
      break
    fi
    break
    done
}

check_memory_and_swap()
{
  mem_count=$(free -m|grep Mem|awk '{print $2}')
  swap_count=$(free -m|grep Swap|awk '{print $2}')
  if [ "$mem_count" -ge 15000 ]  && [ "$mem_count" -le 32768 ]
  then
    if [ "$swap_count" -ge 8000 ]
    then
      echo -e "\033[1;40;31mYour swap is already enough.Do not need to add swap.Script will exit.\n\033[0m"
      rm -rf $LOCKfile
      exit 1
    elif [ "$swap_count" -ne 0 ]
    then
      echo -e "\033[40;32mYour swap is not enough,need to add swap.\n\033[40;37m"
      remove_old_swap
      create_swap 8192
    else
      echo -e "\033[40;32mYour swap is not enough,need to add swap.\n\033[40;37m"
      create_swap 8192
    fi
  elif [ "$mem_count" -ge 3900 ] && [ "$mem_count" -lt 15000 ]
  then
    if [ "$swap_count" -ge 3900 ]
    then
      echo -e "\033[1;40;31mYour swap is already enough.Do not need to add swap.Script will exit.\n\033[0m"
      rm -rf $LOCKfile
      exit 1
    elif [ "$swap_count" -ne 0 ]
    then
      echo -e "\033[40;32mYour swap is not enough,need to add swap.\n\033[40;37m"
      remove_old_swap
      create_swap 4096
    else
      echo -e "\033[40;32mYour swap is not enough,need to add swap.\n\033[40;37m"
      create_swap 4096
    fi
  else
    if [ "$swap_count" -ge 2000 ]
    then
      echo -e "\033[1;40;31mYour swap is already enough.Do not need to add swap.Script will exit.\n\033[0m"
      rm -rf $LOCKfile
      exit 1
    elif [ "$swap_count" -ne 0 ]
    then
      echo -e "\033[40;32mYour swap is not enough,need to add swap.\n\033[40;37m"
      remove_old_swap
      create_swap 2048
    else
      echo -e "\033[40;32mYour swap is not enough,need to add swap.\n\033[40;37m"
      create_swap 2048
    fi
  fi
}

create_swap()
{
  root_disk_size=$(df -m|grep -w "/"|awk '{print $4}')
  if [ "$1" -gt "$((root_disk_size-1024))" ]
  then
    echo -e "\033[1;40;31mThe root disk partition has no space for $1M swap file.Script will exit.\n\033[0m"
    rm -rf $LOCKfile
    exit 1
  fi
  if [ ! -e $swapfile ]
  then
    dd if=/dev/zero of=$swapfile bs=1M count=$1
    /sbin/mkswap $swapfile
    /sbin/swapon $swapfile
    /sbin/swapon -s
    echo -e "\033[40;32mStep 3.Add swap partition successful.\n\033[40;37m"
  else
    echo -e "\033[1;40;31mThe /var/swap_file already exists.Will exit.\n\033[0m"
    rm -rf $LOCKfile
    exit 1
  fi
}

remove_old_swap()
{
  old_swap_file=$(grep swap $fstab|grep -v "#"|awk '{print $1}')
  swapoff $old_swap_file
  cp -f $fstab ${fstab}_bak
  sed -i '/swap/d' $fstab
}

config_rhel_fstab()
{
  if ! grep $swapfile $fstab >/dev/null 2>&1
  then
    echo -e "\033[40;32mBegin to modify $fstab.\n\033[40;37m"
    echo "$swapfile	 swap	 swap defaults 0 0" >>$fstab
  else
    echo -e "\033[1;40;31m/etc/fstab is already configured.\n\033[0m"
    rm -rf $LOCKfile
    exit 1
  fi
}

config_debian_fstab()
{
  if ! grep $swapfile $fstab >/dev/null 2>&1
  then
    echo -e "\033[40;32mBegin to modify $fstab.\n\033[40;37m"
    echo "$swapfile	 none	 swap sw 0 0" >>$fstab
  else
    echo -e "\033[1;40;31m/etc/fstab is already configured.\n\033[0m"
    rm -rf $LOCKfile
    exit 1
  fi
}

##########start######################
#check lock file ,one time only let the script run one time 
LOCKfile=/tmp/.$(basename $0)
if [ -f "$LOCKfile" ]
then
  echo -e "\033[1;40;31mThe script is already exist,please next time to run this script.\n\033[0m"
  exit
else
  echo -e "\033[40;32mStep 1.No lock file,begin to create lock file and continue.\n\033[40;37m"
  touch $LOCKfile
fi

#check user
if [ $(id -u) != "0" ]
then
  echo -e "\033[1;40;31mError: You must be root to run this script, please use root to install this script.\n\033[0m"
  rm -rf $LOCKfile
  exit 1
fi

os_release=$(check_os_release)
if [ "X$os_release" == "X" ]
then
  echo -e "\033[1;40;31mThe OS does not identify,So this script is not executede.\n\033[0m"
  rm -rf $LOCKfile
  exit 0
else
  echo -e "\033[40;32mStep 2.Check this OS type.\n\033[40;37m"
  echo -e "\033[40;32mThis OS is $os_release.\n\033[40;37m"
fi

swapfile=/var/swap_file
fstab=/etc/fstab

echo -e "\033[40;32mStep 3.Check the memory and swap.\n\033[40;37m"
check_memory_and_swap

echo -e "\033[40;32mStep 4.Begin to modify $fstab.\n\033[40;37m"
case "$os_release" in
redhat|centos)
  config_rhel_fstab
  ;;
ubuntu|debian)
  config_debian_fstab
  ;;
esac

free -m
echo -e "\033[40;32mAll the operations were completed.\n\033[40;37m"
rm -rf $LOCKfile

下载建立SWAP分区脚本

转:http://blog.jobbole.com/48769/

一些我更愿意在开始就知道东西

利用 Node.js 开发是一个非常有趣,和令人满足的过程, 它有3万多个模块可以选择使用,并且所有的模块可以非常容易的集成入现有的应用之中。

无论如何,对于一些刚开始使用Node.js 开发的的人来说, 很容易碰壁,在这个文章中,我会提到在你学习过程中遇到的问题。

贴士 1: 在开发环境使用 nodemon, 在生产环境使用pm2

当你第一次开发Node.js应用的时候, 其中一件事情就是一次又一次的运行[file].js 就和揭伤疤一样。 当我第一次开发的node app时候,这个让我感到异常挫败和痛苦, 尤其是每当我修改很小东西的时候需要control+c

幸运的是我发现了一个非常棒的工具Nodemon。 你可以利用以下的命令来安装

1
npm install -g nodemon

Nodemon 是一个令人惊叹的工具, 当你全局安装它以后, 可以通过 nodemon [file].js 来启动你的node.js scripts,它会告诉nodemon来监视你的script和scripts的所有变化, 这样的Node.js开发方式非常震撼以及让大大提高开发速度。

那么,生产环境又如何, 除非你用了herokuNodejitsu或者其它一些好的 Node.js 平台(也许它们有类似的功能), 但是碰巧你用了EC2 或者一些其它的云平台来运行你的Node.js app, 你如何能然保证这是一个始终运行的Node.js app

案就是PM2, PM2 是一个类似于Nodemon的工具,不同之处在于它用于生产环境, 和Nodemon相似的地方在于它会监控你的app的任何修改或者重新部署,但是有更好的一面, PM2 在遭遇到崩溃的时候,它会正确重启你的app。

PM2的优胜之处在于当你要将app需要多核处理的时候,PM2内部集成的负载均衡可以让你很容易的去指定运行多少个实例。

1
pm2 start app.js -i max

-i参数目的是指定运行多少个实例,在这个例子中 PM2 使用了一个常量max来扩展你的app运转到你最大的核数,不要忘记Node 平时只会运行在单核!

http://www.nodebeginner.org/index-zh-cn.html

Node入门

作者: Manuel Kiessling
翻译: goddyzhao & GrayZhang & MondayChen

关于

本书致力于教会你如何用Node.js来开发应用,过程中会传授你所有所需的“高级”JavaScript知识。本书绝不是一本“Hello World”的教程。

状态

你正在阅读的已经是本书的最终版。因此,只有当进行错误更正以及针对新版本Node.js的改动进行对应的修正时,才会进行更新。

本书中的代码案例都在Node.js 0.6.11版本中测试过,可以正确工作。

苹果于1月11日下发运营商更新,已经完美支持港行5S使用移动3G和4G不需要破解。

------------------------------------------

one.com/read-htm-tid-7463171.html">http://bbs.weiphone.com/read-htm-tid-7463171.html

 

12/30更新:根据私信我的朋友,请务必确定国行的已经换了4G卡,国行用户只能实现4G和4G的随意开关还有热点分享,请不要再问我出不出3G了,你们进行完我说的两步以后就能随意控制LTE的开启和关闭了。还有第二步结束后不能上网的,请按步骤来,我昨天的更新就说了不要直接替换,要把之前的删除后再粘贴。根据帖子下的FY回馈,大部分都是可以按我的教程成功的,有失败的请仔细按我的步骤来不要出错,步骤也就两步,很方便的。12/29 11:11更新补充:对于弄完后有LTE标志却没有网络的,这种情况是你没按步骤来(要删除子文件而不是图方便直接覆盖!)要4G网的请务必确定自己的是4G卡,还有认为解决名字不显示要装app的,这个app装完一键+86后就可卸载了,是一次性永久的,不是一直需要app存在的。
12/28更新补充:3G下也是可以进行facetime和热点开启的,这点大家放心。要4G一定要注意自己家那边有4G信号而且已经换了4G卡!!还有就是我是港版的,国行在理论上是可以破解4G并且可以随意控制4G的开关的(这点就解决了破解4G后的国行同学回不到E网的问题了)通话已经测试,非常完美,尤其是在3G网络下非常好,开启LTE后打电话会自动降到E网,但打完后会自动回跳到3G然后再回跳到4G。                                                                                                                                                       现在所有替换中最最完美的!没有之一!尤其是对于使用4G的同学,能完美4G。成功实现4G以及3G上网,关闭4G开关后默认3G(3G网络不好的情况下会自动切回E)其实相信使用惯了3G和4G的同学会根本受不了E网的慢速。
成功实现热点开启。
实现Facetime以及imessage。
不足:通话记录中不能显示姓名,解决方法就是下载一个“号码助手”的app进行添加国家码,如果提示你要开启通讯录,到设置--隐私--通讯录中打开即可。对于还有一种能解决短号号码显示问题的,可以参考one.com/forum.php?mod=viewthread&tid=7466007&page=1#pid108812633" target="_blank">http://bbs.weiphone.com/forum.ph ... page=1#pid108812633感谢作者!

URL:oneasiahost.com" href="http://www.oneasiahost.com/billing/aff.php?aff=232" target="_blank">http://www.oneasiahost.com/

oneasiahost-%e9%92%88%e5%af%b9%e5%9b%bd%e5%86%85%e6%9c%89%e4%bc%98%e5%8c%96%ef%bc%8c%e9%80%9f%e5%ba%a6%e5%be%88%e5%bf%ab.html/qq%e6%88%aa%e5%9b%be20130819153639" rel="attachment wp-att-443">QQ截图20130819153639

 

现在只有OpenVZ主机,SSD少量到货。最低只要$12/年,注意不要选用Core VPS,这个是没有中国线路的。商家还很贴心的用中文写了“中国客户注意 - CORE VPS 没有直接的中国网络, 通过美国. Ping 400ms+ 连接中国速度慢, 较适合在中国以外的地区或需要使用高頻寬的用户”

可以安装PPTPD VPN,访问谷歌、youtube、twitter、非死不可(facebook)嗖嗖的。

------------20131210-----------

要开启 TUN/TAP和PPP

QQ截图20131209151832

CentOS默认是不支持Ext4.所以你需要处理一下才行。

使用环境使用的是CentOS5.8 内核是  2.6.18-238.19.1.el5

其实CentOS 5.8 里面是有 ext4 模块的,只是没加载,所以我们先把模块加入系统

# cd /lib/modules/2.6.18-238.19.1.el5/kernel/fs/ext4   //ext4模块就在此目录下

# [root@linux ext4]# ls

ext4.ko

找到模块后使用modprobe 命令添加

# modprobe ext4    //注意:这里只能写模块名,不能写成 ext4.ko

# lsmod |grep ext4  //添加完后使用lsmod 查看

ext4                  285409  0

jbd2                   47744  1 ext4

crc16                   1027  1 ext4

[root@linux ext4]# yum install e4fsprogs     //最后使用yum 安装一下 e4fsprogs

[root@linux ext4]# mkfs.ext4 /dev/sdc    //最后创建一个分区来使用ext4 创建文件系统

mke4fs 1.41.12 (17-May-2010)
/dev/sdi is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
61014016 inodes, 244056064 blocks
12202803 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
7448 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
        102400000, 214990848
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first.  Use tune4fs -c or -i to override.
[root@linux ext4]#mount /dev/sdc /hadoop1 

one.com/2012-12-03/3D_Virtual_Edition_Mario_video_love_540064.shtml">最有爱的3D实景版马里奥视频

来源于威锋网

one.com/2012-12-03/3D_Virtual_Edition_Mario_video_love_540064.shtml">http://tech.weiphone.com/2012-12-03/3D_Virtual_Edition_Mario_video_love_540064.shtml

one.com/attachments/Day_121203/0_2000434_97e588c4b54c746.jpg">one.com/attachments/Day_121203/0_2000434_97e588c4b54c746.jpg" alt="" />

        马里奥游戏大家自然是再熟悉不过了,水管、蘑菇、乌龟壳和跳上跳下的高低平台都是我们童年到年长的记忆。但是你想象过当马里奥来到现实世界里是什么情景吗?来看看一位国外网友发表的现实场景版马里奥冒险视频,绝对原汁原味,超乎你的想象。

oneplayer1_wrapper" style="position: relative; width: 600px; height: 400px;">oneplayer1" name="weiphoneplayer1" width="100%" height="100%" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0">one.com%2F2012-12-03%2F3D_Virtual_Edition_Mario_video_love_540064.shtml&id=weiphoneplayer1&file=http%3A%2F%2Fmp4.weiphone.com%2F%2Fattachments%2FDay_121203%2F0_2000434_edc1e9200bd833e.mp4&skin=http%3A%2F%2Fbbs.weiphone.com%2Fweplayer%2Fglow.zip&controlbar.position=over" />one.com/weplayer/weplayer.swf" />oneplayer1" width="100%" height="100%" type="application/x-shockwave-flash" data-original="http://bbs.weiphone.com/weplayer/weplayer.swf" allowfullscreen="allowfullscreen" allowscriptaccess="always" seamlesstabbing="true" wmode="opaque" flashvars="netstreambasepath=http%3A%2F%2Ftech.weiphone.com%2F2012-12-03%2F3D_Virtual_Edition_Mario_video_love_540064.shtml&id=weiphoneplayer1&file=http%3A%2F%2Fmp4.weiphone.com%2F%2Fattachments%2FDay_121203%2F0_2000434_edc1e9200bd833e.mp4&skin=http%3A%2F%2Fbbs.weiphone.com%2Fweplayer%2Fglow.zip&controlbar.position=over" name="weiphoneplayer1" bgcolor="#000000" />

这部有爱的小短片里,马里奥世界和现实世界互相穿越到了一起,在我们日常的超市、厨房、书房、大街上、小花园里,看看马里奥大叔是如何以惊人适应力淡定地穿梭在现实世界中。然后视角一转,他竟然在房间里和路易、蘑菇头他们来了一把现实版的马里奥赛车,赛道还是用 SFC 卡带摆出来的,作者你晒够了没有!

马里奥和库巴大 Boss 的决斗在一辆行驶的汽车上进行,搞笑的是最后他用卡带机弹卡的卑鄙招式把库巴打飞了。视频全程充满各种笑点,但是又极具创意,毫无违和感,看得出做视频的一定是位高端任饭。这款游戏曾带给我们的欢乐已经无法说清,如今玩家们也在以不同的方式将这些欢乐再次传递和反馈,真的很可爱。