Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Monday, April 18, 2011

linux命令nc使用实例说明

使用netcat检查服务器的指定的端口是否开通:
root@localhost:~$ nc -z -v 192.168.1.242 80
linux.local [192.168.1.242] 80 (www) open

使用netcat扫描端口:
root@localhost:~$ nc -z -v -w 1 192.168.1.242 1-100
linux.local [192.168.1.242] 80 (www) open
linux.local [192.168.1.242] 22 (ssh) open

使用netcat模拟HTTP请求:
root@localhost:~$ nc www.google.com.hk 80
GET / HTTP/1.1
Host: www.google.com.hk
User-Agent: google-chrome9

HTTP/1.1 200 OK
Date: Mon, 18 Apr 2011 08:56:03 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=Big5
Set-Cookie: PREF=ID=5006f5c292697224:FF=0:NW=1:TM=1303116963:LM=1303116963:S=Lr6ijyXSbmjA6bmZ; expires=Wed, 17-Apr-2013 08:56:03 GMT; path=/; domain=.google.com.hk
Set-Cookie: NID=46=ky6egq_YajJNEzdnM39_2u3CFq2hJLvSVuQm6BokYXSBKhAefFIuL-ZsZOvnDpMISnI2glY25IZxS8_5G0V-EHj-oEc7KRGW4rSZk9yIRnCgsPnm43qhLUMb9hJuKeVW; expires=Tue, 18-Oct-2011 08:56:03 GMT; path=/; domain=.google.com.hk; HttpOnly
Server: gws
X-XSS-Protection: 1; mode=block
Transfer-Encoding: chunked
[......]

Saturday, October 23, 2010

在VIM中如何使用Tidy为HTML验证并格式化内容

在ubuntu中安装tidy只要输入命令:
$> sudo apt-get install tidy

$> man tidy

查看手册,可以看到比较有用的参数设置,一般我的文件都是utf8编码的,所以tidy命令会跟上"-utf8",并且一般情况就是将tidy输出的文件直接替换掉原来的文件,所以"-m"选项也很有用,输出的HTML也希望是格式化,有缩进的代码,这时就要加上"-i"参数,这样在命令行上我的tidy命令会如下所示:

$> tidy -m -i -utf8 target-files1 target-files2

可以将常用的参数设置写在一个配置文件中,在调用tidy命令时指定"-config config-file-name",下面这份配置就是官网上的一个配置例子,稍做了点调整:

// sample config file for HTML tidy
indent: auto
indent-spaces: 4
wrap: 120
markup: yes
output-xml: no
input-xml: no
show-warnings: yes
numeric-entities: yes
quote-marks: yes
quote-nbsp: yes
quote-ampersand: no
break-before-br: no
uppercase-tags: no
uppercase-attributes: no
char-encoding: utf8
new-inline-tags: cfif, cfelse, math, mroot,
mrow, mi, mn, mo, msqrt, mfrac, msubsup, munderover,
munder, mover, mmultiscripts, msup, msub, mtext,
mprescripts, mtable, mtr, mtd, mth
new-blocklevel-tags: cfoutput, cfquery
new-empty-tags: cfelse
在VIM中,如果需要对当前文件进行HTML格式化操作,那么可以在VIM命令模式下输入以下指令:

:!tidy -m -i -utf8 %

References: Clean up your Web pages with HTML TIDY

Friday, October 08, 2010

个人一直使用的一套ubuntu主题

从http://www.bisigi-project.org/?page_id=8&lang=en上下载安装,在ubuntu上用apt-get安装很简单:

$>
sudo add-apt-repository ppa:bisigi/ppa && sudo apt-get update
$> sudo aptitude install showtime-theme

其他更多主题可以选择,都很不错.

ubuntu 10.10 自带的Ambiance配合mac4Lin的emerald主题也很酷.

Friday, October 01, 2010

Ubuntu下Nvidia显卡不定时闪屏的解决

解决方法:

在配置文件中添加一行:
$> sudo vi /etc/modprobe.d/nvidia-kernel-nkc
options nvidia NVreg_Mobile=1 NVreg_RegistryDwords="PerfLevelSrc=0x2222"

更多信息可查看ubuntu的bug list:Occasional screen-wide "blink" when using opengl apps (compiz also) and Nvidia cards

References:
[分享]解决Nvidia显卡不定时闪屏问题

Friday, July 02, 2010

Installation XEN 4.0 from source

以下指令使用root用户执行


$> sudo su -

$> apt-get install bcc bin86 gawk bridge-utils iproute libcurl3 libcurl4-openssl-dev bzip2 module-init-tools transfig tgif texinfo texlive-latex-base texlive-latex-recommended texlive-fonts-extra texlive-fonts-recommended pciutils-dev mercurial build-essential make gcc libc6-dev zlib1g-dev python python-dev python-twisted libncurses5-dev patch libvncserver-dev libsdl-dev libjpeg62-dev iasl libbz2-dev e2fslibs-dev git-core uuid-dev

$> hg clone http://xenbits.xen.org/xen-4.0-testing.hg
$> cd xen-4.0-testing.hg

这个指令会下载linux-2.6-pvops.git,需要较长时间
$> make world


这个指令会安装xen.gz和vmlinuz-2.6.31到系统/boot目录下,vmlinuz-2.6.31这个linux kernel文件在下面会重新设置参数并生成,可查看后面linux kernel编译步骤详细说明。
$> make install


