寻觅生命中的那一片浅草......

文章带标签 Linux

Send Mail with Gmail and sSMTP on CentOS 5

sSMTP is an extremely simple, resource conserving, smtp server that will allow your desktop or server to send email. in this article we are going to use sSMTP to send outgoing email through gmail.

1、Install sSMTP.
Unfortunately,ssmtp is not in CentOS 5 yum base repository,so we have to download and install it manually.

#wget ftp://ftp.muug.mb.ca/mirror/fedora/epel/5/x86_64/ssmtp-2.61-11.8.el5.x86_64.rpm
#rpm -Uvh ssmtp-2.61-11.8.el5.x86_64.rpm

2、configure sSMTP
First,backup and empty /etc/ssmtp/ssmtp.conf
#/bin/cp /etc/ssmtp/ssmtp.conf /etc/ssmtp/ssmtp.conf.OLD
#> /etc/ssmtp/ssmtp.conf
#vi /etc/ssmtp/ssmtp.conf
root=sender@gmail.com
mailhub=smtp.gmail.com:587
UseSTARTTLS=YES
RewriteDomain=
Hostname=sender@gmail.com
AuthUser=sender@gmail.com
AuthPass=password
FromLineOverride=YES

add content above,save and quit.

Second,add each account that you want to be able to send mail from by editing, ‘/etc/ssmtp/revaliases’:

#echo ‘root:sender@gmail.com:smtp.gmail.com:587’ >> /etc/ssmtp/revaliases

Please replace sender and password with your Gmail accountname and password.

Third,backup old sendmail
#/bin/mv /usr/sbin/sendmail /usr/sbin/sendmail.OLD
#ln -s /usr/sbin/ssmtp /usr/sbin/sendmail

On my system,sendmail is provided by postfix.

3、Now try sending an email

You can send an email through your favorite email client, like ‘mail’, or type:

ssmtp someemail@email.com

You will then type your message, hit enter and ‘ctrl+d‘

Now that you have a simple outgoing email server setup, you can do all sorts of neat things:
Configure cron jobs to send log reports to your email address
Alert you of all kinds of system changes
Send email alerts when your computer reaches a certain temperature
Send email through PHP, Python, Ruby, and Perl

References:

http://topo.72pines.com/2009/02/18/linux-命令行下用-gmail-smtp-发信/
http://blog.rogerz.cn/archives/599
http://www.nixtutor.com/linux/send-mail-with-gmail-and-ssmtp/

Dynamic port forward:ssh -D

Bypass the Firewall with “ssh -Nf -D 10086 username@server”

all traffic coming to port 10086 on the client will be forwarded to the server

Great SSH!

Sersync服务器同步程序-inotify与rsync用来代替inotify-tools解决方案(上)

http://code.google.com/p/sersync/
项目简介:
本项目利用inotify与rsync对服务器进行实时同步,其中inotify用于监控文件系统事件,rsync是目前广泛使用的同步算法,其优点是只对文件不同的部分进行操作,所以其优势大大超过使用挂接文件系统的方式进行镜像同步。
目前使用的比较多的同步程序版本是inotify-tools,另外一个是google开源项目Openduckbill(依赖于inotify-tools),这两个都是基于脚本语言编写的,其设计思路同样是采用inotify与rsync命令。 相比较上面两个项目,本项目优点是:
1.sersync是使用c++编写,而且对linux系统文件系统产生的临时文件和重复的文件操作进行过滤(我稍后会提到),所以在结合rsync同步的时候,节省了运行时耗和网络资源。因此更快。
2.相比较上面两个项目,sersync配置起来很简单:在http://code.google.com/p/sersync/downloads/list 处下载源码(分为32版本,与64位版本),其中bin目录下已经有我编译好的2进制文件,配合bin目录下的xml文件直接使用即可。
3.另外本项目相比较其他脚本开源项目,使用多线程进行同步,尤其在同步较大文件时,能够保证多个服务器实时保持同步状态。
4.本项目自带出错处理机制,通过失败队列对出错的文件重新出错,如果仍旧失败,则每10个小时对同步失败的文件重新同步。
5.本项目自带crontab功能,只需在xml配置文件中开启,即可按您的要求,隔一段时间整体同步一次。
6.本项目自带socket与http协议扩展,满足您二次开发的需要。

基本架构:

设计简析

如上图所示,线程组线程是等待线程队列的守护线程,当队列中有数据的时候,线程组守护线程逐个唤醒,当队列中inotify事件交多的时候就会被全部唤醒一起工作。这样设计的目的是能够同时处理多个inotify事件,重发利用服务器的并发能力(核数*2+2)。

