Skip to content


万人在线论坛,系统优化

原先有tcp超时现像(WGET 十几次后会有超时),插拨网线并重启后已恢复正常。

目前一小时近2W人在线,留下些操作记录

系统信息

dell R410 5504(4核2G) 2 4G2 sas15K 146*2 Intel(R) Xeon(R) CPU E5504 @ 2.00GHz

centos 5.2 64bit nginx+php+mysql

nginx 6个进程 php 96个进程

Linux bora 2.6.18-128.el5 #1 SMP Wed Jan 21 10:41:14 EST 2009 x86_64 x86_64 x86_64 GNU/Linux

sysctl内核 net.ipv4.tcp_max_syn_backlog = 65536 net.core.netdev_max_backlog = 32768 net.core.somaxconn = 32768

net.core.wmem_default = 8388608 net.core.rmem_default = 8388608 net.core.rmem_max = 16777216 net.core.wmem_max = 16777216

net.ipv4.tcp_timestamps = 0 net.ipv4.tcp_synack_retries = 2 net.ipv4.tcp_syn_retries = 2

net.ipv4.tcp_tw_recycle = 1 #net.ipv4.tcp_tw_len = 1 net.ipv4.tcp_tw_reuse = 1

net.ipv4.tcp_mem = 94500000 915000000 927000000 net.ipv4.tcp_max_orphans = 3276800

#net.ipv4.tcp_fin_timeout = 30 #net.ipv4.tcp_keepalive_time = 120 net.ipv4.ip_local_port_range = 1024 65535

优化文件句柄 vi /etc/security/limits.conf

  • soft nofile 51200
  • hard nofile 51200

vi /etc/rc.local ulimit -SHn 51200

=================== Active connections: 2419 server accepts handled requests 73668795 73668795 232420556 Reading: 11 Writing: 28 Waiting: 2380

在线会员 – 总计 13433 人在线

top – 13:29:01 up 33 days, 22:53, 2 users, load average: 1.22, 1.60, Tasks: 265 total, 1 running, 264 sleeping, 0 stopped, 0 zombie Cpu(s): 9.3%us, 1.4%sy, 0.0%ni, 88.2%id, 0.5%wa, 0.0%hi, 0.6%si, Mem: 8168412k total, 6691148k used, 1477264k free, 917728k buffe Swap: 4096532k total, 228k used, 4096304k free, 3841696k cache

netstat -n | awk ‘/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}’ TIME_WAIT 4845 SYN_SENT 1 FIN_WAIT1 185 ESTABLISHED 2698 FIN_WAIT2 381 SYN_RECV 162 CLOSING 5 LAST_ACK 137

netstat -n |wc -l 8441

修改tcp_no_metrics_save 默认情况下一个tcp连接关闭后,把这个连接曾经有的参数比如慢启动门限snd_sthresh,拥塞窗口snd_cwnd 还有srtt等信息保存到dst_entry中, 只要dst_entry 没有失效,下次新建立相同连接的时候就可以使用保存的参数来初始化这个连接.通常情况下是关闭的。

echo ‘1’ > /proc/sys/net/ipv4/tcp_no_metrics_save

依然超时

vi /etc/sysctl.conf 增加一行 net.ipv4.tcp_no_metrics_save =1

sysctl -p

开启5分钟后系统负载有小额上升

Active connections: 2520 server accepts handled requests 73715479 73715479 232593589 Reading: 11 Writing: 14 Waiting: 2495

top – 13:46:30 up 33 days, 23:10, 2 users, load average: 1.49, 1.74, 1.64 Tasks: 265 total, 3 running, 262 sleeping, 0 stopped, 0 zombie Cpu(s): 13.8%us, 2.4%sy, 0.0%ni, 82.9%id, 0.1%wa, 0.1%hi, 0.7%si, 0.0 Mem: 8168412k total, 7225928k used, 942484k free, 925236k buffers Swap: 4096532k total, 228k used, 4096304k free, 3893016k cached

vi /etc/sysctl.conf 修改 net.ipv4.tcp_no_metrics_save =0

sysctl -p

5分钟后负载下载,net.ipv4.tcp_no_metrics_save 不是很管用