不修改.config文件,可以直接重新生成xen, kernels, tools, docs到dist目录中
$> make dist


修改了.config文件,可以用以下指令重新生成kernel
$> make linux-2.6-xen-config CONFIGMODE=menuconfig     (or xconfig)
$> make linux-2.6-xen-build
$> make linux-2.6-xen-install

linux kernel编译步骤

$> git clone git://git.kernel.org/pub/scm/linux/kernel/git/jeremy/xen.git linux-2.6-xen

这个指令会从xen.git仓库中下载props dom0 kernel 2.6.31.x,大概是1.6G左右,需要不少时间
$> cd linux-2.6-xen

这个指令的作用是检查源码是否有.o文件和依赖问题,从全新的源码编译时不需要这一步。make mrproper主要清除环境变量及配置文件
$ make mrproper


设置linux kernel编译参数,在图形界面中输入斜杠"/"可以查询"XEN_DOM0"、"PAE"、"HIGHPTE"等参数设置
$> make menuconfig


退出并保存配置文件之后,手工调整.config文件,并且在内核参数设置中需要注意:
1、如果编译32位的内核,XEN需要有PAE支持,(Processor type and features -> High Memory Support (64GB) -> PAE (Physical Address Extension) Support),对于64位内核PAE不需要,32位的操作系统最大内存支持不到4G,安装了PAE之后可以支持64G。
2、编译32位的内核,必须设置CONFIG_HIGHPTE=n。
3、要为DOM0开启ACPI功能。
4、在.config文件中添加以下选项,并重新运行make menuconfig,并检查XEN_DOM0等参数设置状态

CONFIG_ACPI_PROCFS=y
CONFIG_XEN=y
CONFIG_XEN_MAX_DOMAIN_MEMORY=32
CONFIG_XEN_SAVE_RESTORE=y
CONFIG_XEN_DOM0=y
CONFIG_XEN_PRIVILEGED_GUEST=y
CONFIG_XEN_PCI=y
CONFIG_PCI_XEN=y
CONFIG_XEN_BLKDEV_FRONTEND=m
CONFIG_NETXEN_NIC=m
CONFIG_XEN_NETDEV_FRONTEND=m
CONFIG_XEN_KBDDEV_FRONTEND=m
CONFIG_HVC_XEN=y
CONFIG_XEN_FBDEV_FRONTEND=m
CONFIG_XEN_BALLOON=y
CONFIG_XEN_SCRUB_PAGES=y
CONFIG_XEN_DEV_EVTCHN=y
CONFIG_XEN_BACKEND=y
CONFIG_XEN_BLKDEV_BACKEND=y
CONFIG_XEN_NETDEV_BACKEND=y
CONFIG_XENFS=y
CONFIG_XEN_COMPAT_XENFS=y
CONFIG_XEN_XENBUS_FRONTEND=m
CONFIG_XEN_PCIDEV_FRONTEND=y

在RHEL5和CentOS5中,需要在.config文件中加入以下2个参数:

CONFIG_SYSFS_DEPRECATED=y
CONFIG_SYSFS_DEPRECATED_V2=y


要使用initrd,编译内核时必须选择以下两项:

CONFIG_BLK_DEV_RAM=y
CONFIG_BLK_DEV_INITRD=y

重新运行menuconfig,检查配置,最后保存配置文件
$> make menuconfig
$> make install

这个指令会将内核映象和相应的System.map拷贝到/boot目录下。

可以查看指令运行完成后,在/boot目录下新增加的文件列表
$> ll --sort=time /boot/
total 214594
-rw-r--r-- 1 root root 109K 2010-07-02 11:51 config-2.6.31.13
-rw-r--r-- 1 root root 1.6M 2010-07-02 11:51 System.map-2.6.31.13
-rw-r--r-- 1 root root 3.9M 2010-07-02 11:51 vmlinuz-2.6.31.13
...


生成初始化镜像文件(initialed ramdisk)
$> cd /boot
$> depmod 2.6.31.13
# ubuntu中生成初如化镜像文件的指令
$> mkinitramfs -o initrd-2.6.31-xen.img 2.6.31.13
# 或者是用这个指令(CentOS5)
$> mkinitrd -v -f --with=aacraid --with=sd_mod --with=scsi_mod initrd-2.6.31-xen.img 2.6.31.13

$> vi /boot/grub/menu.lst

title Xen 4.0, dom0 Linux kernel 2.6.31.13
kernel /boot/xen.gz dom0_mem=512M
module /boot/vmlinuz-2.6.31.13 root=/dev/sda7 ro nomodeset
module /boot/initrd-2.6.31-xen.img


注:一般内核编译中会有以下一些步骤:
$> make menuconfig
$> make
$> make bzImage
$> make modules
$> make modules_install
$> make install


References:
http://wiki.xensource.com/xenwiki/Xen4.0
http://wiki.xensource.com/xenwiki/XenParavirtOps

Monday, May 24, 2010

linux命令行显示指定行号的内容

以第四行为例,要查询的文件名为list.txt:
方法1:

grep -n '^' list.txt |grep '^4:'|grep -o '[^4:].*'

方法2:
sed -n '4p' list.txt

