2. 传送文件作为邮件附件.
使用matt 客户端,一行即可完成:
echo “Content” | mutt -s “Subject” -a file email@address.demo
这个方法对及时传输一些小文件非常有效, 特别是传送源代码. 还能起到存档备份的效果, 反正Gmail 那么大不用也浪费. 懒人还可以进一步用一个脚本包装, 比如我机器上就包装出了一个 sendboss.sh, 里面是:
echo “Hi, These are the file(s), thanks. Eric” | mutt -s “File” -a $* myboss_email@wustl.edu
这样我每次就只要 “sendboss.sh files” 就可以了. 我老板常常惊讶于我发送文件的反应速度.
3. 一行语句的HTTP文件服务器.
python -m SimpleHTTPServer
即可将当前目录开设为一个8000端口的http 服务器的根目录. 在局域网中,如果需要临时共享当前目录下的一个较大文件,这个方法简便安全,实在是居家旅行必备.
还有, 下载的时候使用 “wget -c” 可以断点续传,很多哥们好像不知道这个小花招.
考虑到以下情况:
1)安装系统时难以确定内存的负荷,如何设置交换分区大小
2)系统中物理内存越大,所需交换分区就会越少
因此,在Red Hat Enterprise Linux 5中,以下是设置合适的交换分区大小的规则:
小于等于4G物理内存的系统,至少设置2GB的交换分区
4G~16G物理内存的系统,至少设置4GB的交换分区
16G~64G物理内存的系统,至少设置8GB的交换分区
64G~256G物理内存的系统,至少设置16GB的交换分区
Note: The information shown below uses measures only associated with data. For example, a kilo-anything is 1000 . . . except that when it is a kilobyte, it is 1024, an even power of two.
提示:以下信息中量度标准均与数据有关。如:kilo-表示1000………但在kilobyte中,它代表1024,一个2的偶次幂。
How Much Data Is That?
Whenever we discuss quantities of data, we tend to do it in the abstract. We speak of a kilobyte, or a megabyte or a gigabyte without really knowing what it represents.
我们总在抽象概念中讨论数据的大小。我们经常提到KB、MB、和GB,但并不知道它们到底代表什么。
The following table shows various quantities of bytes, in each power of ten. Usually, they are shown with multiples of 2 and 5 also. For example, 1 Kilobyte, 2 Kilobytes, 5 Kilobytes.
下表显示了字节所组成的各种数据单位,分别约用10的幂次方表示。他们也经常用2和5的倍数表示。比如:1KB(一千字节)、2KB(两千字节)、3KB(三千字节)。
All the examples are approximate and are rounded. For example, a computer card has 80 columns. If 50 columns contain data on a card, then two cards will be 100 bytes. Also, a 3-1/2 inch diskette can contain 1.4 Megabytes. Showing it as 1 Megabyte reflects both (a) the diskette not typically being filled and (b) rounding. Finally, a CD-ROM can hold more than 500 Megabytes. However, it is listed at that level as “typical” and as the closest match.
所有的例项都取约数或整数,如:一张存储卡有80列。如果其中50列包含数据,那么两张卡就包含了100个字节。同样,在3.5寸磁盘中可以储存1.4兆字节的信息,所以存储1兆字节数据并不代表一张磁盘的空间已被填满。另外一张只读存储器光碟至少可以存储500兆字节的数据。
Bytes (8 bits) 字节(8比特)
0.1字节:一个是/否的指令(实际上是0.125字节,这里取整)
1字节:一个字符
10字节:一个词(语言中的一个词,不是指计算机信息单元)
100字节:电报;两张凿孔编码卡片的内容
Kilobyte(KB) 千字节,1024字节,2的十次方,约为1000或10的三次方
1,024 bytes; 210; approx. 1,000 or 103
1千字节:一个笑话或一个短篇故事的内容
2千字节:打字机打出来的一页的内容
10千字节:百科全书中一页的内容
50千字节:相当于一张压缩的文件图像
100千字节:相当于一张低分辨率的相片
200千字节:两盒(4000张)凿孔编码卡片的内容
500千字节:五盒或一箱(10000张)凿孔编码卡片的内容
Megabyte (MB)兆字节,1024千字节(KB),2的20次方,约为10的六次方
1,048,576 bytes; 220; approx 1,000,000 or 106
1兆字节:一部短篇小说或一张3.5英寸软磁盘的内容
2兆字节:一张高分辨率的相片所占的空间
5兆字节:相当于莎士比亚的所有著作;或30秒与广播质量相当的视频
10兆字节:相当于一分钟的高保真音频信息;一张数码胸腔X光片;或一盒3.5英寸软磁盘所储存的内容
20兆字节:两盒3.5英寸软磁盘的内容
50兆字节:一张数码乳房X光片的内容
100兆字节:一书架书包含的内容;或两卷百科全书的内容
200兆字节:一盘有9首歌的磁带;或一盘IBM3480盒式磁带的内容
500兆字节:一张只读存储光盘的内容
Gigabyte (GB)
1,073,741,824 bytes; 230; approx 1,000,000,000 or 109
1GB:相当于一章交响曲的乐谱;或与发行电影质量相当的视频的内容
20GB:所有贝多芬作品的音频集合;5盒安柏特磁带的内容;一盘储存数据的VHS(Video Home System,VHS式录放像机系统)录像带
50GB:图书馆中一层楼藏书的内容
100GB:
200GB:50盒安伯特磁带的内容
Terabyte (TB)
1,099,511,627,776 or 240; approx. 1,000,000,000,000 or 1012
1TB:一个自动化卡带装置所需的空间大小;一所大型技术医院的所有X光片;用五万株树做成的纸张的打印品;环地轨道系统的日运行量(1998年)
2TB:一个学术图书馆的藏书内容
10TB:美国国会图书馆所有藏书
50TB:一个大容量储存系统的内容
Petabyte (PB)
1,125,899,906,842,624 bytes or 250 approx. 1,000,000,000,000,000 or 1015
1PB:3年的EOS数据总和(2001年)
2PB:美国所有学术图书馆所藏内容的总和
20PB:1995年生产的所有硬盘的空间大小
200PB:世界上所有的打印材料;95年产所有的数码磁带包含的内容总和
Exabyte
1,152,921,504,606,846,976 bytes or 260 approx. 1,000,000,000,000,000,000 or 1018
2EB:每年全球产生的所有信息量总和
5EB:人类所有语言的所有词汇量
Zettabyte
1,180,591,620,717,411,303,424 bytes or 270 approx. 1,000,000,000,000,000,000,000 or 1021
(据说如同全世界海滩的沙子总和)
Yottabyte
1,208,925,819,614,629,174,706,176 bytes or 280 approx. 1,000,000,000,000,000,000,000,000 or 1024
(据说相当于7000位人类体内的微细胞总和)
什么是mysql_proxy?
mysql_proxy是一个简单的位于客户端和mysql服务器程序,它可以监测分析改变起通信,灵活行,允许很多用途,常使用的:负载均衡;备援;查询分析;查询过滤等等。
下面我将要使用mysql_proxy来实现读写分离.首先我这篇文章是结合上一篇mysql master-slave 同步来写的,清大家一定要结合上篇文章。
linux OS : ubuntu 8.04.1
software : mysql-server libmysqlclient15-dev libmysqlclient15off lua libeventdb-dev
mysql1 :192.168.6.4
mysql2 :192.168.6.5 接上篇文章的两台 mysql服务器
mysql_proxy : 192.168.6.3
在 mysql1 于mysql2上执行
建立一个空的数据库 test;
建立一个空表
create table proxy(id int(5),name
char(10));
1.在mysql-proxy服务器上安装 mysql-proxy
apt-get install libmysqlclient15-dev libmysqlclient15off libeventdb-dev lua5.1 tar zxvf mysql-proxy-0.6.1.tar.gz cd mysql-proxy-0.6.1 ./configure --prefix=/usr/local/mysql-proxy make make install /usr/local/mysql-proxy/sbin/mysql-proxy --help-all Usage: mysql-proxy [OPTION...] - MySQL Proxy Help Options: -?, --help Show help options --help-all Show all help options --help-admin Show options for the admin-module --help-proxy Show options for the proxy-module admin module --admin-address=<host:port> listening address:port of internal admin-server (default: :4041) proxy-module --proxy-address=<host:port> listening address:port of the proxy-server (default: :4040) --proxy-read-only-backend-addresses=<host:port> address:port of the remote slave-server (default: not set) --proxy-backend-addresses=<host:port> address:port of the remote backend-servers (default: 127.0.0.1:3306) --proxy-skip-profiling disables profiling of queries (default: enabled) --proxy-fix-bug-25371 fix bug #25371 (mysqld > 5.1.12) for older libmysql versions --proxy-lua-script=<file> filename of the lua script (default: not set) --no-proxy Don't start proxy-server Application Options: -V, --version Show version --daemon Start in daemon-mode --pid-file=<file> PID file in case we are started as daemon --admin-address=<host:port> 管理地址<IP:端口> 内部管理服务器默认端口 4041 --proxy-address=<host:port> 代理地址<IP:端口> 端口代理服务器 默认端口4040 --proxy-read-only-backend-addresses=<host:port> 代理只读后端服务器地址 <IP:端口> --proxy-backend-addresses=<host:port> 代理后断服务器地址<IP:端口> 远程后断服务器默认 127.0.0.1:3306 --proxy-skip-profiling 还不清楚什么意思~ -proxy-fix-bug-25371 应该是修复了漏洞吧,解释是这样的。 --proxy-lua-script=<file> proxy-lua脚本<lua文件> 默认是没有设置的 --no-proxy 没有代理不启动代理服务器 -V, --version 显示 mysql-proxy版本 --daemon 以守护进程启动模式 --pid-file=<file> daemon 启动模式的 pid文件 mysql-proxy 启动,这里我用的一个CU 朋友写的脚本,期间有些改动也是这位朋友告诉我几个要改的地方。再次感谢 KDr2 这个脚本我会上传开放给大家 /usr/loca/mysql-proxy/sbin/mysql-proxy --proxy-read-only-backend-addresses=192.168.6.5:3306 --proxy-backend-addresses=192.168.6.4:3306 --proxy-lua-script=/usr/local/mysql-proxy/mysql.lua & netstat -ant tcp 0 0 0.0.0.0:4040 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:4041 0.0.0.0:* LISTEN
启动成功
可以远程连接了,在一台linux主机上连接,进行一些读写操作
mysql -uroot -p -P4040 -h192.168.6.3 ludy@ludy:~$ mysql -uroot -p -P4040 -h192.168.6.3 Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 25 Server version: 5.0.51a-3ubuntu5.4-log Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> use test; Database changed mysql> insert into proxy(name) values("10"); Query OK, 1 row affected (0.01 sec) mysql>select * from proxy; Empty set (0.00 sec)
我们插入了数据没有结果~这就对了读写分离了~~~~
接下来我们进入 mysql1 192.168.6.4看看
ludy@ludy:~$ mysql -uroot -p -h192.168.6.4 Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 21 Server version: 5.0.51a-3ubuntu5.4-log (Ubuntu) Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> use test; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> select * from proxy; +------+------+ | id | name | +------+------+ | NULL | 10 | +------+------+ 1 row in set (0.00 sec)
有数据 ~~ 最后 看看 mysql-proxy 的日志~
vim /var/log/mysql-proxy.log [2008-12-24 11:46:05] info: starting connect_server ... 2 [2008-12-24 11:46:05] debug: 3 [192.168.6.4:3306].connected_clients = 0 4 [2008-12-24 11:46:05] debug: 5 [192.168.6.4:3306].idling_connections = 1 6 [2008-12-24 11:46:05] debug: 7 [192.168.6.4:3306].type = 1 8 [2008-12-24 11:46:05] debug: [192.168.6.4:3306].state = 1 9 [2008-12-24 11:46:05] debug: [192.168.6.5:3306].connected_clients = 0 10 [2008-12-24 11:46:05] debug: [192.168.6.5:3306].idling_connections = 0 11 [2008-12-24 11:46:05] debug: [192.168.6.5:3306].type = 2 12 [2008-12-24 11:46:05] debug: [192.168.6.5:3306].state = 0 13 [2008-12-24 11:46:05] info: server [192.168.6.5:3306] open new connection 14 [2008-12-24 11:46:05] debug: [read_query] 15 [2008-12-24 11:46:05] debug: authed backend = 0 16 [2008-12-24 11:46:05] debug: used db = 17 [2008-12-24 11:46:05] debug: Query[show databases] Target is [192.168.6.4:3306] 18 [2008-12-24 11:46:05] debug: transaction res : 0 19 [2008-12-24 11:46:10] debug: [read_query] 20 [2008-12-24 11:46:10] debug: authed backend = 0 21 [2008-12-24 11:46:10] debug: used db = 22 [2008-12-24 11:46:10] debug: Query[SELECT DATABASE()] Target is [192.168.6.5:3306] 23 [2008-12-24 11:46:10] debug: transaction res : 0
很明显了 读是在 192.168.6.5 写及一些事务是在192.168.6.4 执行的。
这样,写在 master 读在salvae 上,然后 master –>slave 同步,简单的负载均衡 ~ 好了我把脚本方上来,大家测试成功后最好修改脚本
找到 local log_level=1
改为 local log_level=2
因为 debug 很耗资源
顺便我也把我 修改的 官方 rw-splitting.lua 方上来 很多人说官方的不起作用
我想是大家没看 清楚脚本吧。官方的 rw-splitting.lua 是限制了 4个以下的连接读写分离是不起作用的。多余四个连接才会 启到读写分离的作用,我修改了官方脚本是连接过多会出现错误~现在不会出现了~
我是 tar 打包的 要用 tar 解压哦,因为 51cto不让上传gz格式包所以呵呵。
1. 添加监控MySQL状态的端口
# vi /etc/services mysqlcheck 6033/tcp # MySQL status check
2. 使用xinetd守护进程运行MySQL状态检测
# cat /etc/xinetd.d/mysqlchk service mysqlcheck { disable = no flags = REUSE socket_type = stream port = 6033 wait = no user = root server = /usr/local/haproxy/sbin/mysqlchk_status.sh log_on_failure += USERID }
3. 状态检测脚本
# vi /usr/local/haproxy/sbin/mysqlchk_status.sh #/bin/bash MYSQL_HOST="localhost" MYSQL_PORT="3306" MYSQL_USERNAME="root" MYSQL_PASSWORD="123456" ERROR_MSG=/usr/bin/mysql --host=$MYSQL_HOST --port=$MYSQL_PORT --user=$MYSQL_USERNAME --password=$MYSQL_PASSWORD -e "show databases;" if [ "$ERROR_MSG" != "" ] then # mysql is fine, return http 200 /bin/echo -e "HTTP/1.1 200 OK\r\n" /bin/echo -e "Content-Type: Content-Type: text/plain\r\n" /bin/echo -e "\r\n" /bin/echo -e "MySQL is running.\r\n" /bin/echo -e "\r\n" else # mysql is fine, return http 503 /bin/echo -e "HTTP/1.1 503 Service Unavailable\r\n" /bin/echo -e "Content-Type: Content-Type: text/plain\r\n" /bin/echo -e "\r\n" /bin/echo -e "MySQL is *down*.\r\n" /bin/echo -e "\r\n" fi # chown haproxy.haproxy /usr/local/haproxy/sbin/mysqlchk_status.sh
4. HAproxy日志
# touch /var/log/haproxy.log # chown haproxy.haproxy /var/log/haproxy.log
编辑/etc/syslog.conf文件,添加如下语句
local0.* /var/log/haproxy.log
5. HAProxy配置文件
[root@localhost htdocs]# cat /usr/local/haproxy/conf/haproxy.conf global maxconn 4096 daemon pidfile /usr/local/haproxy/run/haproxy.pid #debug #quiet user haproxy group haproxy defaults log global mode http option httplog option dontlognull log 127.0.0.1 local0 retries 3 option redispatch maxconn 2000 contimeout 5000 clitimeout 50000 srvtimeout 50000 listen admin_stats 192.168.0.1:80 mode http stats uri /dbs stats realm Global\ statistics stats auth test:123456 listen proxy-mysql 0.0.0.0:23306 mode tcp balance roundrobin option httpchk OPTIONS * HTTP/1.1\r\nHost:\ www server db01 192.168.0.1:3306 weight 1 check port 6033 inter 1s rise 2 fall 2 server db02 192.168.0.2:3306 weight 1 check port 6033 inter 1s rise 2 fall 2 option tcpka
6. HAProxy启动脚本
# cat /etc/init.d/haproxy #! /bin/sh set -e PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/haproxy/sbin PROGDIR=/usr/local/haproxy PROGNAME=haproxy DAEMON=$PROGDIR/sbin/$PROGNAME CONFIG=$PROGDIR/conf/$PROGNAME.conf PIDFILE=$PROGDIR/run/$PROGNAME.pid DESC="HAProxy daemon" SCRIPTNAME=/etc/init.d/$PROGNAME # Gracefully exit if the package has been removed. test -x $DAEMON || exit 0 start() { echo -n "Starting $DESC: $PROGNAME" $DAEMON -f $CONFIG echo "." } stop() { echo -n "Stopping $DESC: $PROGNAME" haproxy_pid=cat $PIDFILE kill $haproxy_pid echo "." } restart() { echo -n "Restarting $DESC: $PROGNAME" $DAEMON -f $CONFIG -p $PIDFILE -sf $(cat $PIDFILE) echo "." } case "$1" in start) start ;; stop) stop ;; restart) restart ;; *) echo "Usage: $SCRIPTNAME {start|stop|restart}" >&2 exit 1 ;; esac exit 0