top – 13:52:18 up 33 days, 23:16, 2 users, load average: 1.18, 1.46, 1.56 Tasks: 265 total, 1 running, 264 sleeping, 0 stopped, 0 zombie Cpu(s): 12.9%us, 2.1%sy, 0.0%ni, 83.5%id, 0.8%wa, 0.1%hi, 0.6%si, 0.0 Mem: 8168412k total, 7274212k used, 894200k free, 927504k buffers Swap: 4096532k total, 228k used, 4096304k free, 3911832k cached

=======================================

cat /proc/sys/net/ipv4/tcp_fin_timeout 60 cat /proc/sys/net/ipv4/tcp_keepalive_time 7200 vi /etc/sysctl.conf

net.ipv4.tcp_fin_timeout = 30 net.ipv4.tcp_keepalive_time = 120

sysctl -p

======================== ifconfig eth0 txqueuelen 1000

看了下已经是1000了 ifconfig

TX packets:1924158031 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:339974963014 (316.6 GiB) TX bytes:2165156209254 (1.9 TiB)

================================ cat /proc/sys/net/ipv4/netfilter/ip_conntrack_max 65536

========================= cat /proc/sys/fs/file-nr 4590 0 765985

======================================= cat /proc/sys/net/ipv4/route/gc_interval 60 cat /proc/sys/net/ipv4/route/gc_timeout 300 cat /proc/sys/net/ipv4/route/gc_elasticity 8

eaccelerator

[eaccelerator] zend_extension=”/opt/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so” eaccelerator.shm_size=”32″ eaccelerator.cache_dir=”/opt/php/eaccelerator_cache” eaccelerator.enable=”1″ eaccelerator.optimizer=”1″ eaccelerator.check_mtime=”1″ eaccelerator.debug=”0″ eaccelerator.filter=”” eaccelerator.shm_max=”0″ eaccelerator.shm_ttl=”3600″ eaccelerator.shm_prune_period=”3600″ eaccelerator.shm_only=”0″ eaccelerator.compress=”1″ eaccelerator.compress_level=”9″

nginx

user www website; worker_processes 6; error_log /var/log/nginx/nginx_error.log crit; pid /dev/shm/nginx.pid; #Specifies the value for maximum file descriptors that can be opened by this process. worker_rlimit_nofile 51200; events { use epoll; worker_connections 51200; } http { include mime.types; default_type application/octet-stream; log_format access ‘$remote_addr – $remote_user [$time_local] “$request” ‘ ‘$status $body_bytes_sent “$http_referer” ‘ ‘”$http_user_agent” $http_x_forwarded_for’; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_body_timeout 60; client_max_body_size 8m; #linux 2.4+ sendfile on; tcp_nopush on; tcp_nodelay on; server_name_in_redirect off; keepalive_timeout 60; fastcgi_intercept_errors on; fastcgi_hide_header X-Powered-By; fastcgi_connect_timeout 180; fastcgi_send_timeout 180; fastcgi_read_timeout 180; fastcgi_buffer_size 128k; fastcgi_buffers 4 128K; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 128k; fastcgi_temp_path /dev/shm; gzip on; gzip_min_length 1k; gzip_comp_level 5; gzip_buffers 4 16k; gzip_http_version 1.1; gzip_types text/plain application/x-javascript text/css application/xml; limit_zone one $binary_remote_addr 10m; server { listen 80; server_name bbs.xxx.com *.bbs.xxx.com; index index.html index.htm index.php; root /opt/lampp/htdocs/bbs; error_page 404 403 /404.html; location ~/\.ht { deny all; } location ~ /bbs/attachment\.php?$ { include fcgi.conf; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; limit_conn one 1; limit_rate 30k; } location ~ .*\.php?$ { #fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fcgi.conf; } rewrite ^(.*)/archiver/((fid|tid)-[\w\-]+\.html)$ $1/archiver/index.php?$2 last; rewrite ^(.*)/forum-([0-9]+)-([0-9]+)\.html$ $1/forumdisplay.php?fid=$2&page=$3 last; rewrite ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/viewthread.php?tid=$2&extra=page\%3D$4&page=$3 last; rewrite ^(.*)/profile-(username|uid)-(.+)\.html$ $1/viewpro.php?$2=$3 last; rewrite ^(.*)/space-(username|uid)-(.+)\.html$ $1/space.php?$2=$3 last; location ~(favicon.ico) { log_not_found off; expires 99d; break; } location ~(robots.txt) { log_not_found off; expires 7d; break; } location ~* ^.+\.(jpg|jpeg|gif|png|swf|rar|zip|css|js)$ { valid_referers none blocked *.xxx.com *.xxx.net localhost; if ($invalid_referer) { rewrite ^/ ; return 412; } access_log off; root /opt/lampp/htdocs/bbs; expires 7d; break; } access_log /var/log/nginx/bbs.xxx.com.log access; } }

