<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>枫子博客Linux</title>
	<atom:link href="http://www.imfeng.com/tag/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.imfeng.com</link>
	<description>很枫的那种 闲人请勿靠近</description>
	<lastBuildDate>Sun, 05 Feb 2012 11:12:22 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>MySQL的复制原理及配置</title>
		<link>http://www.imfeng.com/mysql%e7%9a%84%e5%a4%8d%e5%88%b6%e5%8e%9f%e7%90%86%e5%8f%8a%e9%85%8d%e7%bd%ae/</link>
		<comments>http://www.imfeng.com/mysql%e7%9a%84%e5%a4%8d%e5%88%b6%e5%8e%9f%e7%90%86%e5%8f%8a%e9%85%8d%e7%bd%ae/#comments</comments>
		<pubDate>Fri, 06 Jan 2012 16:33:06 +0000</pubDate>
		<dc:creator>枫子</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[SQL数据库]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[主从]]></category>
		<category><![CDATA[配置]]></category>

		<guid isPermaLink="false">http://www.imfeng.com/?p=946</guid>
		<description><![CDATA[mysql的数据库的高可用性的架构大概有以下几种：集群，读写分离，主备。而后面两种都是通过复制来实现的。下面将简单介绍复制的原理及配置，以及一些常见的问题。mysql主从同步，请参考http://www.imfeng.com/linux-deploy-mysql-master-and-slave/
 
 
一。复制的原理
MySQL复制基于主服务器在二进制日志中跟踪所有对数据库的更改(更新、删除等等)。每个从服务器从主服务器接收主服务器已经记录到其二进制日志的保存的更新，以便从服务器可以对其数据拷贝执行相同的更新。
将主服务器的数据拷贝到从服务器的一个途径是使用LOAD DATA FROM MASTER语句。请注意LOAD DATA FROM MASTER目前只在所有表使用MyISAM存储引擎的主服务器上工作。并且，该语句将获得全局读锁定。
MySQL使用3个线程来执行复制功能,其中1个在主服务器上，另两个在从服务器上。当发出START SLAVE时，从服务器创建一个I/O线程，以连接主服务器并让它发送记录在其二进制日志中的语句。
主服务器创建一个线程将二进制日志中的内容发送到从服务器。该线程可以识别为主服务器上SHOW PROCESSLIST的输出中的Binlog Dump线程。
从服务器I/O线程读取主服务器Binlog Dump线程发送的内容并将该数据拷贝到从服务器数据目录中的本地文件中，即中继日志。
第3个线程是SQL线程，是从服务器创建用于读取中继日志并执行日志中包含的更新。
有多个从服务器的主服务器创建为每个当前连接的从服务器创建一个线程；每个从服务器有自己的I/O和SQL线程。
二。复制线程的状态
1.复制主线程的状态
Sending binlog event to slave
二进制日志由各种事件组成，一个事件通常为一个更新加一些其它信息。线程已经从二进制日志读取了一个事件并且正将它发送到从服务器。
Finished reading one binlog; switching to next binlog
线程已经读完二进制日志文件并且正打开下一个要发送到从服务器的日志文件。
Has sent all binlog to slave; waiting for binlog to be updated
线程已经从二进制日志读取所有主要的更新并已经发送到了从服务器。线程现在正空闲，等待由主服务器上新的更新导致的出现在二进制日志中的新事件。
Waiting to finalize termination
线程停止时发生的一个很简单的状态。
2.复制从I/O线程状态
Connecting to master
线程正试图连接主服务器。
Checking master version
建立同主服务器之间的连接后立即临时出现的状态。
Registering slave on master
建立同主服务器之间的连接后立即临时出现的状态。
Requesting binlog dump
建立同主服务器之间的连接后立即临时出现的状态。线程向主服务器发送一条请求，索取从请求的二进制日志文件名和位置开始的二进制日志的内容。
Waiting to reconnect after a failed binlog dump request
如果二进制日志转储请求失败(由于没有连接)，线程进入睡眠状态，然后定期尝试重新连接。可以使用&#8211;master-connect-retry选项指定重试之间的间隔。
Reconnecting after a [...]]]></description>
			<content:encoded><![CDATA[<p>mysql的数据库的高可用性的架构大概有以下几种：集群，读写分离，主备。而后面两种都是通过复制来实现的。下面将简单介绍复制的原理及配置，以及一些常见的问题。<a href="http://www.imfeng.com/linux-deploy-mysql-master-and-slave/">mysql主从同步</a>，请参考<a href="http://www.imfeng.com/linux-deploy-mysql-master-and-slave/">http://www.imfeng.com/linux-deploy-mysql-master-and-slave/</a><span id="more-946"></span></p>
<p> </p>
<p align="right"> </p>
<p>一。复制的原理<br />
MySQL复制基于主服务器在二进制日志中跟踪所有对数据库的更改(更新、删除等等)。每个从服务器从主服务器接收主服务器已经记录到其二进制日志的保存的更新，以便从服务器可以对其数据拷贝执行相同的更新。<br />
将主服务器的数据拷贝到从服务器的一个途径是使用LOAD DATA FROM MASTER语句。请注意LOAD DATA FROM MASTER目前只在所有表使用MyISAM存储引擎的主服务器上工作。并且，该语句将获得全局读锁定。</p>
<p>MySQL使用3个线程来执行复制功能,其中1个在主服务器上，另两个在从服务器上。当发出START SLAVE时，从服务器创建一个I/O线程，以连接主服务器并让它发送记录在其二进制日志中的语句。<br />
主服务器创建一个线程将二进制日志中的内容发送到从服务器。该线程可以识别为主服务器上SHOW PROCESSLIST的输出中的Binlog Dump线程。<br />
从服务器I/O线程读取主服务器Binlog Dump线程发送的内容并将该数据拷贝到从服务器数据目录中的本地文件中，即中继日志。<br />
第3个线程是SQL线程，是从服务器创建用于读取中继日志并执行日志中包含的更新。<br />
有多个从服务器的主服务器创建为每个当前连接的从服务器创建一个线程；每个从服务器有自己的I/O和SQL线程。<br />
二。复制线程的状态</p>
<p>1.复制主线程的状态<br />
Sending binlog event to slave<br />
二进制日志由各种事件组成，一个事件通常为一个更新加一些其它信息。线程已经从二进制日志读取了一个事件并且正将它发送到从服务器。</p>
<p>Finished reading one binlog; switching to next binlog<br />
线程已经读完二进制日志文件并且正打开下一个要发送到从服务器的日志文件。</p>
<p>Has sent all binlog to slave; waiting for binlog to be updated<br />
线程已经从二进制日志读取所有主要的更新并已经发送到了从服务器。线程现在正空闲，等待由主服务器上新的更新导致的出现在二进制日志中的新事件。</p>
<p>Waiting to finalize termination<br />
线程停止时发生的一个很简单的状态。</p>
<p>2.复制从I/O线程状态<br />
Connecting to master<br />
线程正试图连接主服务器。</p>
<p>Checking master version<br />
建立同主服务器之间的连接后立即临时出现的状态。</p>
<p>Registering slave on master<br />
建立同主服务器之间的连接后立即临时出现的状态。</p>
<p>Requesting binlog dump<br />
建立同主服务器之间的连接后立即临时出现的状态。线程向主服务器发送一条请求，索取从请求的二进制日志文件名和位置开始的二进制日志的内容。</p>
<p>Waiting to reconnect after a failed binlog dump request<br />
如果二进制日志转储请求失败(由于没有连接)，线程进入睡眠状态，然后定期尝试重新连接。可以使用&#8211;master-connect-retry选项指定重试之间的间隔。</p>
<p>Reconnecting after a failed binlog dump request<br />
线程正尝试重新连接主服务器。</p>
<p>Waiting for master to send event<br />
线程已经连接上主服务器，正等待二进制日志事件到达。如果主服务器正空闲，会持续较长的时间。如果等待持续slave_read_timeout秒，则发生超时。此时，线程认为连接被中断并企图重新连接。</p>
<p>Queueing master event to the relay log<br />
线程已经读取一个事件，正将它复制到中继日志供SQL线程来处理。</p>
<p>Waiting to reconnect after a failed master event read<br />
读取时(由于没有连接)出现错误。线程企图重新连接前将睡眠master-connect-retry秒。</p>
<p>Reconnecting after a failed master event read<br />
线程正尝试重新连接主服务器。当连接重新建立后，状态变为Waiting for master to send event。</p>
<p>Waiting for the slave SQL thread to free enough relay log space<br />
正使用一个非零relay_log_space_limit值，中继日志已经增长到其组合大小超过该值。I/O线程正等待直到SQL线程处理中继日志内容并删除部分中继日志文件来释放足够的空间。</p>
<p>Waiting for slave mutex on exit<br />
线程停止时发生的一个很简单的状态。</p>
<p>3.复制从SQL线程状态<br />
Reading event from the relay log<br />
线程已经从中继日志读取一个事件，可以对事件进行处理了。</p>
<p>Has read all relay log; waiting for the slave I/O thread to update it<br />
线程已经处理了中继日志文件中的所有事件，现在正等待I/O线程将新事件写入中继日志。</p>
<p>Waiting for slave mutex on exit<br />
线程停止时发生的一个很简单的状态。<br />
三。复制传递和状态文件<br />
从服务器靠中继日志来接收从主服务器上传回来的日志。并依靠状态文件来记录已经从主服务器接收了哪些日志，已经恢复了哪些日志。</p>
<p>中继日志与二进制日志的格式相同，并且可以用mysqlbinlog读取。SQL线程执行完中继日志中的所有事件并且不再需要之后，立即自动删除它。可以采用&#8211;relay-log和&#8211;relay-log-index服务器选项覆盖默认中继日志和索引文件名。其中索引文件名的作用是记录目前正在使用中继日志。</p>
<p>在下面的条件下将创建新的中继日志：<br />
1.每次I/O线程启动时创建一个新的中继日志。<br />
2.当日志被刷新时；例如，用FLUSH LOGS或mysqladmin flush-logs。<br />
3.当当前的中继日志文件变得太大时。“太大”含义的确定方法：<br />
max_relay_log_size，如果max_relay_log_size &gt; 0<br />
max_binlog_size，如果max_relay_log_size = 0<br />
状态文件名默认为master.info和relay-log.info。其中IO线程更新master.info文件，SQL线程更新relay-log.info文件。<br />
文件中的行和SHOW SLAVE STATUS显示的列的对应关系为：<br />
master.info文件：<br />
行 描述<br />
1 文件中的行号<br />
2 Master_Log_File<br />
3 Read_Master_Log_Pos<br />
4 Master_Host<br />
5 Master_User<br />
6 密码(不由SHOW SLAVE STATUS显示)<br />
7 Master_Port<br />
8 Connect_Retry<br />
9 Master_SSL_Allowed<br />
10 Master_SSL_CA_File<br />
11 Master_SSL_CA_Path<br />
12 Master_SSL_Cert<br />
13 Master_SSL_Cipher<br />
14 Master_SSL_Key</p>
<p>relay-log.info文件：<br />
行 描述<br />
1 Relay_Log_File<br />
2 Relay_Log_Pos<br />
3 Relay_Master_Log_File<br />
4 Exec_Master_Log_Pos</p>
<p>当备份从服务器的数据时，你还应备份这两个小文件以及中继日志文件。它们用来在恢复从服务器的数据后继续进行复制。如果丢失了中继日志但仍然有relay-log.info文件，你可以通过检查该文件来确定SQL线程已经执行的主服务器中二进制日志的程度。然后可以用Master_Log_File和Master_LOG_POS选项执行CHANGE MASTER TO来告诉从服务器重新从该点读取二进制日志。当然，要求二进制日志仍然在主服务器上。所以最好建议将自动删除中继日志的特性关闭，手工写shell角本来防止空间满的问题。<br />
四。复制的配置步骤</p>
<p>1.创建专门用于复制的用户(建议这样做)，从服务器采用该帐户登陆主服务器：<br />
GRANT REPLICATION SLAVE ON *.* TO <a href="mailto:'rep'@'%'">&#8216;rep&#8217;@'%&#8217;</a> IDENTIFIED BY &#8216;logzgh&#8217;;</p>
<p>如果你计划从从属服务器主机使用LOAD TABLE FROM MASTER或LOAD DATA FROM MASTER语句，你需要授予该账户其它权限：<br />
授予账户SUPER和RELOAD全局权限。<br />
为所有想要装载的表授予SELECT权限。任何该 账户不能SELECT的主服务器上的表被LOAD DATA FROM MASTER忽略掉。</p>
<p>2.将数据库文件移到从服务器上<br />
情况一：若只用到MyISAM表<br />
mysql&gt; FLUSH TABLES WITH READ LOCK;<br />
(刷新所有表并且阻止其它写入，不要退出该客户端，以保持读锁有效。若退出，读锁就会释放。)<br />
比较简单的办法就是把数据目录打包压缩。<br />
$ tar -cvf /home/mysql/snapshot.tar ./data (在master上)<br />
$ tar -xvf /home/mysql/snapshot.tar (在slave上)<br />
可能不需要同步 mysql 数据库，因为在slave上的权限表和master不一样。这时，解开压缩包的时候要排除它。<br />
同时在压缩包中也不要包含任何日志文件，和状态文件master.info、relay-log.info。<br />
mysql&gt; SHOW MASTER STATUS;<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
| mysql-bin.000058 | 45036137 | | |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+</p>
<p>mysql&gt; UNLOCK TABLES;<br />
情况二：若用到InnoDB表<br />
方法一：使用InnoDB Hot Backup工具。它无需在master上请求任何锁就能做到快照的一致性，并且在后面中在slave上要用到的快照中已经记录了日志文件名以及偏移位置。 (<a href="http://www.innodb.com/manual.php">http://www.innodb.com/manual.php</a>)<br />
方法二：记录当前日志文件及偏移位置，在master关闭前执行：<br />
mysql&gt; FLUSH TABLES WITH READ LOCK;<br />
mysql&gt; SHOW MASTER STATUS;<br />
尽快记下显示结果中的日志文件及偏移位置。然后，在不解锁的情况下关闭master，确保master上的快照和记录的结果一致。<br />
关闭master服务器，$ mysqladmin -u root shutdown<br />
拷贝 InnoDB 数据文件，日志文件，以及表结构定义文件(.frm文件)。<br />
情况三：可以同时用于MyISAM和InnoDB表<br />
在master上做SQL转储而无需如上所述备份二进制日志。运行mysqldump &#8211;master-data命令，然后把结果文件转储到slave上。<br />
不过，这比拷贝二进制日志慢点。</p>
<p>3.修改my.cnf文件<br />
在master上my.cnf文件：(重启生效)<br />
[mysqld]<br />
log_bin<br />
server_id=1 (值是 1 到 2^32-1 之间的正整数)<br />
在slave上my.cnf文件：<br />
[mysqld]<br />
server_id=2 (ID必须和master的ID不同。若有多个slave，则每个slave都必须有唯一的id。)</p>
<p>配置slave的扩展选项<br />
master_host=db-master.mycompany.com<br />
master_port=3306<br />
master_user=rep<br />
master_password=freitag<br />
master_connect_retry=60 (若master宕机或者slave连接断开，slave会定期尝试连接到master上，重试的间隔由该选项来控制，默认值是60秒。)<br />
report_host=db-slave.mycompany.com<br />
slave_net_timeout=3600 (slave默认会在3600秒后，若还没收到来自master的数据，则会当作网络断开的情况来处理。)</p>
<p>服务器认为master.info的优先级比配置文件my.cnf高，<br />
第一次启动slave时，master.info不存在，它从my.cnf中读取选项值，然后把它们保存在master.info中。<br />
下次重启slave时，它只读取master.info的内容，而不会读取my.cnf中的选项值。<br />
想要使用不同的选项值，可以删除master.info后重启slave，或者使用CHANGE MASTER TO语句(推荐)重置选项值。<br />
4.启动从服务器线程<br />
mysqld_safe &#8211;user=mysql &#8211;skip-slave-start &amp; (启动MySQL服务器，但不启动slave)<br />
设置master_log_file等参数<br />
mysql&gt; CHANGE MASTER TO MASTER_HOST=&#8217;qa-sandbox-1&#8242;,<br />
MASTER_USER=&#8217;rep&#8217;,<br />
MASTER_PASSWORD=&#8217;logzgh&#8217;,<br />
MASTER_LOG_FILE=&#8217;mysql-bin.000007&#8242;,<br />
MASTER_LOG_POS=471632;</p>
<p>mysql&gt; START SLAVE；<br />
执行这些程序后，从服务器应连接主服务器，并补充自从快照以来发生的任何更新。<br />
如果你忘记设置主服务器的server-id值，从服务器不能连接主服务器。</p>
<p>注释：为了保证事务InnoDB复制设置的最大可能的耐受性和一致性，<br />
应在主服务器的my.cnf文件中使用innodb_flush_log_at_trx_commit=1和sync-binlog=1。</p>
<p>mysql&gt; show variables; (检查是否read-only，该选项令slave除了slave线程或者拥有SUPER权限用户之外的都不能更新数据，确保slave不会接受来自其他客户端的更新。)<br />
mysql&gt; show processlist; (检查是否slave-start)</p>
<p>在启动mysql的同时启动slave：<br />
mysqld_safe &#8211;user=mysql &#8211;read-only &amp; (启动MySQL服务器，同时启动slave的I/O线程)</p>
<p>mysql&gt; SHOW SLAVE STATUSG;</p>
<p>5.切换slave为master，在slave上：<br />
mysql&gt; STOP SLAVE;<br />
mysql&gt; RESET MASTER;<br />
五.复制启动选项</p>
<p>&#8211;read_only<br />
该选项让从服务器只允许来自从服务器线程或具有SUPER权限的用户的更新。可以确保从服务器不接受来自客户的更新。</p>
<p>&#8211;replicate_do_db=db_name<br />
告诉从服务器只做默认数据库(由USE所选择)为db_name的语句的复制。要指定多个数据库，应多次使用该选项，每个数据库使用一次。请注意不复制跨数据库的语句</p>
<p>&#8211;replicate_do_table=db_name.tbl_name<br />
告诉从服务器线程只做对指定表的复制。要指定多个表，应多次使用该选项，每个表使用一次。同&#8211;replicate-do-db对比，允许跨数据库更新。</p>
<p>&#8211;replicate_ignore_db=db_name<br />
告诉从服务器不要复制默认数据库(由USE所选择)为db_name的语句。要想忽略多个数据库，应多次使用该选项，每个数据库使用一次。</p>
<p>&#8211;replicate-ignore-table=db_name.tbl_name<br />
告诉从服务器线程不要复制更新指定表的任何语句(即使该语句可能更新其它的表)。要想忽略多个表，应多次使用该选项，每个表使用一次。</p>
<p>&#8211;replicate_wild_do_table=db_name.tbl_name<br />
告诉从服务器线程限制复制更新的表匹配指定的数据库和表名模式的语句。模式可以包含‘%’和‘_’通配符，与LIKE模式匹配操作符具有相同的含义。要指定多个表，应多次使用该选项，每个表使用一次。该选项可以跨数据库进行更新。</p>
<p>&#8211;replicate_wild_ignore_table=db_name.tbl_name<br />
告诉从服务器线程不要复制表匹配给出的通配符模式的语句。要想忽略多个表，应多次使用该选项，每个表使用一次。该选项可以跨数据库进行更新。</p>
<p>&#8211;replicate_rewrite_db=from_name-&gt;to_name<br />
告诉从服务器如果默认数据库(由USE所选择)为主服务器上的from_name，则翻译为to_name。只影响含有表的语句</p>
<p>&#8211;report_host=slave_name<br />
从服务器注册过程中报告给主服务器的主机名或IP地址。该值出现在主服务器上SHOW SLAVE HOSTS的输出中。如果不想让从服务器自己在主服务器上注册，则不设置该值。</p>
<p>&#8211;report_port=slave_port<br />
连接从服务器的TCP/IP端口号，从服务器注册过程中报告给主服务器。</p>
<p>&#8211;skip_slave_start<br />
告诉从服务器当服务器启动时不启动从服务器线程。使用START SLAVE语句在以后启动线程。</p>
<p>&#8211;slave_skip_errors=[err_code1,err_code2,... | all]<br />
通常情况，当出现错误时复制停止，这样给你一个机会手动解决数据中的不一致性问题。该选项告诉从服务器SQL线程当语句返回任何选项值中所列的错误时继续复制。<br />
例如：<br />
&#8211;slave-skip-errors=1062,1053<br />
&#8211;slave-skip-errors=all</p>
<p>六.不停机配置复制的方法</p>
<p>方法一：<br />
如果你在某时间点做过主服务器备份并且记录了相应快照的二进制日志名和偏移量(通过SHOW MASTER STATUS命令的输出)，采用下面的步骤：</p>
<p>1. 确保从服务器分配了一个唯一的服务器ID号。<br />
2. 将备份文件拷到从服务器上。<br />
3. 在从服务器上执行下面的语句，为每个选项填入适当的值：<br />
mysql&gt; CHANGE MASTER TO<br />
-&gt; MASTER_HOST=&#8217;master_host_name&#8217;,<br />
-&gt; MASTER_USER=&#8217;master_user_name&#8217;,<br />
-&gt; MASTER_PASSWORD=&#8217;master_pass&#8217;,<br />
-&gt; MASTER_LOG_FILE=&#8217;recorded_log_file_name&#8217;,<br />
-&gt; MASTER_LOG_POS=recorded_log_position;</p>
<p>4.在从服务器上执行START SLAVE语句。</p>
<p>如果你没有备份主服务器，这里是一个创建备份的快速程序。所有步骤都应该在主服务器主机上执行。</p>
<p>1. 发出该语句：<br />
mysql&gt; FLUSH TABLES WITH READ LOCK；<br />
2. 仍然加锁时，执行该命令（或它的变体）：<br />
shell&gt; tar zcf /tmp/backup.tar.gz /var/lib/mysql<br />
并拷到从服务器上。<br />
3. 发出该语句并且确保记录了以后用到的输出：<br />
mysql&gt;SHOW MASTER STATUS；<br />
4. 释放锁：<br />
mysql&gt; UNLOCK TABLES；</p>
<p>方法二：<br />
一个可选择的方法是，转储主服务器的SQL来代替前面步骤中的二进制复制。要这样做，你可以在主服务器上使用mysqldump &#8211;master-data，以后装载SQL转储到到你的从服务器。然而，这比进行二进制复制速度慢。</p>
<p> </p>
<p>七.其他</p>
<p>1.不能从使用新二进制日志格式的主服务器向使用旧二进制日志格式的从服务器复制。<br />
2.升级从服务器时，应先关闭从服务器，升级到相应5.1.x版本，然后重启从服务器并重新开始复制。5.1版本的从服务器能够读取升级前写入的旧的中继日志并执行日志中包含的语句。升级后从服务器创建的中继日志为5.1格式。</p>
<p>3.必须在主服务器和从服务器上总是使用相同的全局字符集和校对规则(&#8211;default-character-set、&#8211;default-collation)。否则，会在从服务器上遇到复制键值错误，因为在主服务器的字符集中被认为是唯一的键值在从服务器的字符集中可能不是唯一的。<br />
4.Q：从服务器需要始终连接到主服务器吗？<br />
A：不，不需要。从服务器可以宕机或断开连接几个小时甚至几天，重新连接后获得更新信息。</p>
<p>5.Q：我怎样知道从服务器与主服务器的最新比较? 换句话说，我怎样知道从服务器复制的最后一个查询的日期？<br />
A：你可以查看SHOW SLAVE STATUS语句的Seconds_Behind_Master列的结果。</p>
<p>6. Q：我怎样强制主服务器阻塞更新直到从服务器同步？<br />
A：使用下面的步骤：<br />
1. 在主服务器上，执行这些语句：<br />
mysql&gt; FLUSH TABLES WITH READ LOCK;<br />
mysql&gt; SHOW MASTER STATUS;<br />
记录SHOW语句的输出的日志名和偏移量。这些是复制坐标。</p>
<p>2.在从服务器上，发出下面的语句，其中Master_POS_WAIT()函数的参量是前面步骤中的得到的复制坐标值：<br />
mysql&gt; SELECT MASTER_POS_WAIT(&#8217;log_name&#8217;, log_offset);<br />
SELECT语句阻塞直到从服务器达到指定的日志文件和偏移量。此时，从服务器与主服务器同步，语句返回。</p>
<p>3.在主服务器上，发出下面的语句允许主服务器重新开始处理更新：<br />
mysql&gt; UNLOCK TABLES；</p>
<p>7.Q：怎样通过复制来提高系统的性能？<br />
A：你应将一个服务器设置为主服务器并且将所有写指向该服务器。然后根据预算配置尽可能多的从服务器以及栈空间，并且在主服务器和从服务器之间分发读取操作。你也可以用&#8211;skip-innodb、&#8211;skip-bdb、&#8211;low-priority-updates以及&#8211;delay-key-write=ALL选项启动从服务器，以便在从服务器端提高速度。在这种情况下，为了提高速度，从服务器使用非事务MyISAM表来代替InnoDB和BDB表。</p>
<p>转载:<a href="http://logzgh.itpub.net/post/3185/453268">http://logzgh.itpub.net/post/3185/453268</a></p>
Here is no comments yet by the time  your rss reader get this, Do you want to be the first commentor? Hurry up ]]></content:encoded>
			<wfw:commentRss>http://www.imfeng.com/mysql%e7%9a%84%e5%a4%8d%e5%88%b6%e5%8e%9f%e7%90%86%e5%8f%8a%e9%85%8d%e7%bd%ae/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux中Apache性能优化 小试牛角</title>
		<link>http://www.imfeng.com/linux-apache-youhua-bingfa/</link>
		<comments>http://www.imfeng.com/linux-apache-youhua-bingfa/#comments</comments>
		<pubDate>Tue, 03 Jan 2012 17:47:22 +0000</pubDate>
		<dc:creator>枫子</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[服务器]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[httpd.conf]]></category>
		<category><![CDATA[性能优化]]></category>

		<guid isPermaLink="false">http://www.imfeng.com/?p=942</guid>
		<description><![CDATA[具体是怎么进行优化的，我不是很清楚，直接放代码，已经测试，PHP速度明显变快了很多，负载也降下来了。

hostnamelookups off
options -followsymlinks
options -indexes
#allowoverride none
timeout 5
keepalive on
maxkeepaliverequests 500
keepalivetimeout 5
serversignature off
StartServers 20
MaxClients 800
servertokens prod

httpd.conf
具体含义可以参考:http://www.myhack58.com/Article/sort099/sort0100/2011/32655.htm
Here is no comments yet by the time  your rss reader get this, Do you want to be the first commentor? Hurry up ]]></description>
			<content:encoded><![CDATA[<p>具体是怎么进行优化的，我不是很清楚，直接放代码，已经测试，PHP速度明显变快了很多，负载也降下来了。<span id="more-942"></span></p>
<pre class="brush: php; title: ;">
hostnamelookups off
options -followsymlinks
options -indexes
#allowoverride none
timeout 5
keepalive on
maxkeepaliverequests 500
keepalivetimeout 5
serversignature off
StartServers 20
MaxClients 800
servertokens prod
</pre>
<p>httpd.conf</p>
<p>具体含义可以参考:<a href="http://www.myhack58.com/Article/sort099/sort0100/2011/32655.htm">http://www.myhack58.com/Article/sort099/sort0100/2011/32655.htm</a></p>
Here is no comments yet by the time  your rss reader get this, Do you want to be the first commentor? Hurry up ]]></content:encoded>
			<wfw:commentRss>http://www.imfeng.com/linux-apache-youhua-bingfa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux修改系统时间</title>
		<link>http://www.imfeng.com/linux-set-date/</link>
		<comments>http://www.imfeng.com/linux-set-date/#comments</comments>
		<pubDate>Fri, 30 Dec 2011 13:05:55 +0000</pubDate>
		<dc:creator>枫子</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[服务器]]></category>
		<category><![CDATA[修改]]></category>
		<category><![CDATA[时间]]></category>
		<category><![CDATA[系统]]></category>

		<guid isPermaLink="false">http://www.imfeng.com/?p=932</guid>
		<description><![CDATA[基本上服务器都是国外的了，在安装lnmpa的时候，军哥已经在shell里面写了命令修改系统时间，设置时区为东八区。
但是，难免有些变态的服务器，简单的命令搞不定它。
常见的修改系统时间命令:


rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

然后date一下，看是否对了。如果还不行，试试下面这个杀手锏:


ntpdate stdtime.sinica.edu.tw

如果没有安装ntpdate的话 请用下面命令安装：


yum -y install ntpdate ntp

写入主板的rtc芯片 设置硬件时间

hwclock -w

查看硬件时间

hwclock --show

硬件时间和系统时间同步

hwclock --hctosys

系统时间和硬件时间同步

hwclock --systohc


 




Here is no comments yet by the time  your rss reader get this, Do you want to be the first commentor? Hurry up ]]></description>
			<content:encoded><![CDATA[<p>基本上服务器都是国外的了，在安装<a href="http://www.imfeng.com/lnmpa-install-mark/">lnmpa</a>的时候，军哥已经在shell里面写了命令修改系统时间，设置时区为东八区。<span id="more-932"></span></p>
<p>但是，难免有些变态的服务器，简单的命令搞不定它。</p>
<p>常见的修改系统时间命令:</p>
<pre class="brush: php; title: ;">

rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
</pre>
<p>然后date一下，看是否对了。如果还不行，试试下面这个杀手锏:</p>
<pre class="brush: php; title: ;">

ntpdate stdtime.sinica.edu.tw
</pre>
<p>如果没有安装ntpdate的话 请用下面命令安装：</p>
<pre class="brush: php; title: ;">

yum -y install ntpdate ntp
</pre>
<p>写入主板的rtc芯片 设置硬件时间</p>
<pre class="brush: php; title: ;">
hwclock -w
</pre>
<p>查看硬件时间</p>
<pre class="brush: php; title: ;">
hwclock --show
</pre>
<pre>硬件时间和系统时间同步
<pre class="brush: php; title: ;">
hwclock --hctosys
</pre>
<pre>系统时间和硬件时间同步
<pre class="brush: php; title: ;">
hwclock --systohc
</pre>
</pre>
<p> </pre>
</pre>
</pre>
</pre>
</pre>
Here is no comments yet by the time  your rss reader get this, Do you want to be the first commentor? Hurry up ]]></content:encoded>
			<wfw:commentRss>http://www.imfeng.com/linux-set-date/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux一键rsync配置实现文件同步</title>
		<link>http://www.imfeng.com/linux-setup-rsync-server/</link>
		<comments>http://www.imfeng.com/linux-setup-rsync-server/#comments</comments>
		<pubDate>Thu, 29 Dec 2011 14:12:28 +0000</pubDate>
		<dc:creator>枫子</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[服务器]]></category>
		<category><![CDATA[rsync]]></category>
		<category><![CDATA[一键]]></category>
		<category><![CDATA[同步]]></category>
		<category><![CDATA[配置]]></category>

		<guid isPermaLink="false">http://www.imfeng.com/?p=923</guid>
		<description><![CDATA[昨天搞定了数据库同步，今天理所应当就要搞定好文件同步。
主服务器

wget -c http://www.imfeng.com/downforlnmpa/rsync/rsserver.sh
chmod +x rsserver.sh
./rsserver.sh

会提示输入
帐号
密码
服务器IP地址
同步服务器IP地址
同步文件路径
然后会自动安装好
同步服务器

wget -c http://www.imfeng.com/downforlnmpa/rsync/rshost.sh
chmod +x rshost.sh
./rshost.sh

显示完成之后
用下面命令可以开始同步

rsync -avz --delete --password-file=/etc/rsyncd/rsyncd.secrets rsync://帐号@服务器IP地址/fengzi 同步文件路径

例如:

rsync -avz --delete --password-file=/etc/rsyncd/rsyncd.secrets rsync://fengzi@110.120.119.250/fengzi /home/wwwroot

参考:
http://www.blogjava.net/jasmine214&#8211;love/archive/2011/10/28/362222.html
http://bbs.vpser.net/thread-5647-1-1.html
http://blog.lixiphp.com/solve-rsync-auth-failed-on-module/
http://os.51cto.com/art/200903/113682.htm
############################################################
如果您看完文章，自己测试还是不成功，可以购买枫子的收费服务。

请注明 rsync同步 50元部署文件同步。
Here is no comments yet by the time  your rss reader get this, Do you want to be the first commentor? Hurry up ]]></description>
			<content:encoded><![CDATA[<p>昨天搞定了<a href="http://www.imfeng.com/linux-deploy-mysql-master-and-slave/">数据库同步</a>，今天理所应当就要搞定好<a href="http://www.imfeng.com/linux-setup-rsync-server/">文件同步</a>。<span id="more-923"></span></p>
<p>主服务器</p>
<pre class="brush: php; title: ;">
wget -c http://www.imfeng.com/downforlnmpa/rsync/rsserver.sh
chmod +x rsserver.sh
./rsserver.sh
</pre>
<p>会提示输入<br />
帐号<br />
密码<br />
服务器IP地址<br />
同步服务器IP地址<br />
同步文件路径</p>
<p>然后会自动安装好</p>
<p>同步服务器</p>
<pre class="brush: php; title: ;">
wget -c http://www.imfeng.com/downforlnmpa/rsync/rshost.sh
chmod +x rshost.sh
./rshost.sh
</pre>
<p>显示完成之后</p>
<p>用下面命令可以开始同步</p>
<pre class="brush: php; title: ;">
rsync -avz --delete --password-file=/etc/rsyncd/rsyncd.secrets rsync://帐号@服务器IP地址/fengzi 同步文件路径
</pre>
<p>例如:</p>
<pre class="brush: php; title: ;">
rsync -avz --delete --password-file=/etc/rsyncd/rsyncd.secrets rsync://fengzi@110.120.119.250/fengzi /home/wwwroot
</pre>
<p>参考:</p>
<p><a href="http://www.blogjava.net/jasmine214--love/archive/2011/10/28/362222.html">http://www.blogjava.net/jasmine214&#8211;love/archive/2011/10/28/362222.html</a></p>
<p><a href="http://bbs.vpser.net/thread-5647-1-1.html">http://bbs.vpser.net/thread-5647-1-1.html</a></p>
<p><a href="http://blog.lixiphp.com/solve-rsync-auth-failed-on-module/">http://blog.lixiphp.com/solve-rsync-auth-failed-on-module/</a></p>
<p><a href="http://os.51cto.com/art/200903/113682.htm">http://os.51cto.com/art/200903/113682.htm</a></p>
<p>############################################################</p>
<p>如果您看完文章，自己测试还是不成功，可以购买枫子的收费服务。</p>
<p><img src="http://www.imfeng.com/upload/beian7.jpg" alt="批量查询域名备案" width="396" height="153" /></p>
<p>请注明 rsync同步 50元部署文件同步。</p>
Here is no comments yet by the time  your rss reader get this, Do you want to be the first commentor? Hurry up ]]></content:encoded>
			<wfw:commentRss>http://www.imfeng.com/linux-setup-rsync-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux部署Mysql数据库主从同步</title>
		<link>http://www.imfeng.com/linux-deploy-mysql-master-and-slave/</link>
		<comments>http://www.imfeng.com/linux-deploy-mysql-master-and-slave/#comments</comments>
		<pubDate>Wed, 28 Dec 2011 16:59:52 +0000</pubDate>
		<dc:creator>枫子</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[SQL数据库]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[同步]]></category>

		<guid isPermaLink="false">http://www.imfeng.com/?p=918</guid>
		<description><![CDATA[搞了一天，最后没办法，在hostloc和im286还有微博里面求救，有一个hostloc的朋友(醒醒)加我QQ，帮了挺多的，再次感谢。
最后，我们实在找不到问题的所在，我还原了主服务器和从服务器的my.cnf，一步一步来。
主服务器IP: 250.110.120.119
从服务器IP: 110.120.119.250
1.在主服务器新建一个用户，给从服务器同步使用。


GRANT ALL PRIVILEGES ON *.* TO 'tongbu'@'110.120.119.250.' IDENTIFIED BY 'tongbu';

意思是新建一个用户名为tongbu 密码为tongbu 具有所有操作权限的帐号。
2.修改主服务器my.cnf文件
其实这一步可以省略，因为保持默认的配置文件就可以了。
/*
添加
server-id=1
并开启log-bin二进制日志文件
log-bin=mysql-bin
注:需要把默认的server-id=1去掉
*/
3.重启主服务器mysql数据库
4.进入mysql界面执行下面命令 获取日志文件名和偏移量

show master status;

显示如:
mysql&#62; show master status;
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+
&#124; File &#124; Position &#124; Binlog_Do_DB &#124; Binlog_Ignore_DB &#124;
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+
&#124; mysql-bin.000010 &#124; 106 &#124; &#124; &#124;
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+
1 row in set (0.00 sec)
得到的日志文件名为 mysql-bin.000010 偏移量为106
5.修改从服务器的my.cnf
添加一个
server-id=2
注:需要把默认的server-id=1去掉
6.重启从服务器mysql数据库
7.对从数据库进行设置，@@@这是最最重要的地方。


change master to master_host='250.110.120.119', master_user='tongbu', master_password='tongbu', master_log_file='mysql-bin.000010', master_log_pos=106;

8.启动从服务器

start slave;

9.执行下面命令 查看进程

show processlist\G

显示如下
mysql&#62; show processlist\G
*************************** 1. row [...]]]></description>
			<content:encoded><![CDATA[<p>搞了一天，最后没办法，在hostloc和im286还有微博里面求救，有一个<a href="http://www.hostloc.com/thread-98183-1-2.html">hostloc</a>的朋友(醒醒)加我QQ，帮了挺多的，再次感谢。<span id="more-918"></span></p>
<p>最后，我们实在找不到问题的所在，我还原了主服务器和从服务器的my.cnf，一步一步来。</p>
<p>主服务器IP: 250.110.120.119<br />
从服务器IP: 110.120.119.250</p>
<p>1.在主服务器新建一个用户，给从服务器同步使用。</p>
<pre class="brush: php; title: ;">

GRANT ALL PRIVILEGES ON *.* TO 'tongbu'@'110.120.119.250.' IDENTIFIED BY 'tongbu';
</pre>
<p>意思是新建一个用户名为tongbu 密码为tongbu 具有所有操作权限的帐号。</p>
<p>2.修改主服务器my.cnf文件<br />
其实这一步可以省略，因为保持默认的配置文件就可以了。<br />
/*<br />
添加<br />
server-id=1<br />
并开启log-bin二进制日志文件<br />
log-bin=mysql-bin<br />
注:需要把默认的server-id=1去掉<br />
*/</p>
<p>3.重启主服务器mysql数据库</p>
<p>4.进入mysql界面执行下面命令 获取日志文件名和偏移量</p>
<pre class="brush: php; title: ;">
show master status;
</pre>
<p>显示如:<br />
mysql&gt; show master status;<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
| <span style="color: #ff0000;">mysql-bin.000010 | 106</span> | | |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
1 row in set (0.00 sec)</p>
<p>得到的日志文件名为 mysql-bin.000010 偏移量为106</p>
<p>5.修改从服务器的my.cnf<br />
添加一个<br />
server-id=2<br />
注:需要把默认的server-id=1去掉</p>
<p>6.重启从服务器mysql数据库</p>
<p>7.对从数据库进行设置，@@@这是最最重要的地方。</p>
<pre class="brush: php; title: ;">

change master to master_host='250.110.120.119', master_user='tongbu', master_password='tongbu', master_log_file='mysql-bin.000010', master_log_pos=106;
</pre>
<p>8.启动从服务器</p>
<pre class="brush: php; title: ;">
start slave;
</pre>
<p>9.执行下面命令 查看进程</p>
<pre class="brush: php; title: ;">
show processlist\G
</pre>
<p>显示如下<br />
mysql&gt; <span style="color: #ff0000;">show processlist\G<br />
</span>*************************** 1. row ***************************<br />
Id: 4<br />
User: root<br />
Host: localhost<br />
db: test<br />
Command: Query<br />
Time: 0<br />
State: NULL<br />
Info: show processlist<br />
*************************** 2. row ***************************<br />
Id: 5<br />
User: system user<br />
Host:<br />
db: NULL<br />
Command: Connect<br />
Time: 1773<br />
State: Waiting for master to send event<br />
Info: NULL<br />
*************************** 3. row ***************************<br />
Id: 6<br />
User: system user<br />
Host:<br />
db: NULL<br />
Command: Connect<br />
Time: 1630<br />
State: <span style="color: #ff0000;">Has read all relay log; waiting for the slave I/O thread to update it<br />
</span>Info: NULL<br />
3 rows in set (0.00 sec)</p>
<p>10.查看从服务器状态</p>
<pre class="brush: php; title: ;">
show slave status\G
</pre>
<p>显示如下<br />
mysql&gt; show slave status\G<br />
*************************** 1. row ***************************<br />
<span style="color: #ff0000;">Slave_IO_State: Waiting for master to send event<br />
</span>Master_Host: 250.110.120.119<br />
Master_User: tongbu<br />
Master_Port: 3306<br />
Connect_Retry: 60<br />
Master_Log_File: mysql-bin.000010<br />
Read_Master_Log_Pos: 281<br />
Relay_Log_File: up2-relay-bin.000002<br />
Relay_Log_Pos: 426<br />
Relay_Master_Log_File: mysql-bin.000010<br />
<span style="color: #ff0000;">Slave_IO_Running: Yes<br />
Slave_SQL_Running: Yes<br />
</span>Replicate_Do_DB:<br />
Replicate_Ignore_DB:<br />
Replicate_Do_Table:<br />
Replicate_Ignore_Table:<br />
Replicate_Wild_Do_Table:<br />
Replicate_Wild_Ignore_Table:<br />
Last_Errno: 0<br />
Last_Error:<br />
Skip_Counter: 0<br />
Exec_Master_Log_Pos: 281<br />
Relay_Log_Space: 579<br />
Until_Condition: None<br />
Until_Log_File:<br />
Until_Log_Pos: 0<br />
Master_SSL_Allowed: No<br />
Master_SSL_CA_File:<br />
Master_SSL_CA_Path:<br />
Master_SSL_Cert:<br />
Master_SSL_Cipher:<br />
Master_SSL_Key:<br />
Seconds_Behind_Master: 0<br />
Master_SSL_Verify_Server_Cert: No<br />
Last_IO_Errno: 0<br />
Last_IO_Error:<br />
Last_SQL_Errno: 0<br />
Last_SQL_Error:<br />
1 row in set (0.00 sec)</p>
<p>测试:<br />
1、在主服务器test数据库中创建user表<br />
mysql&gt;use test;<br />
mysql&gt;create table user(id int);<br />
2、在从服务器中查看user表<br />
mysql&gt;use test;<br />
mysql&gt; show tables like ‘user’;<br />
+———————-+<br />
| Tables_in_test(user) |<br />
+———————-+<br />
| user |<br />
+———————-+<br />
1 row in set (0.00 sec)<br />
说明主从数据同步成功。</p>
<p>部分参考:<a href="http://database.51cto.com/art/201009/223213.htm">http://database.51cto.com/art/201009/223213.htm</a></p>
<p>附录:</p>
<pre class="brush: php; title: ;">

cp /usr/local/mysql/share/mysql/my-medium.cnf  /etc/my.cnf

/usr/local/mysql/bin/mysql -u root -p

show master status;

show variables like 'server_id';

set global server_id=2;

slave start;

slave stop;

show slave status\G

show processlist\G

flush privileges;

/usr/local/mysql/bin/mysql -h110.120.119.250 -uroot -proot123
</pre>
<p>############################################################</p>
<p>如果您看完文章，自己测试还是不成功，可以购买枫子的收费服务。</p>
<p><img src="http://www.imfeng.com/upload/beian7.jpg" alt="批量查询域名备案" width="396" height="153" /></p>
<p>请注明 mysql同步 50元部署主从实时同步。</p>
By the time  your rss reader get this post here is <strong> 3 </strong>comments ,Welcome you come to leave your opinion !]]></content:encoded>
			<wfw:commentRss>http://www.imfeng.com/linux-deploy-mysql-master-and-slave/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Linux 利用SFTP传输文件</title>
		<link>http://www.imfeng.com/linux-sftp-files/</link>
		<comments>http://www.imfeng.com/linux-sftp-files/#comments</comments>
		<pubDate>Mon, 05 Dec 2011 16:12:58 +0000</pubDate>
		<dc:creator>枫子</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[SFTP]]></category>

		<guid isPermaLink="false">http://www.imfeng.com/?p=902</guid>
		<description><![CDATA[基本上记得2个命令就可以了
put 上传
get 下载
其它命令:
cd 路径                        更改远程目录到“路径”
lcd 路径                       更改本地目录到“路径”
chgrp group path  [...]]]></description>
			<content:encoded><![CDATA[<p>基本上记得2个命令就可以了<br />
put 上传<br />
get 下载<span id="more-902"></span></p>
<p>其它命令:<br />
cd 路径                        更改远程目录到“路径”<br />
lcd 路径                       更改本地目录到“路径”<br />
chgrp group path               将文件“path”的组更改为“group”<br />
chmod mode path                将文件“path”的权限更改为“mode”<br />
chown owner path               将文件“path”的属主更改为“owner”<br />
exit                           退出 sftp<br />
help                           显示这个帮助文本<br />
get 远程路径                   下载文件<br />
ln existingpath linkpath       符号链接远程文件<br />
ls [选项] [路径]               显示远程目录列表<br />
lls [选项] [路径]              显示本地目录列表<br />
mkdir 路径                     创建远程目录<br />
lmkdir 路径                    创建本地目录<br />
mv oldpath newpath             移动远程文件<br />
open [用户@]主机[:端口]        连接到远程主机<br />
put 本地路径                   上传文件<br />
pwd                            显示远程工作目录<br />
lpwd                           打印本地工作目录<br />
quit                           退出 sftp<br />
rmdir 路径                     移除远程目录<br />
lrmdir 路径                    移除本地目录<br />
rm 路径                        删除远程文件<br />
lrm 路径                       删除本地文件<br />
symlink existingpath linkpath  符号链接远程文件<br />
version                        显示协议版本</p>
Here is no comments yet by the time  your rss reader get this, Do you want to be the first commentor? Hurry up ]]></content:encoded>
			<wfw:commentRss>http://www.imfeng.com/linux-sftp-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mysql 出现Table &#8216;xxx&#8217; is read only 解决办法</title>
		<link>http://www.imfeng.com/mysql-got-table-xxx-is-read-only/</link>
		<comments>http://www.imfeng.com/mysql-got-table-xxx-is-read-only/#comments</comments>
		<pubDate>Mon, 05 Dec 2011 14:17:48 +0000</pubDate>
		<dc:creator>枫子</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[SQL数据库]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[解决]]></category>

		<guid isPermaLink="false">http://www.imfeng.com/?p=900</guid>
		<description><![CDATA[在Linux下面执行下面命令就可以了，当然你要找到你的mysql目录
/usr/local/mysql/bin/mysqladmin -u root -p flush-tables
如果你是Windows的话，登录mysql 然后执行 flush-tables 即可。
Here is no comments yet by the time  your rss reader get this, Do you want to be the first commentor? Hurry up ]]></description>
			<content:encoded><![CDATA[<p>在Linux下面执行下面命令就可以了，当然你要找到你的mysql目录</p>
<pre class="brush: php; title: ;">/usr/local/mysql/bin/mysqladmin -u root -p flush-tables</pre>
<p>如果你是Windows的话，登录mysql 然后执行 flush-tables 即可。</p>
Here is no comments yet by the time  your rss reader get this, Do you want to be the first commentor? Hurry up ]]></content:encoded>
			<wfw:commentRss>http://www.imfeng.com/mysql-got-table-xxx-is-read-only/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux 查看并发数</title>
		<link>http://www.imfeng.com/linux-check-concurrent/</link>
		<comments>http://www.imfeng.com/linux-check-concurrent/#comments</comments>
		<pubDate>Tue, 29 Nov 2011 15:01:02 +0000</pubDate>
		<dc:creator>枫子</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[并发数]]></category>

		<guid isPermaLink="false">http://www.imfeng.com/?p=895</guid>
		<description><![CDATA[在Linux中查看并发数的命令:


netstat -n &#124; awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'

解释:
返回结果示例： 
　　LAST_ACK 5   (正在等待处理的请求数) 
　　SYN_RECV 30 
　　ESTABLISHED 1597 (正常数据传输状态) 
　　FIN_WAIT1 51 
　　FIN_WAIT2 504 
　　TIME_WAIT 1057 (处理完毕，等待超时结束的请求数) 
 
　　状态：描述 
　　CLOSED：无连接是活动的或正在进行 
　　LISTEN：服务器在等待进入呼叫 
　　SYN_RECV：一个连接请求已经到达，等待确认 
　　SYN_SENT：应用已经开始，打开一个连接 
　　ESTABLISHED：正常数据传输状态 
　　FIN_WAIT1：应用说它已经完成 
　　FIN_WAIT2：另一边已同意释放 
　　ITMED_WAIT：等待所有分组死掉 
　　CLOSING：两边同时尝试关闭 
　　TIME_WAIT：另一边已初始化一个释放 
　　LAST_ACK：等待所有分组死掉
Here is no comments yet by the time  your rss reader get this, Do you want to be the first commentor? Hurry up ]]></description>
			<content:encoded><![CDATA[<p>在Linux中查看并发数的命令:<span id="more-895"></span></p>
<pre class="brush: php; title: ;">

netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
</pre>
<p>解释:</p>
<p>返回结果示例： <br />
　　LAST_ACK 5   (正在等待处理的请求数) <br />
　　SYN_RECV 30 <br />
　　ESTABLISHED 1597 (正常数据传输状态) <br />
　　FIN_WAIT1 51 <br />
　　FIN_WAIT2 504 <br />
　　TIME_WAIT 1057 (处理完毕，等待超时结束的请求数) <br />
 <br />
　　状态：描述 <br />
　　CLOSED：无连接是活动的或正在进行 <br />
　　LISTEN：服务器在等待进入呼叫 <br />
　　SYN_RECV：一个连接请求已经到达，等待确认 <br />
　　SYN_SENT：应用已经开始，打开一个连接 <br />
　　ESTABLISHED：正常数据传输状态 <br />
　　FIN_WAIT1：应用说它已经完成 <br />
　　FIN_WAIT2：另一边已同意释放 <br />
　　ITMED_WAIT：等待所有分组死掉 <br />
　　CLOSING：两边同时尝试关闭 <br />
　　TIME_WAIT：另一边已初始化一个释放 <br />
　　LAST_ACK：等待所有分组死掉</p>
Here is no comments yet by the time  your rss reader get this, Do you want to be the first commentor? Hurry up ]]></content:encoded>
			<wfw:commentRss>http://www.imfeng.com/linux-check-concurrent/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux cp -rf复制提示覆盖 完美解决</title>
		<link>http://www.imfeng.com/linux-cp-rf-copy-no-tips/</link>
		<comments>http://www.imfeng.com/linux-cp-rf-copy-no-tips/#comments</comments>
		<pubDate>Thu, 24 Nov 2011 17:19:07 +0000</pubDate>
		<dc:creator>枫子</dc:creator>
				<category><![CDATA[生活日记]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[解决]]></category>

		<guid isPermaLink="false">http://www.imfeng.com/?p=892</guid>
		<description><![CDATA[平常在Linux中使用 cp 命令时,会发现将一个目录中文件复制到另一个目录具有相同文件名称时,即使添加了 -rf 参数强制覆盖复制时,系统仍然会提示让你一个个的手工输入 y 确认复制。
很麻烦，解决办法很简单：
 unalias cp 
去掉cp别名。
恢复方法也简单
alias cp='cp -i'
Here is no comments yet by the time  your rss reader get this, Do you want to be the first commentor? Hurry up ]]></description>
			<content:encoded><![CDATA[<p>平常在Linux中使用 cp 命令时,会发现将一个目录中文件复制到另一个目录具有相同文件名称时,即使添加了 -rf 参数强制覆盖复制时,系统仍然会提示让你一个个的手工输入 y 确认复制。<span id="more-892"></span></p>
<p>很麻烦，解决办法很简单：</p>
<pre class="brush: php; title: ;"> unalias cp </pre>
<p>去掉cp别名。</p>
<p>恢复方法也简单</p>
<pre class="brush: php; title: ;">alias cp='cp -i'</pre>
Here is no comments yet by the time  your rss reader get this, Do you want to be the first commentor? Hurry up ]]></content:encoded>
			<wfw:commentRss>http://www.imfeng.com/linux-cp-rf-copy-no-tips/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux查看当前文件夹下面占用空间最大的文件夹</title>
		<link>http://www.imfeng.com/linux-du-max/</link>
		<comments>http://www.imfeng.com/linux-du-max/#comments</comments>
		<pubDate>Mon, 17 Oct 2011 16:53:53 +0000</pubDate>
		<dc:creator>枫子</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[du]]></category>
		<category><![CDATA[占用空间]]></category>

		<guid isPermaLink="false">http://www.imfeng.com/?p=850</guid>
		<description><![CDATA[命令:
 du --max-depth=1 -h 
Here is no comments yet by the time  your rss reader get this, Do you want to be the first commentor? Hurry up ]]></description>
			<content:encoded><![CDATA[<p>命令:</p>
<pre class="brush: php; title: ;"> du --max-depth=1 -h </pre>
Here is no comments yet by the time  your rss reader get this, Do you want to be the first commentor? Hurry up ]]></content:encoded>
			<wfw:commentRss>http://www.imfeng.com/linux-du-max/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