sed -n '4,4p' list.txt
方法3:
awk '{if ( NR==4 ) print $0}' list.txt

方法4:
tac list.txt |tail -4|tac|tail -1
tac list.txt |tail -n 4|tac|tail -n 1

References: http://zhidao.baidu.com/question/91856742

Wednesday, December 02, 2009

在64位的CentOS5中编译安装mysql5.0.88

$> wget http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.88.zip/from/http://mysql.byungsoo.net/
$> yum -y install gcc
$> yum -y install gcc-c++
$> yum -y install ncurses-devel

$> CC=gcc \
CFLAGS="-O3 -fno-omit-frame-pointer" \
CXX=gcc \
CXXFLAGS="-O3 -fno-omit-frame-pointer -felide-constructors -fno-exceptions -fno-rtti" \
./configure --prefix=/usr/local/mysql --without-debug --with-big-tables --with-unix-socket-path=/tmp/mysql.sock --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --enable-assembler --with-extra-charsets=gbk,gb2312,utf8 --with-pthread --enable-thread-safe-client

$> make && make install

Reference: http://dev.mysql.com/doc/refman/5.0/en/linux-ia-64.html

.bashrc中rc的含义说明

rc (像是 ".cshrc" 或 "/etc/rc" 中的 rc 这两个字母) = "RunCom"

"rc" 是取自 "runcom", 来自麻省理工学院在 1965 年发展的 CTSS系统。相关文献曾记载这一段话:
具有从档案中取出一系列命令来执行的功能;这称为 "run commands" 又称为 "runcom",而这种档案又称为一个 runcom (a runcom)。

Monday, November 09, 2009

在linux命令行中批量新建文件夹

$> printf 'dir%01d\n' {1..100} | xargs mkdir

Mysql Server System Variables

mysql 数据库中几个系统变量的分析说明

connect_timeout

Command Line Format --connect_timeout=#
Config File Format connect_timeout
Option Sets Variable Yes, connect_timeout
Variable Name connect_timeout
Variable Scope Global
Dynamic Variable Yes
   Permitted Values (<= 5.1.22)
Type numeric
Default 5
   Permitted Values (>= 5.1.23)
Type numeric
Default 10

The number of seconds that the mysqld server waits for a connect packet before responding with Bad handshake. The default value is 10 seconds as of MySQL 5.1.23 and 5 seconds before that.
Increasing the connect_timeout value might help if clients frequently encounter errors of the form Lost connection to MySQL server at 'XXX', system error: errno.
增加此值可以解决此问题:Lost connection to MySQL server at 'XXX', system error: errno.



delay_key_write

Command Line Format --delay-key-write[=name]
Config File Format delay-key-write
Option Sets Variable Yes, delay_key_write
Variable Name delay-key-write
Variable Scope Global
Dynamic Variable Yes
   Permitted Values
Type enumeration
Default ON
Valid Values ON, OFF, ALL

This option applies only to MyISAM tables.
此参数只针对MyISAM表。
It can have one of the following values to affect handling of the DELAY_KEY_WRITE table option that can be used in CREATE TABLE statements.
Option Description
OFF DELAY_KEY_WRITE is ignored.
ON MySQL honors any DELAY_KEY_WRITE option specified in CREATE TABLE statements. This is the default value.
ALL All new opened tables are treated as if they were created with the DELAY_KEY_WRITE option enabled.

If DELAY_KEY_WRITE is enabled for a table, the key buffer is not flushed for the table on every index update, but only when the table is closed. This speeds up writes on keys a lot, but if you use this feature, you should add automatic checking of all MyISAM tables by starting the server with the --myisam-recover option (for example, --myisam-recover=BACKUP,FORCE). See Section 5.1.2, “Server Command Options”, and Section 13.5.1, “MyISAM Startup Options”.
Warning
如果启用了DELAY_KEY_WRITE,说明使用该项的表的键缓冲区在每次更新索引时不被清空,只有关闭表时才清空。遮掩盖可以大大加快键的写操作,但如果你使用该特性,你应用--myisam-recover选项启动服务器,为所有MyISAM表添加自动检查(例如,--myisam-recover=BACKUP,FORCE)。
If you enable external locking with --external-locking, there is no protection against index corruption for tables that use delayed key writes.



expire_logs_days

Command Line Format --expire_logs_days=#
Config File Format expire_logs_days
Option Sets Variable Yes, expire_logs_days
Variable Name expire_logs_days
Variable Scope Global
Dynamic Variable Yes
   Permitted Values
Type numeric
Default 0
Range 0-99

The number of days for automatic binary log removal. The default is 0, which means “no automatic removal.” Possible removals happen at startup and when the binary log is flushed.
二进制日志自动删除的天数,可设置值的范围为0至99。默认值为0,表示“没有自动删除”。启动时和二进制日志循环时可能删除。

init_connect
Command Line Format --init-connect=name
Config File Format init_connect
Option Sets Variable Yes, init_connect
Variable Name init_connect
Variable Scope Global
Dynamic Variable Yes
   Permitted Values
Type string

A string to be executed by the server for each client that connects. The string consists of one or more SQL statements. To specify multiple statements, separate them by semicolon characters. For example, each client begins by default with autocommit mode enabled. There is no global system variable to specify that autocommit should be disabled by default, but init_connect can be used to achieve the same effect:

SET GLOBAL init_connect='SET autocommit=0';