================== 总计 18518 人在线

top – 17:40:04 up 5:49, 2 users, load average: 1.81, 2.08, 2.20 Tasks: 265 total, 6 running, 259 sleeping, 0 stopped, 0 zombie Cpu(s): 26.0%us, 3.4%sy, 0.0%ni, 69.0%id, 0.7%wa, 0.0%hi, 0.9%si, Mem: 8168412k total, 7173156k used, 995256k free, 486980k buffe Swap: 4096532k total, 0k used, 4096532k free, 3559140k cache

Active connections: 2306 server accepts handled requests 297904 297904 980053 Reading: 7 Writing: 10 Waiting: 2289

netstat -n|wc -l 8157

sysctl

net.ipv4.ip_forward = 0 net.ipv4.conf.default.rp_filter = 1 net.ipv4.conf.default.accept_source_route = 0 kernel.sysrq = 0 kernel.core_uses_pid = 1 net.ipv4.tcp_syncookies = 1 kernel.msgmnb = 65536 kernel.msgmax = 65536 kernel.shmmax = 68719476736 kernel.shmall = 4294967296 net.ipv4.tcp_max_syn_backlog = 65536 net.core.netdev_max_backlog = 32768 net.core.somaxconn = 32768 net.ipv4.tcp_max_tw_buckets = 10000 net.core.wmem_default = 8388608 net.core.rmem_default = 8388608 net.core.rmem_max = 16777216 net.core.wmem_max = 16777216 net.ipv4.tcp_timestamps = 0 net.ipv4.tcp_synack_retries = 2 net.ipv4.tcp_syn_retries = 2 net.ipv4.tcp_tw_recycle = 1 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_mem = 196608 262144 393216 net.ipv4.tcp_max_orphans = 3276800 net.ipv4.tcp_fin_timeout = 30 net.ipv4.tcp_keepalive_time = 120 net.ipv4.ip_local_port_range = 1024 65535 net.ipv4.tcp_syncookies = 1

=================================== 2009/11/2更新 近日网络有些不稳定,系统日志中有下列信息 tail /var/log/messages

Nov 1 19:37:32 bora kernel: ip_conntrack: table full, dropping packet. Nov 1 19:38:31 bora kernel: ip_conntrack: table full, dropping packet. Nov 1 19:43:15 bora kernel: ip_conntrack: table full, dropping packet. Nov 1 20:38:31 bora kernel: ip_conntrack: table full, dropping packet. Nov 1 20:42:16 bora last message repeated 2 times Nov 1 20:51:42 bora last message repeated 2 times Nov 1 21:23:38 bora last message repeated 3 times Nov 1 21:28:14 bora last message repeated 2 times cat /var/log/messages |grep ‘ip_conntrack: table full’ cat /var/log/messages |grep ‘syslogd 1.4.1: restart’

发现个规律 ip_conntrack: table full信息一般隔5天出现,一天后系统就出现假死,然后需手工重启。 应该就是ip_conntrack的问题

查看当前的参数

cat /proc/sys/net/ipv4/ip_conntrack_max 65536

65536为系统默认1G内存的数值 ip_conntrack_max 计算公式 参考:http://www.wallfire.org/misc/netfilter_conntrack_perf.txt

CONNTRACK_MAX = RAMSIZE (in bytes) / 16384 / (x / 32) #where x is the number of bits in a pointer (for example, 32 or 64 bits)

1G内存的话:102410241024/16384/(32/32)=65536 我的配值为8G 64bit 819210241024/16384/(64/32)=262144

查看RAMSIZE

cat /proc/sys/net/ipv4/netfilter/ip_conntrack_buckets 8192

查看ip_conntrack timeout

cat /proc/sys/net/ipv4/netfilter/ip_conntrack_tcp_timeout_established 432000

#432000(5天)改成36000 (10小时)

vi /etc/sysctl.conf 修改内核在尾部增加两行

net.ipv4.ip_conntrack_max = 262144 net.ipv4.netfilter.ip_conntrack_tcp_timeout_established = 36000

立即生效 sysctl -p

Posted in linux 维护优化, 技术.

Tagged with .