之所以称之为线程组线程,是因为每个线程在工作的时候,会根据服务器的数量建立子线程,子线程可以保证所有的文件与各个服务器同时同步,当要同步的文件较大的时候,这样设计可以保证各个远程服务器可以同时获得要同步的文件。

服务线程的作用有三个,首先是处理同步失败的文件,将这些文件再次同步,对于再次同步失败的文件会生成rsync_fail_log.sh脚本,记录失败的事件。同时每隔10个小时执行脚本一次,同时清空脚本。服务线程的第三个作用是crontab功能,可以每隔一定时间,将所有路径整体同步一次。

过滤队列的建立是为了过滤短时间内产生的重复的inotify信息,例如在删除文件夹得时候,inotify就会同时产生删除文件夹里的文件与删除文件夹得事件,通过过滤队列当删除文件夹事件产生的时候,会将之前加入队列的删除文件的事件全部过滤掉,这样只产生一条事件减轻了同步的负担。同时对于修改文件的操作的时候,会产生临时文件与重复操作。

举例:

当我们在vi的一个test文件,进行wq操作的时候会产生如下事件:

即使把”.”开头与”~”结尾的世界过滤了,对于test文件仍旧有3次操作,分别是删除,创建与保存,通过过滤队列,就只剩下一个事件,一定程度上也提高了效率。

过滤队列第二个作用,即当你在本机删除目录的时候,假设你删除一个有5个文件的目录,inotify会产生6个事件,分别是5个文件删除事件,和一个删除目录事件,如果使用过滤队列,正常情况下会只产生一个删除目录的事件,大大减少了rsync通信次数。(当然,这不是绝对的。如果这6个事件分多次读到进入队列,那么可能还没来得及过滤,就已经被同步线程从队列中取走同步了。但一定程度上可以减少删除文件夹得同步通信次数)。

过滤队列的第三个作用,可以过滤监控目录下的文件夹,如果不想同步目录下的一些文件夹,或者一些后缀的文件。对于不需监控的子文件夹,在inotify启动时候remove掉监控,对于不需监控子文件,产生的文件事件就会从在入同步队列前过滤掉。如果使用rsync用–exclude, 这样虽然也可以过滤,但还是与rsync守护进程进行了一次交互。

关于inotify识别事件,详见我上一篇博客:

http://hi.baidu.com/johntech/blog/item/e4a31a3db1ee1ce755e723f4.html

转载自:http://hi.baidu.com/johntech/blog/item/5aa39a890124a6749f2fb4c7.html/cmtid/deed43f268e2e5ce7831aae3

Using yumdownloader To Download RPM Package Without Installing under CentOS

I would like to make a local yum Repository which only contains rpm packages I need.Copy packages from the CentOS DVD?That can’t resolve dependency problems between packages.We can use yumdownloader to download packages.

1、create directory to store packages
#mkdir /media/CentOS

2、install yum-utils which provides yumdownloader
#yum -y install yum-utils

3、download packages,–reolve option will resolve dependencies and download required packages
#cd /media/CentOS
#yumdownloader –resolve rsync telnet vixie-cron

memcached start error:event_queue_remove

I configure Nginx+MySQL+PHP+Memcached enviroment.I use my script to start memcached,then I type “netstat -tlnp” to see if memcached listens on 11211,I can see 11211,but when I type “netstat -tlnp” again,the 11211 port has disappeared.I type this command manually:

/usr/local/bin/memcached -m 128 -c 4096 -p 11211 -u www -t 10

It runs about three seconds,and then crash.the only message logged is:

[err] event_queue_remove: 0x60cfc0(fd -1) not on queue 1

I search “event_queue_remove” in Google. Some guys guess that there is something wrong with libevent.

I type LD_DEBUG=libs /usr/local/bin/memcached -m 128 -c 4096 -p 11211 -u www -t 10

The output of libevent is :
6283: calling init: /usr/lib64/libevent-1.1a.so.1

this shows that the version of libevent is “libevent-1.1a”,but the one I install from source code is “libevent-1.4.9-stable”.

rpm -qa |grep libevent
the result is :
libevent-devel-1.1a-3.2.1
libevent-1.1a-3.2.1
libevent-devel-1.1a-3.2.1
libevent-1.1a-3.2.1

Oh,my god,there is an old version libevent installed by rpm.I uninstall libevent with “yum -y remove libevent libevent-devel”,reinstall memcached,then memcached start normally.

Reference articles:http://www.serverphorums.com/read.php?9,108005

2025年五月
« 5月    
 1234
567891011
12131415161718
19202122232425
262728293031