以技术为主
开源软件
定时备份网站代码与数据的shell工具
四 12th
需求
鉴于国内网络环境的恶劣,本人的blog的托管在国外的vps,为了防范数据丢失,需要及时备份下网站的数据和代码,这样等哪天数据丢失即可及时恢复,数据最重要
解决方法
自己就通过查找资料,简单地写了shell脚本
- 首先打包wordpress代码,使用mysqldump导出mysql数据
- 其次使用mail命令发送数据到指定邮箱
- 最后crontab定时执行
即可搞定
另外在使用mail命令行工具时遇到了一个问题,stackoverflow帮我解决了,具体在这里
实现脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #!/bin/bash # author: yaronli (jidalyg_8711@163.com) # powered by yaronspace.cn set -x backup() { cd /var/www/ #打包代码 tar -czf /tmp/${1}_$(date +%F).tar.gz ${1} #导出数据 mysqldump -u${2} -p${3} ${1} > /tmp/${1}_$(date +%F).sql #以附件形式发送邮件 (uuencode /tmp/${1}_$(date +%F).tar.gz ${1}_$(date +%F).tar.gz; uuencode /tmp/${1}_$(date +%F).sql ${1}_$(date +%F).sql)\ | mail -s ${1}_$(date +%F) yangguangli19871124@gmail.com } #param1: 站点目录 param2: 数据库用户 param3: 密码 backup yaronspace **** **** backup xiaofangdeng **** **** |
使用 cron、bash 和 wget 监控 Web 服务器的状态[转载]
三 29th
原文地址:http://www.oschina.net/question/12_45835
比较好的文章,分享下
需求列表:
- 要求是 bash, wget, 以及 “mail” 命令 (sendmail, exim, postfix, 之类)
- 可监控任何 HTTP/HTTPS URL, 检查 “200″ 状态返回
- 检查请求返回时间,用于监控一些慢响应
- 通过 Email 发送异常状态提醒
- 可定制的接收异常信息的邮箱
- 可定制慢响应的时间
- 避免重复发送相同的异常提醒
- 使用简单文本文件作为数据存储,不需要数据库
crontab脚本如下:
*/5 * * * * root /home/username/sitemonitor.sh
sitemonitor.sh脚本如下: 更多 >
推荐firefox插件vimperator (用vim方式使用Firefox)
七 18th
今天在逛水木的时候,发现这篇文章:http://www.newsmth.net/bbsrecon.php?id=8017
是对vimperator进行了介绍,原来国外哥们写的firefox插件,能够像使用Vim的方式来高效地使用firefox,下来来尝试了,效果不错!
下载地址:https://addons.mozilla.org/en-US/firefox/addon/vimperator/
常用命令(不断更新):
open: 在当前tab打开新的网址 open www.baidu.com
tabopen: 在新的tab打开网址
back: 后退键
forward:前进键
gt/gT:在tab间进行移动
d: 关闭当前tab
hjkl:上下移动网页或者光标
i(insert):进入insert模式,可以移动光标
/ :搜索网页的内容
总的来说很强大哈!!!
SMTP邮件服务器postfix配置与使用
六 1st
最近要帮朋友配置一个SMTP服务器,需求就是每天需要向外发送上百万封邮件,google之,发现postfix邮件服务器比较靠谱, 能够发送外部邮件,于是就选它了
操作系统:CentOS 5 32bit
postfix安装
可以通过源码安装最新的版本,但是为了方便,我直接使用yum安装
sudo yum install postfix
配置文件路径:/etc/postfix/main.cf
postfix启动与停止命令:
sudo /etc/init.d/postfix start sudo /etc/init.d/postfix stop sudo /etc/init.d/postfix restart
postfix日志文件位置:/var/log/maillog
卸载sendmail
检查系统是否安装sendmail:
rpm –qa |grep sendmail
如果存在,卸载之
rpm -e sendmail --nodeps
安装cyrus-sasl-2.1.23
由于在centos 源中不存在,直接通过源码安装cyrus-sasl-2.1.23.tar.gz
下载地址
./configure &&make &&make install
这个软件包的作用就是postfix邮件服务器的认证,因为如果转发外部的邮件,必须使用smtpd_recipient_restrictions选项的值check_relay_domains或者是reject_unauth_destination,二者必须选一个,而relay_damains手工来配置允许的邮件域太麻烦,所以就选用sasl认证
修改sasl配置:/etc/sysconfig/saslauthd为
# Directory in which to place saslauthd's listening socket, pid file, and so # on. This directory must already exist. START=yes SOCKETDIR=/var/run/saslauthd # Mechanism to use when checking passwords. Run "saslauthd -v" to get a list # of which mechanism your installation was compiled with the ablity to use. #MECH="pam" MECHANISMS="pam" #使用linux自身的用户认证 # Additional flags to pass to saslauthd on the command line. See saslauthd(8) # for the list of accepted flags. #FLAGS=
然后重启saslauthd:
sudo /etc/init.d/saslauthd restart
测试saslauthd生效:
/usr/sbin/testsaslauthd -u liyg -p liyangguang
将sasl与postfix结合
在main.cf文件中加入:
#added by liyangguang smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination #smtpd_client_restrictions = permit_sasl_authenticated smtpd_sasl_auth_enable = yes broken_sasl_auth_clients = yes smtpd_sasl_security_options = noanonymous
重启postfix :sudo /etc/init.d/postfix restart。
然后通过foxmail客户端配置smtp服务器地址,测试发送邮件是否成功
参考资料:
http://yahoon.blog.51cto.com/13184/40091
http://www.postfix.org/RESTRICTION_CLASS_README.html
http://publish.it168.com/2006/0221/20060221219401.shtml
redis中常用数据结构介绍
四 13th
1. 常用数据结构
dict
在redis中最基本的三个数据结构是dict 、adlist和sds,其中dict是redis中最重要的数据结构了,其key-value的映射关系就是通过dict来实现的,dict的内部实现是hash table,这个哈希表的大小是动态增加或减少的,主要是依据哈希表中的元素个数;同时哈希表适用链接法来解决哈希冲突的,具体实现在dict.h和dict.c文件中;
adlist
adlist(a generic doubly linked list)双向链表,这个数据结构在redis中用的也比较多,包括像当前保存的客户端连接或者是value对应是list的实现等,都是用的adlist,这个应该来说比较简单,具体实现在adlist.h和adlist.c;
sds
还有一个比较基本的数据结构就是sds(dynamic string),对字符串处理的简单封装,具体细节实现在sds.h和sds.c中,有一篇文章是介绍sds的实现的,点击这里
更多 >
redis中sorted set的实现原理
四 12th
从redis 1.1版本,redis开始支持sorted set(有序集合),今天在看redis源码时,具体看了它的实现;
关于ZSET的具体用法:http://redis.io/commands#sorted_set
ZSET的实现用到了两个数据结构:hash table 和 skip list(跳跃表),其中hash table是具体使用redis中的dict来实现的,主要是为了保证查询效率为O(1) ,而skip list(跳跃表)主要是保证元素有序并能够保证INSERT和REMOVE操作是O(logn)的复杂度。
关于skip list这里简单介绍下:skip list是链表的一种特殊形式,对链表的一种优化;保证INSERT和REMOVE操作是O(logn)的负载读,而通用链表的复杂度为O(n);
关于skip list的详细介绍请参考下面这篇文章:
http://blog.csdn.net/caoeryingzi/archive/2010/11/18/6018070.aspx
sorted set的用途:
可以用作实时排名,例如微博用户的排名
还有TOPN问题等
http://wangyuanzju.blog.163.com/blog/static/1302920099311165490/
redis源码分析资料
四 8th
最近闲来无事,看看redis源码,看看redis为何如此高效~
下面是redis代码分析的资料,记录下:
比较全面但不太详细的分析:Redis: under the hood
简单的读和写的完整处理过程:More Redis internals: Tracing a GET & SET (同时也是一个挺好的GDB调试研究源码的实例教程)
关于虚拟内存:Virtual memory
其它资料:http://redis.io/documentation
那就先从redis最原始的1.0版本开始看吧,这里需要说明下,一般学习开源软件代码,最初的版本代码量比较少,看起来不是很费劲,而且基本上能够体现软件的架构信息。
有关本站redis的内容请点击这里
drupal号称比wordpress更强大
三 28th
drupal没有wordpress普及,但是功能应该比wordpress更强大,有以下8个用途:
项目主页:http://drupal.org
1. 文件存储分享站点
使用Drupal创建文件分享,你可以使用 CCK 和 Views ,也包括一些模块,比如Media Mover, Filebrowser 或者 Web File Manager。看看Box.net,你会非常感兴趣的^_^。
2. 社交网站
在社交网络能力方面,Drupal可能是最好的CMS。Drupal提供了强大的用户管理和权限管理系统。但是如果你想创建强大的社交网站,就需要一些模块,见http://drupal.org/node/206724。
你想看一些案例?Imbee 或者 GoingOn。
3. Twitter Clone
建议你不要尝试利用Drupal创建Twitter竞争产品,但是,如果你想整合Twitter功能到你的站点,Drupal的微博模块 可以帮到你。
4. 新闻News portal
如果你想创建新闻站点或杂志站点,Drupal的完美的选择。使用CCK 和 Views ,你可以创建所有的发布内容类型,并且可灵活列表。这样的新闻站点非常之多,比如New York Observer。
5. 博客网络
用Drupal创建博客网站,很轻松,甚至无需额外模块。看看 Wisebread吧。
6. 视频分享站点
这类站点太耗带宽了,如果你决定创建,那么Drupal来帮你实现吧。FlashVideo 模块提供了创建Youtube克隆的强大能力,它整合了CCK,转换视频到FLV,并有分享代码。另外你也可以尝试Media Mover 和 SWF Tools 。MTV UK 站点就是Drupal创建的。
7. 图片分享站点
Image module ,这个模块将派上用场,可让你创建类Flickr站点,很好很强大。MyFinePix 就是Drupal创建的照片分享站点。
8. 类Digg-like news site
感谢 Drigg module, 这个模块可帮助你快速建立Digg克隆站点。流行的设计社交新闻网Designbump在使用Drupal。
netstrain 和 netperf 网络吞吐量测试软件
十 12th
netstrain
代码很小,使用也很方便
下载tar 包,解压make 即可,生成两个二进制文件netstraind netstrain
netstraind [-46] port 服务器端
netstrain [-46] host port send|recv|both 客户端
下载地址:http://sourceforge.net/projects/netstrain/files/
NetStrain is a tool to measure practical data throughput between two
machines over a TCP connection. It can be used for performance
testing, stress/stability testing and to demonstrate various network
effects. It supports both IPv4 and IPv6, provided the underlying
system does.
netperf
下载地址:http://www.netperf.org/netperf/DownloadNetperf.html
介绍netperf的一篇文章:http://www.ibm.com/developerworks/cn/linux/l-netperf/index.html

近期评论