Nginx 修补bug,平滑升级至0.8.16

A patch to fix VU#180065 vulnerability in 0.1.0-0.8.14. The patch is not required for versions 0.8.16+, 0.7.62+, 0.6.39+, 0.5.38+.

nginx有一安全漏洞影响0.1.0-0.8.14的版本。 除0.8.16+, 0.7.62+, 0.6.39+, 0.5.38+.

wget http://sysoev.ru/nginx/nginx-0.7.62.tar.gz tar zxvf nginx-0.7.62.tar.gz cd nginx-0.7.62

关闭debug模式来减少nginx大小

vi auto/cc/gcc # 最后几行sheft+g #注释这行 #CFLAGS=”$CFLAGS -g”

伪装header

vi src/core/nginx.h #define NGINX_VERSION “1.2” #define NGINX_VER “C1GWS/” NGINX_VERSION

编译

./configure –user=www –group=website –prefix=/opt/nginx –with-http_stub_status_module –with-http_ssl_module make

#不需做make install哈

备份原始文件

mv /opt/nginx/sbin/nginx /opt/nginx/sbin/nginx.old

复制新文件

cp objs/nginx /opt/nginx/sbin/nginx

检查配置文件

/opt/nginx/sbin/nginx -t

如果你的配置文件是0.6X的话会有2个错误

[warn]: the “optimize_server_names” directive is deprecated, use the “server_name_in_redirect” directive instead in /opt/nginx/conf/nginx.conf:36 [emerg]: “server_name_in_redirect” directive is duplicate in /opt/nginx/conf/nginx.conf:37 configuration file /opt/nginx/conf/nginx.conf test failed [warn]: duplicate MIME type “text/html” in /opt/nginx/conf/nginx.conf:63 the configuration file /opt/nginx/conf/nginx.conf syntax is ok configuration file /opt/nginx/conf/nginx.conf test is successful

nginx.conf中去掉server_name_in_redirect及text/html

optimize_server_names off; server_name_in_redirect off; gzip_types text/plain application/x-javascript text/css application/xml;

重命名pid,并启用新的pid #”`“在键盘左上角

kill -USR2 `cat /dev/shm/nginx.pid`

退出旧的nginx

kill -QUIT `cat /dev/shm/nginx.pid.oldbin`

升级完成!

curl -I localhost HTTP/1.1 200 OK Server: C1GWS/1.2

curl -I localhost

Posted in Nginx, 安全, 技术.

Tagged with , .


tomcat安全设置

1.关闭服务器端口: server.xml默认有下面一行:

这样允许任何人只要telnet到服务器的8005端口,输入”SHUTDOWN”,然后回车,服务器立即就被关掉了。 从安全的角度上考虑,我们需要把这个shutdown指令改成一个别人不容易猜测的字符串,可以同时把端口也改了。 例如修改如下:

这样就只有在telnet到8005,并且输入”c1gstudio”才能够关闭Tomcat. 注意:这个修改不影响shutdown.bat的执行。运行shutdown.bat一样可以关闭服务器。

2.增加防火墙 更安全的方式是同时增加防火墙,来限制访问Tomcat的控制与连接器端口 你可以通过运行netstat -a来查看网络服务器socket及其他现有连接的清单 插入规则 iptables -A INPUT -p tcp -m tcp –dport 8005 -j DROP 保存规则 service iptables save 重载规则 service iptables restart

3.处理好Tomcat管理台的安全 Tomcat管理台的应用文件,默认在{Tomcat安装目录}\server\webapps下,有admin和manager两个应用。 其用户密码,在{Tomcat安装目录}\conf/tomcat-users.xml中定义。在{Tomcat安装目录}\webapps下 admin.xml和manager.xml文件定义了可以通过访问/admin和/manager进入。 默认情况下,完全可以登录tomcat管理台,造成严重安全问题 检测办法:用IE打开链接http://[IP]:[Port]/admin,以用户名admin,密码为空登录,如果成功, 说明存在问题。 解决办法:可以删除{Tomcat安装目录}\webapps下admin.xml和manager.xml文件,或者去掉用户密 码,也可以删除应用文件。

4.运行错误网页

如果找不到网页即出现404错误,会显示服务器版本号,服务器配置也一目了然, 为了避免这种情况,希望自定义设置错误页面。 设置如下: 用记事本打开\conf\web.xml文件,在文件的倒数第二行(一行之前)加入以下内容:

404 /404.jsp 500 /500.jsp

在根目录下创建404.jsp和500.jsp文件

5.多重服务器的安全防护模式 当在同一台主机(或同一网络文件系统)上的 Apache httpd Web 服务器与 Tomcat 之间共享网页的实际目录时, 请留意其个别安全防护模式间的相互作用。当你有“受保护的目录”时,这会特别重要。 服务器将具有能读取彼此文件的权限。 在这些状况下,请注意 Tomcat 并不会保护如 .htaccess 的文件,而Apache也不会保护Web应用程序的 WEB-INF 或 META-INF 目录。 这些情形都有可能导致重大的安全漏洞,所以,我们建议你在使用这些特别的目录时,要格外小心。

若要让 Apache httpd 保护 WEB-INF 及 META-INF 目录,请在 httpd.conf 中加入下列内容

AllowOverride None deny from all AllowOverride None deny from all

6.屏蔽目录文件自动列出的方法 conf/web.xml文件

default org.apache.catalina.servlets.DefaultServlet debug 0 listings false 1 false

这里false为不列出,true为充许列出

7.以非root用户运行

8.关闭8009端口 8009/tcp open ajp13

8009端口是tomcat和apache的mod_proxy_ajp,mod_jk沟通的端口,没有用到就关了。

tomcatpath/conf/server.xml 中的这段注释掉

<!– –>

Posted in Tomcat, 技术.

Tagged with , .


整理国内centos5 yum源

一,http://ftp.sjtu.edu.cn/centos/,上海交大,但服务器位于北京,中国教育网网络中心,我看像是朝阳区那边的IP,以前在那边上过班,下载速度高达十M。 北方用户与教育网用户推荐,速度飞快。 CentOS版本也挺多,现在用5.2和5.3的用户较新。 CenOS-Base.repo:无连接,麻烦手动

二,http://centos.ustc.edu.cn,中国科技大学,服务器位于合肥。 南方用户推荐。 同样的,CenOS版本非常丰富,适合长期使用。 CenOS-Base.repo:http://centos.ustc.edu.cn/CentOS-Base.repo

三,http://mirrors.sohu.com ,搜狐的开源软件镜像。 已经有了各种Linux、BSD发行版和MySQL,服务器位于山东网通。

四,http://mirrors.163.com,网易的开源软件镜像

以下是手动更新YUM配置文件的方法:

修改/etc/yum.repos.d/CentOS-Base.repo:

[base] name=CentOS-5 – Base #mirrorlist=http://mirrorlist.centos.org/?release=$releasever5&arch=$basearch& repo=os #baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/ baseurl=http://ftp.sjtu.edu.cn/centos/5.0/os/$basearch/ gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos5

#released updates [update] name=CentOS-5 – Updates #mirrorlist=http://mirrorlist.centos.org/?release=4&arch=$basearch&repo=updates baseurl=http://ftp.sjtu.edu.cn/centos/5.0/updates/$basearch/ gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos5

#packages used/produced in the build but not released [addons] name=CentOS-5 – Addons #mirrorlist=http://mirrorlist.centos.org/?release=4&arch=$basearch&repo=addons

baseurl=http://ftp.sjtu.edu.cn/centos/5.0/addons/$basearch/ gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos5

#additional packages that may be useful [extras] name=CentOS-5 – Extras #mirrorlist=http://mirrorlist.centos.org/?release=4&arch=$basearch&repo=extras

baseurl=http://ftp.sjtu.edu.cn/centos/5.0/extras/$basearch/ gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos5

#additional packages that extend functionality of existing packages [centosplus] name=CentOS-5 – Plus #mirrorlist=http://mirrorlist.centos.org/?release=4&arch=$basearch&repo=centosplus baseurl=http://ftp.sjtu.edu.cn/centos/5.0/centosplus/$basearch/ gpgcheck=1 enabled=0 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos5

#contrib – packages by Centos Users [contrib] name=CentOS-5 – Contrib #mirrorlist=http://mirrorlist.centos.org/?release=4&arch=$basearch&repo=contrib baseurl=http://ftp.sjtu.edu.cn/centos/5.0/contrib/$basearch/ gpgcheck=1 enabled=0 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos5

2.执行 64位: rpm –import http://ftp.sjtu.edu.cn/centos/5.0/os/x86_64/RPM-GPG-KEY-CentOS-5