This variable can also be set on the command line or in an option file. To set the variable as just shown using an option file, include these lines:

[mysqld]
init_connect='SET autocommit=0'

Note that the content of init_connect is not executed for users that have the SUPER privilege. This is done so that an erroneous value for init_connect does not prevent all clients from connecting. For example, the value might contain a statement that has a syntax error, thus causing client connections to fail. Not executing init_connect for users that have the SUPER privilege enables them to open a connection and fix the init_connect value.
在这里比较常用的初始化语句是设置一个字符集,当然也可以直接修改my.cnf中的配置参数(character_set_connection/character_set_client等):
[mysqld]
init_connect='SET names utf8'




interactive_timeout

Command Line Format --interactive_timeout=#
Config File Format interactive_timeout
Option Sets Variable Yes, interactive_timeout
Variable Name interactive_timeout
Variable Scope Both
Dynamic Variable Yes
   Permitted Values
Type numeric
Default 28800
Min Value 1

The number of seconds the server waits for activity on an interactive connection before closing it. An interactive client is defined as a client that uses the CLIENT_INTERACTIVE option to mysql_real_connect(). See also wait_timeout.
一个连接如果长时间空闲会被mysql服务端强行关闭掉,其默认的时间是8小时,在用JDBC连接到mysql中,如果池里的连接超过8小时没有使用,就会产生连接异常。

wait_timeout
Command Line Format --wait_timeout=#
Config File Format wait_timeout
Option Sets Variable Yes, wait_timeout
Variable Name wait_timeout
Variable Scope Both
Dynamic Variable Yes
   Permitted Values
Type numeric
Default 28800
Range 1-31536000
   Permitted Values
Type (windows) numeric
Default 28800
Range 1-2147483

The number of seconds the server waits for activity on a noninteractive connection before closing it. This timeout applies only to TCP/IP and Unix socket file connections, not to connections made via named pipes, or shared memory.

On thread startup, the session wait_timeout value is initialized from the global wait_timeout value or from the global interactive_timeout value, depending on the type of client (as defined by the CLIENT_INTERACTIVE connect option to mysql_real_connect()).
这个值一般不需要去设置,只要设置interactive_timeout。



join_buffer_size
Command Line Format --join_buffer_size=#
Config File Format join_buffer_size
Option Sets Variable Yes, join_buffer_size
Variable Name join_buffer_size
Variable Scope Both
Dynamic Variable Yes
   Permitted Values
Platform Bit Size 64
Type numeric
Default 131072
Range 8200-18446744073709547520

The size of the buffer that is used for plain index scans, range index scans, and joins that do not use indexes and thus perform full table scans. Normally, the best way to get fast joins is to add indexes. Increase the value of join_buffer_size to get a faster full join when adding indexes is not possible. One join buffer is allocated for each full join between two tables. For a complex join between several tables for which indexes are not used, multiple join buffers might be necessary.

The maximum allowable setting for join_buffer_size is 4GB. As of MySQL 5.1.23, values larger than 4GB are allowed for 64-bit platforms (except 64-bit Windows, for which large values are truncated to 4GB with a warning).




key_buffer_size

Command Line Format --key_buffer_size=#
Config File Format key_buffer_size
Option Sets Variable Yes, key_buffer_size
Variable Name key_buffer_size
Variable Scope Global
Dynamic Variable Yes
   Permitted Values
Type numeric
Default 8388608
Range 8-4294967295

此参数仅用于MyISAM表中,一般此值可设置为物理内存的25-50%,尽可能的使用 Key_reads/Key_read_requests 的比率小于0.01,最重要的mysql性能调优参数。

Index blocks for MyISAM tables are buffered and are shared by all threads. key_buffer_size is the size of the buffer used for index blocks. The key buffer is also known as the key cache.
MyISAM表的索引块分配了缓冲区,由所有线程共享。key_buffer_size是索引块缓冲区的大小。键值缓冲区即为键值缓存。
The maximum allowable setting for key_buffer_size is 4GB on 32-bit platforms. As of MySQL 5.1.23, values larger than 4GB are allowed for 64-bit platforms, except 64-bit Windows prior to MySQL 5.1.31, for which large values are truncated to 4GB with a warning. As of MySQL 5.1.31, values larger than 4GB are also allowed for 64-bit Windows. The effective maximum size might be less, depending on your available physical RAM and per-process RAM limits imposed by your operating system or hardware platform. The value of this variable indicates the amount of memory requested. Internally, the server allocates as much memory as possible up to this amount, but the actual allocation might be less.
key_buffer_size的最大允许设定值为4GB。有效最大值可以更小,取决于可用物理RAM和操作系统或硬件平台强加的每个进程的RAM限制。
You can increase the value to get better index handling for all reads and multiple writes; on a system whose primary function is to run MySQL using the MyISAM storage engine, 25% of the machine's total memory is an acceptable value for this variable. However, you should be aware that, if you make the value too large (for example, more than 50% of the machine's total memory), your system might start to page and become extremely slow. This is because MySQL relies on the operating system to perform file system caching for data reads, so you must leave some room for the file system cache. You should also consider the memory requirements of any other storage engines that you may be using in addition to MyISAM.
增加该值,达到你可以提供的更好的索引处理(所有读和多个写操作)。通常为主要运行MySQL的机器内存的25%。但是,如果你将该值设得过大(例如,大于总内存的50%),系统将转换为页并变得极慢。MySQL依赖操作系统来执行数据读取时的文件系统缓存,因此你必须为文件系统缓存留一些空间。
For even more speed when writing many rows at the same time, use LOCK TABLES. See Section 7.2.21, “Speed of INSERT Statements”.
同时写多行时要想速度更快,应使用LOCK TABLES。
You can check the performance of the key buffer by issuing a SHOW STATUS statement and examining the Key_read_requests, Key_reads, Key_write_requests, and Key_writes status variables. (See Section 12.5.5, “SHOW Syntax”.) The Key_reads/Key_read_requests ratio should normally be less than 0.01. The Key_writes/Key_write_requests ratio is usually near 1 if you are using mostly updates and deletes, but might be much smaller if you tend to do updates that affect many rows at the same time or if you are using the DELAY_KEY_WRITE table option.