32位: rpm –import http://ftp.sjtu.edu.cn/centos/5.0/os/i386/RPM-GPG-KEY-CentOS-5

3.执行 yum update

以下是直接下载配置文件的方法,我比较喜欢,当然,前提是需要你联网了。

cd /etc/yum.repos.d mv CentOS-Base.repo CentOS-Base.repo.save wget http://centos.ustc.edu.cn/CentOS-Base.repo

参考:http://www.4wei.cn/?p=1000248

Posted in LINUX, 技术.

Tagged with .


Linux Top命令翻页方法

一直以为Top是没有翻页的,汗~

Shift+

======================================== 问了下man是这这么说的,确实不是翻页… ´<´ :Move_Sort_Field_Left Moves the sort column to the left unless the current sort field is the first field being displayed.

     ´>´ :Move_Sort_Field_Right
          Moves the sort column to the right unless the current sort field is the last field being displayed.

Posted in Linux 命令, 技术.

Tagged with .


搜狐开源镜像上线

继网易在今年二月启动开源项目镜像之后(http://mirrors.163.com/),现在国内的另一家门户网站搜狐也上线了开源镜像站。浏览该站点,其中镜像的项目包括 Arch Linux、CentOS、Debian、Fedora、Gentoo、Ubuntu 等 Linux 发行版,同时也包括 FreeBSD、OpenBSD 等 BSD 版本 http://mirrors.sohu.com

页底红色的”Coming soon“字样提示目前尚未同步完毕,各位仍需稍作等待方能投入使用。

CentOs5 目前还没有…

Posted in LINUX, 技术.

Tagged with .


SSH,telnet终端中文显示乱码解决办法 (CentOS 5.2 )

vi /etc/sysconfig/i18n LANG=”en_US.UTF-8″ SYSFONT=”latarcyrheb-sun16″

修改原内容为

LANG=”zh_CN.GB18030″ LANGUAGE=”zh_CN.GB18030:zh_CN.GB2312:zh_CN” SUPPORTED=”zh_CN.UTF-8:zh_CN:zh:en_US.UTF-8:en_US:en” SYSFONT=”lat0-sun16″

用yum安装中文字体

yum install fonts-chinese.noarch

断开ssh重新连

date

2009年 09月 21日 星期一 13:47:53 CST

Posted in linux 维护优化, 技术.

Tagged with .


[转]MySQL 的調校 (軟硬體、版本、設定)

 

把一些關於 MySQL 的資料整理一下。

初期的 MySQL 隨便跑沒關係,備份的部份記得要把 binlog 也一起備份起來,用 gzip 壓過後 (不使用 bzip2 或是高壓縮率參數,是因為考量解壓縮速度;另外推薦用 Parallel gzip 壓縮,速度比較快) 再用 openssl 加密丟到 Amazon S3 上。

成長後,買獨立伺服器要一次買兩台跑 HA,每台分別是:

  • CPU 要考量 SQL query 的方式,如果打算在 MySQL 做很多事情 (i.e. JOIN),CPU 要選高階的;如果大多都是 simple query,則以 C/P 值高的 CPU 優先:兩顆四核心 CPU 算是現在比較划算的硬體。不管哪一種,選低電壓的,像是 Intel Xeon L5408 或是 Intel Xeon L5520,因為硬碟蠻熱的,要減少熱量以免伺服器容易當掉。
  • 記憶體愈多愈好,64GB 算是還蠻基本的。
  • 硬碟選轉速快的 15krpm SAS,挑大一點的硬碟 (以現在的市場就是 300GB) 省得以後空間不夠要搬動。最好是硬體 RAID1+0,依照應用決定單台 database 要多大,如果預定八顆的話可以買 2U 來塞。

軟體的部份:

  • 一定要跑 Linux x86-64 版本,挑大的 distribution 以免遇到問題卻無法解決。我自己還蠻偏好用 Debian。不論是 Debian 還是其他 distribution,儘量跟穩定的 branch,遇到需要升級時的問題會比較少,像是 Debian Lenny
  • 如果要跑 DRBD,先在兩台上面設定好 Heartbeat + DRBD。如果是跑 MMM 的話就設定 MMM,比較需要注意的是 MMM 的版本,參考「MySQL MMM 的情況」。
  • Filesystem 跑 XFS,很多人在上面跑很久了,經過時間考驗的 Filesystem,跑起 MySQL InnoDB 的效率還不錯。
  • MySQL 跑 Percona 的 5.0 標準版本 (非 highperf 版),穩定性還不錯。如果預期到資料量很大的時候會是 I/O bound,可以考慮 Percona 的 5.1 版本,並且開啟 InnoDB Plugin 壓縮的功能。
  • 跑監控程式,把系統的狀態記錄下來。可以是 MuninCacti 或是 nagios,資料對於瓶頸分析很重要。

my.cnf 設定的部份要花不少功夫,除了一般常見的設定外 (這部份網路上很多文件),有些在站台比較大時會發生的問題要注意:

  • back_log 要開大,因為站台大的時候通常不會用 pconnect (每個 web server 都掛著 64 個連線,當有十台 web server 就佔用 640 個連線),而是用 connect,在每次做完事情就斷線,配合 memcached 降低 MySQL 的需求。不過在量夠大的時候,還是會遇到預設的 back_log 不夠。Smugmug 的 CEO 在「Great things afoot in the MySQL community」有提到吃過這個值的虧。
  • max_allowed_packet 設大一點,避免比較大的 INSERT 或是 UPDATE 造成錯誤。通常這是設計上的問題,應該要避免在 MySQL 裡放 blob 資料,不過偶而還是會需要…
  • max_connect_errors 設 4294967295,可以避免當 client (像是 php) 發生太多錯誤時被 block 住。
  • innodb_adaptive_checkpoint 要打開,可以避免在 flush dirty pages 的時候產生 slow query。MySQL 官方的版本沒有這個參數,而這個參數也是為什麼要用 Percona 版本之一。效果可以參考「Adaptive checkpointing」這篇文章。

 

原文http://blog.gslin.org/archives/2009/09/13/2088/

Posted in Mysql, 技术.

Tagged with , .


2009年9月语言排行榜:php超越c++第一次进入前三

 

The TIOBE Programming Community index gives an indication of the popularity of programming languages. The index is updated once a month. The ratings are based on the number of skilled engineers world-wide, courses and third party vendors. The popular search engines Google, MSN, Yahoo!, Wikipedia and YouTube are used to calculate the ratings. Observe that the TIOBE index is not about the best programming language or the language in which most lines of code have been written.

The index can be used to check whether your programming skills are still up to date or to make a strategic decision about what programming language should be adopted when starting to build a new software system. The definition of the TIOBE index can be found here.

Position Sep 2009 Position Sep 2008 Delta in Position Programming Language Ratings Sep 2009 Delta Sep 2008 Status
1 1 Java 19.383% -1.33%   A
2 2 C 16.861% +1.48%   A
3 5 PHP 10.156% +0.91%   A
4 3 C++ 9.988% -0.73%   A
5 4 (Visual) Basic 9.196% -1.29%   A
6 7 Perl 4.528% -0.31%   A
7 8 C# 4.186% -0.15%   A
8 6 Python 3.930% -1.08%   A
9 9 JavaScript 2.995% -0.14%   A
10 11 Ruby 2.377% -0.38%   A
11 10 Delphi 1.972% -1.08%   A
12 18 Pascal 0.961% +0.56%   A
13 16 Lisp/Scheme 0.842% +0.42%   A–
14 13 PL/SQL 0.819% +0.12%   A
15 14 SAS 0.781% +0.14%   A
16 24 ABAP 0.705% +0.42%   A
17 12 D 0.588% -0.68%   B
18 42 Objective-C 0.585% +0.48%   B
19 17 Lua 0.507% +0.09%   B
20 25 MATLAB 0.506% +0.25%   B

 

Long term trends

The long term trends for the top 10 programming languages can be found in the line diagram below.

 

Posted in 其它, 分析报告.

Tagged with , .


配置一个内网网卡

先查看下网卡

ifconfig eth0 ……外网 lo ……回路

启用第二块网卡做内网

ifconfig eth1 up ifconfig eth1 192.168.0.11 netmask 255.255.0.0

这样就可以使用了,但重启网络或机器后配置就会失效

想要不失效就需写的文件里

vi etc/sysconfig/networking/profiles/default/ifcfg-eth1 DEVICE=eth1 BOOTPROTO=static HWADDR=00:44:88:6C:3C:88 ONBOOT=yes NETMASK=255.255.255.0 IPADDR=192.168.0.11 TYPE=Ethernet

Posted in linux 维护优化, 技术.

Tagged with .