The fraction of the key buffer in use can be determined using key_buffer_size in conjunction with the Key_blocks_unused status variable and the buffer block size, which is available from the key_cache_block_size system variable:

   ((Key_blocks_unused × key_cache_block_size) / key_buffer_size)
  
用key_buffer_size结合Key_blocks_unused状态变量和缓冲区块大小,可以确定使用的键值缓冲区的比例。从key_cache_block_size服务器变量可以获得缓冲区块大小。使用的缓冲区的比例为:
   ((Key_blocks_unused * key_cache_block_size) / key_buffer_size)
该值为约数,因为键值缓冲区的部分空间被分配用作内部管理结构。

可以创建多个MyISAM键值缓存。4GB限制可以适合每个缓存,而不是一个组。
This value is an approximation because some space in the key buffer may be allocated internally for administrative structures.

It is possible to create multiple MyISAM key caches. The size limit of 4GB applies to each cache individually, not as a group. See Section 7.4.5, “The MyISAM Key Cache”.



log_slave_updates

Whether updates received by a slave server from a master server should be logged to the slave's own binary log. Binary logging must be enabled on the slave for this variable to have any effect.
假如mysql slave还用作为master server时,需要设置此参数,记录所有SQL操作,提供其他slave复制。



log_slow_queries
Command Line Format --log-slow-queries[=name]
Config File Format log-slow-queries
Option Sets Variable Yes, log_slow_queries
Variable Name log_slow_queries
Variable Scope Global
Dynamic Variable Yes
   Permitted Values
Type boolean

Whether slow queries should be logged. “Slow” is determined by the value of the long_query_time variable.
记录查询非常慢的SQL到一个独立的日志文件中,可用于SQL分析和优化。




lower_case_file_system
Command Line Format --lower_case_file_system[=#]
Config File Format lower_case_file_system
Option Sets Variable Yes, lower_case_file_system
Variable Name lower_case_file_system
Variable Scope Global
Dynamic Variable No
   Permitted Values
Type boolean

This variable describes the case sensitivity of file names on the file system where the data directory is located. OFF means file names are case sensitive, ON means they are not case sensitive.

lower_case_table_names
Command Line Format --lower_case_table_names[=#]
Config File Format lower_case_table_names
Option Sets Variable Yes, lower_case_table_names
Variable Name lower_case_table_names
Variable Scope Global
Dynamic Variable No
   Permitted Values
Type numeric
Default 0
Range 0-2

If set to 1, table names are stored in lowercase on disk and table name comparisons are not case sensitive. If set to 2 table names are stored as given but compared in lowercase. This option also applies to database names and table aliases. See Section 8.2.2, “Identifier Case Sensitivity”.

这个参数在linux服务器上需要注意,一般是将此值设置为1,使表名全部以小写方式写入硬盘,避免表名的大小写问题。

If you are using InnoDB tables, you should set this variable to 1 on all platforms to force names to be converted to lowercase.

You should not set this variable to 0 if you are running MySQL on a system that does not have case-sensitive file names (such as Windows or Mac OS X). If this variable is not set at startup and the file system on which the data directory is located does not have case-sensitive file names, MySQL automatically sets lower_case_table_names to 2.


max_allowed_packet
Command Line Format --max_allowed_packet=#
Config File Format max_allowed_packet
Option Sets Variable Yes, max_allowed_packet
Variable Name max_allowed_packet
Variable Scope Both
Dynamic Variable Yes
   Permitted Values
Type numeric
Default 1048576
Range 1024-1073741824

The maximum size of one packet or any generated/intermediate string.

The packet message buffer is initialized to net_buffer_length bytes, but can grow up to max_allowed_packet bytes when needed. This value by default is small, to catch large (possibly incorrect) packets.

此值需要是1024的一个倍数值,如果操作的数据有使用很长的字符串和大的BLOB字段,如图片,需要增加此值。
You must increase this value if you are using large BLOB columns or long strings. It should be as big as the largest BLOB you want to use. The protocol limit for max_allowed_packet is 1GB. The value should be a multiple of 1024; nonmultiples are rounded down to the nearest multiple.

When you change the message buffer size by changing the value of the max_allowed_packet variable, you should also change the buffer size on the client side if your client program allows it. On the client side, max_allowed_packet has a default of 1GB. Some programs such as mysql and mysqldump enable you to change the client-side value by setting max_allowed_packet on the command line or in an option file.




max_connect_errors
Command Line Format --max_connect_errors=#
Config File Format max_connect_errors
Option Sets Variable Yes, max_connect_errors
Variable Name max_connect_errors
Variable Scope Global
Dynamic Variable Yes
   Permitted Values
Platform Bit Size 32
Type numeric
Default 10
Range 1-4294967295
   Permitted Values
Platform Bit Size 64
Type numeric
Default 10
Range 1-18446744073709547520

If there are more than this number of interrupted connections from a host, that host is blocked from further connections. You can unblock blocked hosts with the FLUSH HOSTS statement.
如果从某台服务器的连接错误过多,会被mysql服务器阻挡连接。




max_connections
Command Line Format --max_connections=#
Config File Format max_connections
Option Sets Variable Yes, max_connections
Variable Name max_connections
Variable Scope Global
Dynamic Variable Yes
   Permitted Values (<= 5.1.14)
Type numeric
Default 100
   Permitted Values (>= 5.1.15)
Type numeric
Default 151
Range 1-16384
   Permitted Values (>= 5.1.17)
Type numeric
Default 151
Range 1-100000

The number of simultaneous client connections allowed. By default, this is 151, beginning with MySQL 5.1.15. (Previously, the default was 100.)
这个值一般都会调整得大一些,如200或者是500,用于处理并发连接数。如果看到“Too many connections”这样的错误提示就是表示mysql服务器的连接数已经被用完。



max_relay_log_size
Command Line Format --max_relay_log_size=#
Config File Format max_relay_log_size
Option Sets Variable Yes, max_relay_log_size
Variable Name max_relay_log_size
Variable Scope Global
Dynamic Variable Yes
   Permitted Values
Type numeric
Default 0
Range 0-1073741824

If a write by a replication slave to its relay log causes the current log file size to exceed the value of this variable, the slave rotates the relay logs (closes the current file and opens the next one). If max_relay_log_size is 0, the server uses max_binlog_size for both the binary log and the relay log. If max_relay_log_size is greater than 0, it constrains the size of the relay log, which enables you to have different sizes for the two logs. You must set max_relay_log_size to between 4096 bytes and 1GB (inclusive), or to 0. The default value is 0.



net_read_timeout
Command Line Format --net_read_timeout=#
Config File Format net_read_timeout
Option Sets Variable Yes, net_read_timeout
Variable Name net_read_timeout
Variable Scope Both
Dynamic Variable Yes
   Permitted Values
Type numeric
Default 30
Min Value 1

The number of seconds to wait for more data from a connection before aborting the read. This timeout applies only to TCP/IP connections, not to connections made via Unix socket files, named pipes, or shared memory. When the server is reading from the client, net_read_timeout is the timeout value controlling when to abort. When the server is writing to the client, net_write_timeout is the timeout value controlling when to abort.
此参数只针对TCP/IP的mysql连接,当超过此值的秒数后,服务器端会放弃从客户端读取数据。



old_passwords
Command Line Format --old_passwords
Config File Format old-passwords
Option Sets Variable Yes, old_passwords
Variable Name old_passwords
Variable Scope Both
Dynamic Variable Yes
   Permitted Values
Type boolean
Default FALSE

Whether the server should use pre-4.1-style passwords for MySQL user accounts.
如果客户端收到的错误消息为:“Client does not support authentication protocol”,说明服务器使用的是旧的密码格式,需要为用户按旧的格式重设密码。
mysql>SET PASSWORD 'some_user'@'some_host' = OLD_PASSWORD('newpwd');




read_only
Command Line Format --read_only
Config File Format read_only
Option Sets Variable Yes, read_only
Variable Name read_only
Variable Scope Global
Dynamic Variable Yes
   Permitted Values
Type numeric
Default 0

This variable is off by default. When it is enabled, the server allows no updates except from users that have the SUPER privilege or (on a slave server) from updates performed by slave threads. On a slave server, this can be useful to ensure that the slave accepts updates only from its master server and not from clients. This variable does not apply to TEMPORARY tables, nor does it prevent the server from inserting rows into the log tables (see Section 5.2.1, “Selecting General Query and Slow Query Log Output Destinations”).

read_only exists only as a GLOBAL variable, so changes to its value require the SUPER privilege. Changes to read_only on a master server are not replicated to slave servers. The value can be set on a slave server independent of the setting on the master.

As of MySQL 5.1.15, the following conditions apply:

    * If you attempt to enable read_only while you have any explicit locks (acquired with LOCK TABLES) or have a pending transaction, an error occurs.
    * If you attempt to enable read_only while other clients hold explicit table locks or have pending transactions, the attempt blocks until the locks are released and the transactions end. While the attempt to enable read_only is pending, requests by other clients for table locks or to begin transactions also block until read_only has been set.
    * read_only can be enabled while you hold a global read lock (acquired with FLUSH TABLES WITH READ LOCK) because that does not involve table locks.
这个参数用于slave服务器上,可以控制避免同步复制发生问题。在master上设置此值与slave是无关的,二都互相独立。




server_id
Command Line Format --server-id=#
Config File Format server-id
Option Sets Variable Yes, server_id
Variable Name server_id
Variable Scope Global
Dynamic Variable Yes
   Permitted Values
Type numeric
Default 0
Range 0-4294967295

The server ID, used in replication to give each master and slave a unique identity. This variable is set by the --server-id option. For each server participating in replication, you should pick a positive integer in the range from 1 to 232 – 1 to act as that server's ID.
这个参数用在同步复制时,分配给每个mysql server一个独立唯一的ID标识。




skip_networking

This is ON if the server allows only local (non-TCP/IP) connections. On Unix, local connections use a Unix socket file. On Windows, local connections use a named pipe or shared memory. On NetWare, only TCP/IP connections are supported, so do not set this variable to ON. This variable can be set to ON with the --skip-networking option.
这个参数在许多linux发行版中是被打开的,这样如果是通过TCP/IP进行连接的话,是无法连接成功的,需要注释掉这一行设置才可以,或者使用socket进行连接。





slow_query_log

Whether the slow query log is enabled. The value can be 0 (or OFF) to disable the log or 1 (or ON) to enable the log. The default value depends on whether the --slow_query_log option is given (--log-slow-queries before MySQL 5.1.29). The destination for log output is controlled by the log_output system variable; if that value is NONE, no log entries are written even if the log is enabled. The slow_query_log variable was added in MySQL 5.1.12.
用于分析查询效率低下的SQL


slow_query_log_file
Version Introduced 5.1.12
Command Line Format --slow-query-log-file=file_name
Config File Format slow_query_log_file
Option Sets Variable Yes, slow_query_log_file
Variable Name slow_query_log_file
Variable Scope Global
Dynamic Variable Yes
   Permitted Values
Type filename

The name of the slow query log file. The default value is host_name-slow.log, but the initial value can be changed with the --slow_query_log_file option (--log-slow-queries before MySQL 5.1.29). This variable was added in MySQL 5.1.12.


  
sort_buffer_size
Command Line Format --sort_buffer_size=#
Config File Format sort_buffer_size
Option Sets Variable Yes, sort_buffer_size
Variable Name sort_buffer_size
Variable Scope Both
Dynamic Variable Yes
   Permitted Values
Platform Bit Size 32
Type numeric
Default 2097144
Max Value 4294967295
   Permitted Values
Platform Bit Size 64
Type numeric
Default 2097144
Max Value 18446744073709547520

Each thread that needs to do a sort allocates a buffer of this size. Increase this value for faster ORDER BY or GROUP BY operations. See Section B.5.4.4, “Where MySQL Stores Temporary Files”.

The maximum allowable setting for sort_buffer_size is 4GB. As of MySQL 5.1.23, values larger than 4GB are allowed for 64-bit platforms (except 64-bit Windows, for which large values are truncated to 4GB with a warning).
对于SQL中用到order by和group by子句的,提高此值可以增加查询的速度。



table_cache
Version Removed 5.1.3
Version Deprecated 5.1.3
Command Line Format --table_cache=#
Config File Format table_cache
Option Sets Variable Yes, table_cache
Variable Name table_cache
Variable Scope Global
Dynamic Variable Yes
Deprecated 5.1.3, by table_open_cache
   Permitted Values
Type numeric
Default 64
Range 1-524288

This is the old name of table_open_cache before MySQL 5.1.3. From 5.1.3 on, use table_open_cache instead.



table_open_cache
Version Introduced 5.1.3
Command Line Format --table-open-cache=#
Config File Format table_open_cache
Variable Name table_open_cache
Variable Scope Global
Dynamic Variable Yes
   Permitted Values
Type numeric
Default 64
Range 64-524288

The number of open tables for all threads. Increasing this value increases the number of file descriptors that mysqld requires. You can check whether you need to increase the table cache by checking the Opened_tables status variable. See Section 5.1.7, “Server Status Variables”. If the value of Opened_tables is large and you don't do FLUSH TABLES often (which just forces all tables to be closed and reopened), then you should increase the value of the table_open_cache variable. For more information about the table cache, see Section 7.4.7, “How MySQL Opens and Closes Tables”. Before MySQL 5.1.3, this variable is called table_cache.
  


thread_concurrency
Command Line Format --thread_concurrency=#
Config File Format thread_concurrency
Option Sets Variable Yes, thread_concurrency
Variable Name thread_concurrency
Variable Scope Global
Dynamic Variable No
   Permitted Values
Type numeric
Default 10
Range 1-512

This variable is specific to Solaris systems, for which mysqld invokes the thr_setconcurrency() with the variable value. This function enables applications to give the threads system a hint about the desired number of threads that should be run at the same time.

Sunday, September 27, 2009

svn 批量添加新文件

$> svn status |grep '^\?'|awk -F " " '{print $2}'|xargs svn add

或者是
$> svn st|grep '^\?'|sed 's/^\?\s*//g'|xargs svn add

Thursday, August 06, 2009

todo list on linux

1. devtodo
2. tudu
3. remind
4. todo.txt
5. awn todo list applet

使用之后觉得devtodo最为好用,tudu也不错,有vi类似的操作快捷键,用起来很顺手。
awn todo list applet结合awn一起用,做为桌面工具可以即时看到任务数量,操作也非常简单。

Friday, July 31, 2009

Linux 环境变量显示和设置

$> export
export命令不带参数可以将系统的环境变量全部列出来,如果需要设置环境变量,
可以在/etc/profile, ~/.bash_profile, ~/.bashrc文件中设置。

一些标准的环境变量:
SHELL 默认shell
LANG 默认语言
PATH linux寻找命令的默认路径,一般包括/bin,/usr/bin,/sbin,/usr/sbin,
/usr/X11R6/bin, /opt/bin,/usr/local/bin等。用户可以自行添加,
MANPATH man手册的默认路径
INPUTRC 默认键盘映象,详见/etc/inputrc
BASH_ENV bash shell的环境变量,通常在~/.bashrc中
DISPLAY X窗口适用的控制台,DISPLAY=:0对应于控制台F7,DISPLAY=:1对应于
控制台F8,DISPLAY=server:0向远程计算机发送 GUI应用程序。
COLORTERM GUI中的默认终端,通常是gnome-terminal.
USER 自动设置当前登陆用户的用户名。
LONGNAME 通常设置为$USER
MAIL 设置特定$USR的标准邮件目录
HOSTNAME 设置为/bin/hostname的命令输出
HISTSIZE 设置为history命令记住的命令数

Reference:http://matt-u.javaeye.com/blog/411379

Sunday, July 12, 2009

linux 基础学习篇一

1973 UNIX
1977 BSD (Bill Joy) -> FreeBSD
1979 AT&T 版权声明
1984 x86 Minix
1984 Richard Mathew Stallman -> GNU & FSF
GPL / LGPL / Apache / BSD / MIT
1991 Linus Torvalds -> Linux

Linux 执行命令
Command [-options] parameters
date -s '2009-09-09 09:09:09'
cal 2009
netstat -a
ps -aux
查看错误信息
google错误信息和example用法
用man/info查说明及用法

keyboard shortcut
Tab
CTRL + C
CTRL + D

Linux 目录和文件相关命令
root
文件权限:所属用户、所属组、其他人
drwxr-xr-x   19        yu            staff   646     Mar 11 18:39 Books
[属性]        [文件数] [所属用户]   [所属组]  [大小]  [修改日期]    [文件名]
mtime 修改时间(modify)
ctime 状态变更时间(change)
atime 访问时间(access)
touch 修改文件的3个时间值
chgrp/chown/chmod

目录相关操作
./../-/~/~yu
pwd/mkdir/rm/ls/cp/mv

文件相关操作
cat/tac/nl/more/less/head/tail
man/more/less 过程中可以按h/H帮助键

Note: This article is published from gmail.

Saturday, December 27, 2008

clear history command when logout linux

$> vi .bash_logout
# ~/.bash_logout

history -c
clear

Reference:
http://rcsg-gsir.imsb-dsgi.nrc-cnrc.gc.ca/documents/advanced/node125.html

linux auto logout setting

$> cd
$> vi .profile
# user will be auto logout after 300 seconds.
export TMOUT=300

如果是针对所有用户,则修改/etc/profile文件。

Tuesday, December 23, 2008

Wednesday, December 17, 2008

修改gnome-terminal的默认窗口大小

原来打开时为80*24的尺寸,如果需要调整默认的大小,可按下操作:
$> sudo vi /usr/share/vte/termcap/xterm
找到下面这行
:co#80:it#8:li#24\
修改其中的80和24,分别为terminal的高和宽。
也可以用以下命令查看参数:
$> gnome-terminal --help-all

Thursday, December 04, 2008

find command examples related with file status

空目录
find . -type d -empty

n*24小时前访问过的文件
find . -atime +2

n分钟前状态发生改变的文件
find . -cmin +10

n*24小时前内容有被修改过的文件
find . -mtime +1

n*24小时与(n+1)*24小时这一天中,内容有被修改过的文件(数字n前没有"+"号)
find . -mtime 1

删除find命令找到的文件
find . -cmin 1 -delete

这上面的命令中需要注意一点是其中数字前面需要带上"+"号,才表示这个时间点之前的时间段,如果没有提供"+"号,则指这的就限定在这个时间点内,如这一天内或者这一分钟内。

更多find相关用法可参考http://linux.about.com/od/commands/l/blcmdl1_find.htm

Thursday, September 18, 2008

Rsync install and configure

Firstly, download rsync and make install, then:
Rsync Server configure file example:


motd file = /etc/rsyncd.motd
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock

[MODULENAME]
path = /data/backfrom
comment = back data using rsync server
uid = nobody
gid = nobody
read only = no
list = yes
auth users = test
secrets file = /etc/rsyncd.scrt

$> rsync --daemon --port=873

$> vi /etc/rsyncd.scrt
test:testYu@Gmail.com
$> chmod 400 /etc/rsyncd.scrt

==================
Client:

$> vi /home/users/passwordfile
testYu@Gmail.com
$> chmod 400 /etc/rsyncd.scrt

$> rsync -vzrtopg --progress --delete test@192.168.0.1::MODULENAME /data/backto --password-file=/home/users/passwordfile

==================
OR connect rsync server using ssh:

#!/bin/sh
DEST="192.168.0.1"
USER="test"
BACKDIR="/data/backfrom/"
DESTDIR="/data/backto/"
OPTS="-vzrtopg --rsh=ssh --stats --progress"
VAR=`ping -s 1 -c 1 $DEST > /dev/null; echo $?`
if [ $VAR -eq 0 ]; then
rsync $OPTS $BACKDIR $USER@$DEST:$DESTDIR
else
echo "Cannot connect to $DEST."
fi