环境:
ubuntu server 10.04 + rvm + ruby 1.9.2 + rails 3.0.3
本来自启动是很简单的操作,可是今天为了让服务器上一个应用自启动,应用服务器用的是 thin, thin怎么也不能自启动,估计是rvm的问题,最后使用rvm wrapper解决了.
我以普通用户登录的ubuntu
安装 thin init.d 脚本
>sudo thin install
如果提示sudo thin 找不到 ,可以使用:
>rvmsudo thin install
这句命令实质在 /etc/init.d 下新建了 thin脚本
#!/bin/sh ### BEGIN INIT INFO # Provides: thin # Required-Start: $local_fs $remote_fs # Required-Stop: $local_fs $remote_fs # Default-Start: 2 3 4 5 # Default-Stop: S 0 1 6 # Short-Description: thin initscript # Description: thin ### END INIT INFO # Original author: Forrest Robertson # Do NOT "set -e" # DAEMON=/usr/local/rvm/gems/ruby-1.9.2-p318/bin/thin DAEMON=/usr/local/rvm/bin/bootup_thin SCRIPT_NAME=/etc/init.d/thin CONFIG_PATH=/etc/thin # Exit if the package is not installed [ -x "$DAEMON" ] || exit 0 case "$1" in start) $DAEMON start --all $CONFIG_PATH ;; stop) $DAEMON stop --all $CONFIG_PATH ;; restart) $DAEMON restart --all $CONFIG_PATH ;; *) echo "Usage: $SCRIPT_NAME {start|stop|restart}" >&2 exit 3 ;; esac :
设置 thin 开机自启动
>sudo update-rc.d -f thin defaults
然后把你的thin.yml配置文件放到 /etc/thin/ 下,看下我的:
wxianfeng@SNDA-192-168-2-15:~$ cat /etc/thin/thin.yml --- chdir: /data/projects/project_manager environment: production address: 0.0.0.0 port: 3000 timeout: 30 log: log/thin.log pid: tmp/pids/thin.pid max_conns: 1024 max_persistent_conns: 512 require: [] wait: 30 servers: 6 daemonize: true onebyone: true
就这么简单,发现 reboot 后,thin启动不起来 , 百思不得其解,
使用
>/etc/init.d/thin start可以顺利启动
>service start thin
启动不了,提示找不到 thin,所以问题可能在这
于是google,最后找到了 rvm wrapper
我为我的项目使用了 rvm gemset , gemset名字为 huaianxinao
使用gemset
rvm @huaianxinao生成wrapper
rvm wrapper ruby-1.9.3-p318@huaianxinao bootup thin
可以看到是生成了一个这样的可执行文件
/usr/local/rvm/bin/bootup_thin于是把你的thin init.d 脚本的DAEMON修改为该路径
测试
>service thin start
可以顺利启动,
>sudo reboot
thin 顺利自启动, OH YEAR O_O
最后看下 wrapper 原理,ls -l 看下 bootup_thin文件:
wxianfeng@SNDA-192-168-2-15:~$ ls -l /usr/local/rvm/bin/bootup_thin lrwxrwxrwx 1 wxianfeng rvm 56 2012-04-21 17:29 /usr/local/rvm/bin/bootup_thin -> /usr/local/rvm/wrappers/ruby-1.9.2-p318@huaianxinao/thin
发现从gemset那ln -s 过来的,继续cat看下
wxianfeng@SNDA-192-168-2-15:~$ cat /usr/local/rvm/wrappers/ruby-1.9.2-p318@huaianxinao/thin #!/usr/bin/env bash if [[ -s "/usr/local/rvm/environments/ruby-1.9.2-p318@huaianxinao" ]] then source "/usr/local/rvm/environments/ruby-1.9.2-p318@huaianxinao" exec thin "$@" else echo "ERROR: Missing RVM environment file: '/usr/local/rvm/environments/ruby-1.9.2-p318@huaianxinao'" >&2 exit 1 fi
发现source了这个文件 /usr/local/rvm/environments/ruby-1.9.2-p318@huaianxinao,cat 看下
wxianfeng@SNDA-192-168-2-15:~$ cat /usr/local/rvm/environments/ruby-1.9.2-p318@huaianxinao export PATH ; PATH="/usr/local/rvm/gems/ruby-1.9.2-p318@huaianxinao/bin:/usr/local/rvm/gems/ruby-1.9.2-p318@global/bin:/usr/local/rvm/rubies/ruby-1.9.2-p318/bin:/usr/local/rvm/bin:$PATH" export rvm_env_string ; rvm_env_string='ruby-1.9.2-p318@huaianxinao' export rvm_path ; rvm_path='/usr/local/rvm' export rvm_ruby_string ; rvm_ruby_string='ruby-1.9.2-p318' export rvm_gemset_name ; rvm_gemset_name='huaianxinao' export RUBY_VERSION ; RUBY_VERSION='ruby-1.9.2-p318' export GEM_HOME ; GEM_HOME='/usr/local/rvm/gems/ruby-1.9.2-p318@huaianxinao' export GEM_PATH ; GEM_PATH='/usr/local/rvm/gems/ruby-1.9.2-p318@huaianxinao:/usr/local/rvm/gems/ruby-1.9.2-p318@global' export MY_RUBY_HOME ; MY_RUBY_HOME='/usr/local/rvm/rubies/ruby-1.9.2-p318' export IRBRC ; IRBRC='/usr/local/rvm/rubies/ruby-1.9.2-p318/.irbrc' unset MAGLEV_HOME unset RBXOPT
发现设置了很多环境变量,所以找到问题了,你必须设置 rvm一系列的环境变量,才可以搞定!
SEE:
http://beginrescueend.com/integration/init-d/
http://stackoverflow.com/questions/3230404/rvm-and-thin-root-vs-local-user
capistrano 自动部署产生的releases下的版本太多了,没一次都有一个新的版本,足足有了 8G ,我的VPS 一共才16G , 把之前老的版本删除之:
capistrano产生的版本:
[root@li165-150 releases]# ll total 24 drwxrwxr-x 19 root root 4096 Mar 10 12:31 20110310173127 drwxrwxr-x 19 root root 4096 Mar 31 05:08 20110331090836 drwxrwxr-x 19 root root 4096 Apr 1 10:14 20110401141405 drwxrwxr-x 19 root root 4096 Apr 30 02:25 20110430062446 drwxrwxr-x 19 root root 4096 May 9 07:18 20110509111749 drwxrwxr-x 19 root root 4096 Jul 6 12:20 20110706162030
删除shell:
>find . -type d -name "*" -ctime +120 -maxdepth 1 | xargs rm -rf -ctime +120 创建时间120 天前的 -maxdepth 1 不递归查找
环境:ubuntu10.10(client) + Centos 5.5 (server)
每次ssh连接服务器 ,scp 拷贝东西 , 或者rsync同步 ,都要输入密码验证,很麻烦,把publickey传到server上的 authorized_keys 中即可 ,建立信任后就不需要输入密码了
1,生成publickey
>ssh-keygen -t rsa # 或者用 dsa 加密2,上传 publickey 文件到server
>scp ~/.ssh/id_dsa.pub root@173.230.155.150:~/.ssh/authorized_keys # 173.230.155.150 换成你server的ip
3,ok了
======
本地普通用户免密码连接服务器上的普通用户
把服务器上的 authorized_keys 变为 600权限,默认是 644 是不允许的
[entsea@www .ssh]$ ll total 16 -rw-------. 1 entsea entsea 404 May 19 02:50 authorized_keys
=========
ssh时候直接写host连接,不写username配置
localhost:.ssh wangxianfeng$ cat ~/.ssh/config Host www.wxianfeng.com user wxianfeng >ssh www.wxianfeng.com
http://liluo.org/2011/05/%E8%AE%BE%E7%BD%AE-ssh-%E8%87%AA%E5%8A%A8%E7%99%BB%E9%99%86%EF%BC%88%E5%85%8D%E5%AF%86%E7%A0%81%EF%BC%8C%E7%94%A8%E6%88%B7%E5%90%8D%EF%BC%89/
http://topic.csdn.net/u/20110701/12/2519a5cc-77d3-4fda-b2d0-88c62edd2556.html
环境:centos 5.5
在这之前我的服务器密码很简单,感觉不安全,于是改的复杂一点了,顺手对我的登录日志分析了一下,还真发现了很多来破解root密码的远程ip,还记得之前在公司有一次上下班忘记打卡,行政找到我必须找出证据,于是从 我工作电脑中调出当天的登入登出信息 最好不过了 ,记得当时不太熟悉,还是在同事帮助下立即解决的, 另外合理的分析登录日志对你服务器的安全也有很大的作用~!
1,来看看你的服务器被哪些ip登录过(root密码错误的)
[root@li165-150 log]# grep "Failed password for root" /var/log/secure | awk '{print $9}' | uniq -c | sort -nr # awk分割,uniq -c 剔重 + 显示重复次数 , sort -nr 降序(-r) + 数值排序(-n) 3116 69.162.125.77 224 173.230.145.104 111 184.106.229.209 84 60.217.234.142 76 222.237.78.139 51 210.193.16.75 46 88.191.73.232 13 109.169.56.3 4 220.165.28.67 2 115.248.49.217 1 88.191.52.74 1 221.221.173.88 1 220.181.147.187
从上面可以看出来有许多ip试图登录我的服务器,其中 69.162.125.77 就有 3116次失败记录 , 总共统计下:
[root@li165-150 log]# grep "Failed password for root" /var/log/secure | awk '{print $9}' | wc -l 13730
哈,原来这么多人喜欢扫描我的服务器啊。。。。。
2,从 系统日志里查找 root 的相关信息
[root@li165-150 log]# cd /var/log [root@li165-150 log]# find ./ -type f -name "messages*" | xargs grep "root" | more ./messages:2010-08-30T12:54:25.987395-04:00 li165-150 avahi-daemon[2862]: Successfully dropped root privileges. ./messages:2010-08-30T12:54:26.023483-04:00 li165-150 avahi-daemon[2862]: Successfully called chroot(). ./messages.1:2010-08-20T22:55:03.457101-04:00 li165-150 avahi-daemon[2928]: Successfully dropped root privileges. ./messages.1:2010-08-20T22:55:03.504958-04:00 li165-150 avahi-daemon[2928]: Successfully called chroot(). ./messages.1:2010-08-20T22:56:22.025464-04:00 li165-150 avahi-daemon[3047]: Successfully dropped root privileges. ./messages.1:2010-08-20T22:56:22.054287-04:00 li165-150 avahi-daemon[3047]: Successfully called chroot(). ./messages.1:2010-08-21T14:21:13.824695-04:00 li165-150 avahi-daemon[2816]: Successfully dropped root privileges. ./messages.1:2010-08-21T14:21:13.907610-04:00 li165-150 avahi-daemon[2816]: Successfully called chroot().
3,当前登录用户的信息记录在文件/var/run/utmp 中,这是一个二进制文件 用普通的 tail , cat 等工具是无法查看的 , 但是可以通过一些命令来查看文件的信息,例如who
当前登录用户:
[root@li165-150 log]# who # 或者 users 命令 root ttyp1 Aug 31 12:13 (220.181.147.187) root ttyp2 Aug 31 12:53 (220.181.147.187)
[root@li165-150 log]# who -b # 上次启动时间 system boot Aug 30 12:54
更多的who命令请>who —help
4,所有登录进入和退出纪录在文件/var/log/wtmp中,也是二进制文件
[root@li165-150 log]# last -10 root # 查看root用户最后10次的登录情况 root ttyp2 220.181.147.187 Tue Aug 31 12:53 still logged in root ttyp1 220.181.147.187 Tue Aug 31 12:13 still logged in root ttyp0 220.181.147.187 Tue Aug 31 09:06 - 13:16 (04:10) root ttyp0 221.221.173.88 Mon Aug 30 22:40 - 22:42 (00:01) root ttyp0 220.181.147.187 Mon Aug 30 12:55 - 13:11 (00:16) root ttyp0 220.181.147.187 Mon Aug 30 12:51 - down (00:01) root ttyp1 221.221.8.126 Fri Aug 27 03:01 - 04:14 (01:12) root ttyp0 125.34.211.119 Fri Aug 27 01:47 - 04:21 (02:33) root ttyp0 125.34.211.119 Wed Aug 25 23:41 - 23:41 (00:00) root ttyp0 221.221.8.126 Wed Aug 25 21:44 - 21:46 (00:01) wtmp begins Wed Jun 2 09:10:09 2010
[root@li165-150 log]# last # last命令往回搜索wtmp,来显示自从文件第一次创建以来登录过的用户 root ttyp2 220.181.147.187 Tue Aug 31 12:53 still logged in root ttyp1 220.181.147.187 Tue Aug 31 12:13 still logged in root ttyp0 220.181.147.187 Tue Aug 31 09:06 - 13:16 (04:10) root ttyp0 221.221.173.88 Mon Aug 30 22:40 - 22:42 (00:01) root ttyp0 220.181.147.187 Mon Aug 30 12:55 - 13:11 (00:16) reboot system boot 2.6.32.16-linode Mon Aug 30 12:54 (1+00:55) root ttyp0 220.181.147.187 Mon Aug 30 12:51 - down (00:01) root ttyp1 221.221.8.126 Fri Aug 27 03:01 - 04:14 (01:12) root ttyp0 125.34.211.119 Fri Aug 27 01:47 - 04:21 (02:33) root ttyp0 125.34.211.119 Wed Aug 25 23:41 - 23:41 (00:00) root ttyp0 221.221.8.126 Wed Aug 25 21:44 - 21:46 (00:01) root ttyp0 125.34.211.119 Wed Aug 25 21:34 - 21:37 (00:02)
5,最后一次登录记录在 /var/log/lastlog 这个文件中,可以用lastlog查看
[root@li165-150 log]# lastlog Username Port From Latest root ttyp2 220.181.147.187 Tue Aug 31 12:53:34 -0400 2010
6,清除登录log
>rm -f /var/log/wtmp >cat /dev/null > /var/log/lastlog
另外今天学了一招历史命令的用法,之前都是用上箭头调出,若是调到前面第10个就需要10下,麻烦,可以用history命令搞定
[root@li165-150 log]# history 10 # 最近10条 1085 last 1086 last 1087 last 1088 lastlog 1089 lastlog -u wxianfeng 1090 lastlog 1091 last 1092 rm -f /var/log/wtmp 1093 last 1094 history 10
>history -c # 清除 historySEE:
http://zhiwei.li/text/2010/06/linux%E7%99%BB%E5%BD%95%E6%97%A5%E5%BF%97/
环境:centos 5.5 + imagemagick 6.2.8 + rmagick 1.15.17
原本想安装最新版的rmagick的,但是发现编译ImageMagick安装不是少这个就是少那个,一汽之下,最后还是 yum 安装的比较快。。。。
如果你已经yum安装了,但是想再编译安装,需要先卸载原来的:
>yum remove ImageMagick安装过程:
yum install ImageMagick yum install ImageMagick-devel gem install rmagick -v=1.15.17 --no-rdoc --no-ri -- --disable-htmldoc # 注意后面的参数需要加上,没加上会报错
安装 rmagick时主要还有版本问题,出错的话,会提示你ImageMagick必须大于多少版本,那么如何查看ImageMagick版本?
>convert -version
SEE:
http://stackoverflow.com/questions/1254366/problem-installing-rmagick-rubygem-on-centos-5
环境:centos 5.5 + postfix 2.3.3
[root@li165-150 ~]# postconf mail_version mail_version = 2.3.3
上次,http://wxianfeng.com/2010/08/20/linode-mysql-got-error-28-from-storage-engine,刚刚解决了blog不能访问的问题 , 由于磁盘占满的原因 ,一天时间没到我的磁盘又被占满了,还是maillog在一直增长的原因,经过查找原因,原来我的mail server变成了肉鸡,被人拿来发送大量的垃圾邮件了,刚开始配的时候不太懂,没注意 open relay的情况 , http://wxianfeng.com/2010/08/01/centos-install-mail-server,所以,必须关系open replay功能~!
1,什么是open – relay ?
顾名思义,relay的转发的意思 , Open-Relay(开放转发或匿名转发)是指由于邮件服务器不理会邮件发送者或邮件接受者的是否为系统所设定的用户,而对所有的入站邮件一律进行转发(RELAY)的功能。通常,若邮件服务器的此功能开放,则我们一般称此邮件服务器是Open-Relay的
2,怎么测我的mail server 是不是 open relay 的 ?
[root@li165-150 ~]# telnet mail.wxianfeng.com 25 Trying 173.230.155.150... Connected to mail.wxianfeng.com. Escape character is '^]'. 220 mail.wxianfeng.com ESMTP Postfix mail from:ss@163.com 250 2.1.0 Ok rcpt to:wang.fl_1429@gmail.com 554 5.7.1 <wang.fl_1429@gmail.com>: Relay access denied
上面出现了 Relay access denied , 则说明你的mail server 不是 open replay的 ,如果可以成功发送email , 则说明 你的mail server 是 open replay的 ,另外 , 还可以通过以下网址测试:
http://verify.abuse.net/relay.html
直接输入 mail.wxianfeng.com 测试
3,open-relay 后 , 被人盗寄的症状
>mailq 查看邮件队列,会发现里面有大量的邮件等待发送
>tail -f /var/log/maillog出现了大量的像下面这样的log:
2010-08-21T05:52:31.424284-04:00 li165-150 postfix/qmgr[8366]: 0C50427536: to=<xlgaga@yahoo.com.tw>, relay=none, delay=141354, delays=141354/0.04/0/0, dsn=4.7.1, status=deferred (delivery temporarily suspended: host mx2.mail.tw.yahoo.com[203.188.197.10] refused to talk to me: 421 4.7.1 [TS03] All messages from 173.230.155.150 will be permanently deferred; Retrying will NOT succeed. See http://postmaster.yahoo.com/errors/421-ts03.html) 2010-08-21T05:52:31.425279-04:00 li165-150 postfix/qmgr[8366]: 0C50427536: to=<xocy@yahoo.com.tw>, relay=none, delay=141354, delays=141354/0.04/0/0, dsn=4.7.1, status=deferred (delivery temporarily suspended: host mx2.mail.tw.yahoo.com[203.188.197.10] refused to talk to me: 421 4.7.1 [TS03] All messages from 173.230.155.150 will be permanently deferred; Retrying will NOT succeed. See http://postmaster.yahoo.com/errors/421-ts03.html) 2010-08-21T05:52:31.426311-04:00 li165-150 postfix/qmgr[8366]: 0C50427536: to=<xup6ru4vm0@yahoo.com.tw>, relay=none, delay=141354, delays=141354/0.04/0/0, dsn=4.7.1, status=deferred (delivery temporarily suspended: host mx2.mail.tw.yahoo.com[203.188.197.10] refused to talk to me: 421 4.7.1 [TS03] All messages from 173.230.155.150 will be permanently deferred; Retrying will NOT succeed. See http://postmaster.yahoo.com/errors/421-ts03.html) 2010-08-21T05:52:31.427198-04:00 li165-150 postfix/qmgr[8366]: 0C50427536: to=<y2003625@yahoo.com.tw>, relay=none, delay=141354, delays=141354/0.05/0/0, dsn=4.7.1, status=deferred (delivery temporarily suspended: host mx2.mail.tw.yahoo.com[203.188.197.10] refused to talk to me: 421 4.7.1 [TS03] All messages from 173.230.155.150 will be permanently deferred; Retrying will NOT succeed. See http://postmaster.yahoo.com/errors/421-ts03.html) 2010-08-21T05:52:31.428079-04:00 li165-150 postfix/qmgr[8366]: 0C50427536: to=<yck1012.tw@yahoo.com.tw>, relay=none, delay=141354, delays=141354/0.05/0/0, dsn=4.7.1, status=deferred (delivery temporarily suspended: host mx2.mail.tw.yahoo.com[203.188.197.10] refused to talk to me: 421 4.7.1 [TS03] All messages from 173.230.155.150 will be permanently deferred; Retrying will NOT succeed. See http://postmaster.yahoo.com/errors/421-ts03.html) 2010-08-21T05:52:31.429149-04:00 li165-150 postfix/qmgr[8366]: 0C50427536: to=<yfjtommu@yahoo.com.tw>, relay=none, delay=141354, delays=141354/0.05/0/0, dsn=4.7.1, status=deferred (delivery temporarily suspended: host mx2.mail.tw.yahoo.com[203.188.197.10] refused to talk to me: 421 4.7.1 [TS03] All messages from 173.230.155.150 will be permanently deferred; Retrying will NOT succeed. See http://postmaster.yahoo.com/errors/421-ts03.html) 2010-08-21T05:52:31.430203-04:00 li165-150 postfix/qmgr[8366]: 0C50427536: to=<yfk134@yahoo.com.tw>, relay=none, delay=141354, delays=141354/0.05/0/0, dsn=4.7.1, status=deferred (delivery temporarily suspended: host mx2.mail.tw.yahoo.com[203.188.197.10] refused to talk to me: 421 4.7.1 [TS03] All messages from 173.230.155.150 will be permanently deferred; Retrying will NOT succeed. See http://postmaster.yahoo.com/errors/421-ts03.html) 2010-08-21T05:52:31.431290-04:00 li165-150 postfix/qmgr[8366]: 0C50427536: to=<yi05@yahoo.com.tw>, relay=none, delay=141354, delays=141354/0.05/0/0, dsn=4.7.1, status=deferred (delivery temporarily suspended: host mx2.mail.tw.yahoo.com[203.188.197.10] refused to talk to me: 421 4.7.1 [TS03] All messages from 173.230.155.150 will be permanently deferred; Retrying will NOT succeed. See http://postmaster.yahoo.com/errors/421-ts03.html)
从log中可以看出 , 你的mail server 正在发往yahoo的email,但是全部被拒绝了 ,
4,为什么 会被人盗寄?
网络上 会有很多人用 port scan工具扫描端口 , 当你的25端口, 被人测出是open relay的,这些人就会 充分利用你的mail server 来发垃圾邮件 ,发垃圾邮件的后果 ,可能会导致你的 ip被封 , 被世界垃圾邮件组织 把你ip 拉入黑名单 , 这时你的mail server 也就是废物了。
5,如果关闭 盗寄 的邮件?
我的mail server 有大量的 发送队列, 怎么清除 ,用下面命令
[root@li165-150 mail]# postsuper -d ALL postsuper: Deleted: 61178 messages
发现我清楚了 61178 封垃圾邮件队列 , 这样你的log 应该会停止了, 不会再狂刷了。。。
6,如何关闭open-relay ?
配置 postfix的 mynetworks
mynetworks = 127.0.0.1/32 # ip/netmask
我的整个 postfix main.cf 配置 :
[root@li165-150 ~]# postconf -n alias_database = hash:/etc/aliases alias_maps = hash:/etc/aliases broken_sasl_auth_clients = yes command_directory = /usr/sbin config_directory = /etc/postfix daemon_directory = /usr/libexec/postfix debug_peer_level = 2 home_mailbox = Maildir/ html_directory = no inet_interfaces = $myhostname, localhost , 173.230.155.150 # 设置postfix服务监听的网络接口 通常是将所有的网络接口都开放,以便接收任何网络接口的邮件 mail_owner = postfix mailq_path = /usr/bin/mailq.postfix manpage_directory = /usr/share/man mydestination = $myhostname,$mydomain,localhost.$mydomain , localhost , $mydomain,mail.$mydomain,www.$mydomain # 设置可接收邮件的主机名称或域名 mydomain = wxianfeng.com # 邮件域名 myhostname = mail.wxianfeng.com # 邮件主机名 mynetworks = 127.0.0.1/32 # 设置可转发(Relay)哪些网络的邮件 myorigin = $mydomain # 由本机寄出的域名 newaliases_path = /usr/bin/newaliases.postfix queue_directory = /var/spool/postfix readme_directory = /usr/share/doc/postfix-2.3.3/README_FILES relay_domains = $mydestination # 设置可转发哪些网域的邮件 sample_directory = /usr/share/doc/postfix-2.3.3/samples sendmail_path = /usr/sbin/sendmail.postfix setgid_group = postdrop smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination smtpd_sasl_auth_enable = yes # SASL来完成SMTP的SMTP-AUTH功能,postfix 本身没有认证机制 smtpd_sasl_local_domain = wxianfeng.com smtpd_sasl_path = private/auth smtpd_sasl_security_options = noanonymous smtpd_sasl_type = dovecot unknown_local_recipient_reject_code = 550 virtual_mailbox_domains = $mydomain
See:
http://www.raidenhttpd.com/jlbb/viewtopic.php?p=82160&sid=661a10a71ded2a6280fdd5ad6ba20101
http://www.linuxgoo.com/2005/66127/10433644999.html
http://blog.csdn.net/daisy_cheung/archive/2009/01/16/3795087.aspx
http://www.cnblogs.com/newversion/articles/1490910.html
环境:centos 5.5 + postfix + dovecot +SASL + Squirrelmail
postfix 提供smtp服务,dovecot 提供pop3,imap服务,sasl提供smtp认证服务, Squirrelmail 是webmail 用来收发邮件之用,最近需要发送email的服务,本想使用gmail的smtp的,后来索性就自己搭了个,以便熟悉mail服务器的搭建过程,一路下来,发现还真不是一件容易的事 ,这个还是比较简单的,还有加密传输,反垃圾邮件处理等等东西没弄,搭建过程中遇到的问题比较多, 问题最大的地方是 例如我用 gmail 发送邮件给 wxianfeng@wxianfeng.com, 邮件收不到,gmail中也没有显示退信信息,说明邮件还是发出去了,最后发现是 postfix 的配置文件 mynetworks 配置错误 ……
上面的是我mail服务器搭建的选择,当然你也可以选择别的mail服务器 , 例如 smtp你可以选择sendmail , 或者你可以看看别人的mail服务器是什么,eg:
[root@li165-150 ~]# telnet vic360.com 25 # 或者 telnet vic360.com smtp Trying 221.6.104.142... Connected to vic360.com. Escape character is '^]'. 220 mail.vic360.com Kerio MailServer 6.3.1 ESMTP ready quit 221 2.0.0 SMTP closing connection Connection closed by foreign host. [root@li165-150 ~]# telnet vic360.com pop3 # 或者 telnet vic360.com 110 Trying 221.6.104.142... Connected to vic360.com. Escape character is '^]'. +OK Kerio MailServer 6.3.1 POP3 server ready <12927.1280636072@mail.vic360.com>
可以看出 vic360 的mail服务器选择的是 Kerio MailServer , 25 一般是 smtp的port , 110 是 pop3 的port
[root@li165-150 ~]# telnet mail.beebuyer.com smtp Trying 218.202.225.66... Connected to mail.beebuyer.com. Escape character is '^]'. 220 mobase.cn ESMTP MDaemon 9.5.1; Sun, 01 Aug 2010 12:21:07 +0800 quit 221 See ya in cyberspace Connection closed by foreign host. [root@li165-150 ~]# telnet mail.beebuyer.com pop3 Trying 218.202.225.66... Connected to mail.beebuyer.com. Escape character is '^]'. +OK mobase.cn POP MDaemon 9.5.1 ready <MDAEMON-F201008011221.AA2142193MD8611@mobase.cn>
可以看出 beebuyer.com 的 mail server 是 MDaemon 9.5.1
okay , 下面介绍 我的 mail server的搭建过程:
1,安装 postfix ,卸载sendmail
yum update yum remove sendmail yum install postfix
2,配置 postfix
>vim /etc/postfix/main.cf myhostname = mail.wxianfeng.com mydomain = wxianfeng.com myorigin = $mydomain inet_interfaces = $myhostname, localhost , 173.230.155.150 # 173.230.155.150 是我服务器IP mydestination = $myhostname,localhost.$mydomain , localhost , $mydomain,mail.$mydomain,www.$mydomain mynetworks = 0.0.0.0/0 home_mailbox = Maildir/ # email的存放地址 , 默认是存放在file中,你还可以配置mysql , 存到mysql 中
3,安装配置SASL + TLS
>yum install cyrus-sasl
>vim /etc/postfix/main.cf
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = wxianfeng.com
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination
smtpd_sasl_security_options = noanonymous
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
broken_sasl_auth_clients = yes4,安装配置 Dovecot
>yum install dovecot >vim /etc/dovecot.conf protocols = pop3 pop3s imap imaps mail_location = maildir:~/Maildir/ # email的存放地址 pop3_uidl_format = %08Xu%08Xv auth default { mechanisms = plain login passdb pam { } userdb passwd { } socket listen { client { path = /var/spool/postfix/private/auth mode = 0660 user = postfix group = postfix } } }
5,安装配置 Squirrelmail
>yum install squirrelmail >vim /etc/httpd/conf.d/squirrelmail.conf Alias /webmail /usr/share/squirrelmail # 配置apache >/usr/share/squirrelmail/config/conf.pl 2 -> 1 Domain : wxianfeng.com # 配置域名 10 -> 2 Default Charset : utf-8 # 配置编码
6,重启所有服务
/etc/init.d/postfix restart /etc/init.d/dovecot restart /etc/init.d/saslauthd restart service httpd restart
7,测试安装是否成功
http://wxianfeng.com:8080/webmail/src/configtest.php
http://wxianfeng.com:8080/webmail 访问, 可以 收发email
8,创建mail用户
>adduser wxianfeng
>passwd 123459,本地测试收发email
smtp发:
>telnet localhost smtp Trying 127.0.0.1... Connected to localhost.localdomain (127.0.0.1). Escape character is '^]'. 220 mail.wxianfeng.com ESMTP Postfix >ehlo localhost 250-mail.wxianfeng.com 250-PIPELINING 250-SIZE 10240000 250-VRFY 250-ETRN 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 DSN >mail from:wxianfeng 250 2.1.0 Ok >rcpt to:wxianfeng 250 2.1.5 Ok >data 354 End data with <CR><LF>.<CR><LF> test . # 以 . 结束输入 250 2.0.0 Ok: queued as 9729067C17 quit 221 2.0.0 Bye Connection closed by foreign host.
查看 发送队列
[root@mail ~]# cd /home/wxianfeng/Maildir/new [root@mail new]# ls 1185669817.Vfd00I18012M795756.mail.wxianfeng.com [root@mail new]# cat 1185669817.Vfd00I18012M795756.mail.wxianfeng.com
pop3 收 测试:
[root@li165-150 ~]# telnet localhost pop3 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. +OK Dovecot ready. user wxianfeng +OK pass 12345 +OK Logged in. list +OK 11 messages: 1 483 2 453 3 809 4 853 5 2029 6 2671 7 2721 8 2870 9 3178 10 2749 11 2702 . retr 1 +OK 483 octets Return-Path: <wxianfeng@wxianfeng.com> X-Original-To: wxianfeng@wxianfeng.com Delivered-To: wxianfeng@wxianfeng.com Received: from localhost (localhost [127.0.0.1]) by li165-150.wxianfeng.com (Postfix) with ESMTP id D31F91331F for <wxianfeng@wxianfeng.com>; Thu, 29 Jul 2010 03:35:50 -0400 (EDT) Message-Id: <20100729073619.D31F91331F@li165-150.wxianfeng.com> Date: Thu, 29 Jul 2010 03:35:50 -0400 (EDT) From: wxianfeng@wxianfeng.com To: undisclosed-recipients:; test .
10 , 域名 设置
必须保证你的 域名设置那有 mail.wxianfeng.com 指向你的 ip , 或者你有 *.wxianfeng.com 的 泛域名 解析
11,添加 MX record
在你的域名商那添加 MX record ,例如我的在godaddy,什么是mx record: 邮件交换记录(MX record)是一个DNS资源记录类型,它指出哪个主机能够处理一个特定域的e-mail。把godaddy默认的mx record删除掉,我的默认是下面的这两个,删除之:
Priority Host Goes To TTL 10 @ mailstore1.secureserver.net 1 Hour 0 @ smtp.secureserver.net 1 Hour
添加自己的:
Priority Host Goes To TTL
10 @ mail.wxianfeng.com 1 Hour
设置好后 可能过段时间才生效,测试生效方法,.下面结果说明已经生效:
[root@li165-150 ~]# host -t mx wxianfeng.com wxianfeng.com mail is handled by 10 mail.wxianfeng.com.
12,解决Squirrelmail 内中文email的乱码
在option(选项)那设置显示语言为 中文简体即可
13,如果你的Squirrelmail 不可以 收发邮件,可以直接远程telnet 测试
>telnet mail.wxianfeng.com 25 mail from:wxianfeng rcpt to:wang.fl1429@gmail.com ......... >telnet mail.wxianfeng.com 110 user wxianfeng pass 12345 list retr 1 ......
如果telnet 可以发送成功 , 就没 问题….
14,查看错误
如果过程中出现错误,可以随时查看log
>tail -f /var/log/maillogthat’s all , just do it
See :
http://www.mysql-apache-php.com/mailserver.htm
http://www.linuxmail.info/postfix-smtp-server-howto-centos-5/
douban blog 认领标识:
doubanclaim5c7c4eaf84713af2
1,安装subversion
yum update yum install subversion
3,创建和配置代码仓库
cd /usr/local/system svnadmin create vcs # 配置工程 vim vcs/conf/svnserve.conf # 取消掉如下两行的注释 # auth-access = write # password-db = passwd # 配置该工作的用户与密码 vim vcs/conf/passwd [users] wxianfeng = 12345
4,启动svn server
cd /usr/local/system
svnserve -d -r vcs5,导入工程
svn import wxianfeng_com svn://173.230.155.150/wxianfeng_com -m "first import" --username wxianfeng --password 12345 # 远程 或本机导入 svn import wxianfeng_com file:///localhost/wxianfeng_com # 本机导入
前面的wxianfeng_com 是本地的文件夹,后面的wxianfeng_com 是svn仓库的project name , 或者你可以借助netbeans,eclipse带的svn客户端直接导入netbeans中或eclipse中的project到svn仓库中
6,checkout项目
svn co svn://173.230.155.150/wxianfeng_com
以上就可以做到一个仓库,多个项目的目的了,当有另外一个project时,直接import即可,如果想删除仓库中的某个工程,可以执行delete命令
svn delete svn://173.230.155.150/wxianfeng_com -m "delete project"
See:
http://www.tonyspencer.com/2007/03/02/setup-a-subversion-server-in-4-minutes/
http://blog.itmem.com/archives/1207
这几天真是和phpmyadmin有缘啊,老是和他接触,今天又在我的linode VPS上搭建了个phpmyadmin,用来管理mysql数据库,装好后才猛然发现我的数据库中中文全部是乱码,但是rails读出来后是中文,也就是大家看到我现在的这个blog是中文,但是mysql里是乱码,看了下所有的编码都是utf-8形式,诡异的问题,这个问题比较棘手,必须解决。但是今天写的是 centos 5.5 上如何搭建phpmyadmin ,和其他系统的安装的大同小异
1,安装php
yum install php – enablerepo=centosplus
注意 – 和 enablerepo 之间有个空格 , 加上 – enablerepo=centosplus 为了安装到5.x的php,如果直接 yum install php 的话 , 则安装的是php 4.x 系列
以后更新php 可以执行下面的命令:
yum update php –enablerepo=centosplus
结束后 可以用 php -v 查看安装的版本信息
2,安装phpmyadmin
到phpmyadmin官网下载 phpmyadmin , 注意下载的版本 必须注意支持的mysql 和 php 版本
我用的是 2.1 版,安装和配置过程:
>cd /usr/local/system # 进入到该目录下,这个一般是我的工作目录,你可以任意指定 >wget http://downloads.sourceforge.net/project/phpmyadmin/phpMyAdmin/2.11.10/phpMyAdmin-2.11.10-all-languages.tar.gz?use_mirror=cdnetworks-kr-1&27689465 # 下载 phpmyadmin >tar -zvxf phpMyAdmin-2.11.9.5-all-languages.tar.gz # 解压 >mv phpMyAdmin-2.11.9.5-all-languages phpmyadmin # rename >cp config.sample.inc.php config.inc.php >vi config.inc.php $cfg['blowfish_secret'] = ‘TypeAnything_for_Secure’; # 找到 $cfg['blowfish_secret'] 值为后面的值 >vi /etc/httpd/conf.d/phpmyadmin.conf Alias /phpmyadmin /usr/local/system/phpmyadmin # 添加该代码
3,配置apache的端口
>vi /etc/httpd/conf/httpd.conf Listen:8080 # 修改Listen 端口为 8080
4,重启 apache
service httpd restart
>netstat -antup # 可以查看端口启动情况5,访问phpmyadmin
http://localhost:8080/phpmyadmin
报错,php 不能加载 mysql 模块 ,因为 php 没有安装 mysql 扩展,安装之:
>yum install php-mysql - enablerepo=centosplus
再次访问 phpmyadmin .OK 成功了
tips:
登录phpmyadmin出现下面错误 #2002 Cannot log in to the MySQL server
修改config.inc.php 的localhost 为 127.0.0.1 即可
>vim config.inc.php
我的phpmyadmin地址:
http://wxianfeng.com:8080/phpmyadmin
See:
https://www.sevenl.net/blog/how-to-install-lamp-phpmyadmin-and-vsftp-on-centos-5-3-using-yum/
http://imthi.com/blog/linux/install-or-update-php-5-on-centos.php
centos 5.5 成功搭建ruby 1.8.6 + rails 2.3.5 + mysql 5.0 环境 , 大致步骤如下:
安装ruby :
1,首先更新下 yum 源
sudo yum update
2,添加ruby repo 源
vi /etc/yum.repos.d/rubyworks.repo在此文件中添加如下内容:
[rubyworks] name=RubyWorks baseurl=http://rubyworks.rubyforge.org/redhat/$releasever/RPMS/$basearch enabled=1 gpgcheck=1 gpgkey=http://rubyworks.rubyforge.org/RubyWorks.GPG.key priority=1
3,安装 ruby
yum install ruby ruby-devel ruby-libs ruby-irb ruby-rdoc ruby-mysql
4,检测ruby安装是否成功 >ruby -v 我安装成功后 , 版本是 1.8.6
安装 rubygem
1,下载
wget http://rubyforge.org/frs/download.php/45905/rubygems-1.3.1.tgz
2,编译并安装
tar -zvxf rubygems-1.3.1.tgz cd rubygems-1.3.1 ruby setup.rb
我在编译时 发现系统 找不到make编译命令 , 所以 需要安装 make库,安装后就ok了:
yum -y install gcc automake autoconf libtool make
3,gem -v 测试安装
4,升级gem
gem update --system
1,安装
gem install -v=2.3.5 rails
2,rails -v 测试安装
安装比较傻瓜 , 不是编译安装的ruby , 所以比较简单 。。。 , 刚开始时依照下面slicehost的文章直接安装 , 安装 出来时 ruby 1.8.5 ,后来又重新按照本文的方法 , 安装一遍 , ruby顺利安装成 1.8.6 ,个人想要 1.8.7 的 ,所以又编译安装了ruby 1.8.7 , 后来发现安装的ruby bin 不是覆盖 , 两个ruby bin安装在不同目录下 , 所以建rails项目 和使用 ruby命令的时候老是冲突,例如 ruby script/server都起不来 , 所以后来索性把编译安装的安装目录 , bin目录 都给我删了 , 6,7 差别估计也不是 太大! 然后就ok了 , 所以 建议 要不你 yum 安装 , 要不你 编译安装 , 不要不同方式 重复 安装两遍
安装 mysql
1,三条命令实现安装 mysql
yum install mysql-server yum install mysql yum install mysql-devel
2,默认安装的mysql 密码是空 , 所以需要修改密码
mysql -u root -p 回车进入 mysql> USE mysql; mysql> UPDATE user SET Password=PASSWORD('new-password') WHERE user='root'; mysql> FLUSH PRIVILEGES;
3,重启 mysql service
/etc/init.d/mysqld restartmysql 安装依然比较傻瓜 , yum直接安装编译好的 , 和在ubuntu里apt-get一样方便 , 更高级的用户 建议 最好都是 编译 source 安装 我想你已经可以 >rails project 新建一个项目 , 测试下 一个demo了 ,ruby on rails + mysql 能否跑起来
See:
http://www.how-to-linux.com/2008/12/how-to-install-ruby-on-rails-on-centos-52/
http://articles.slicehost.com/2009/4/7/centos-ruby-on-rails
http://getablogger.blogspot.com/2009/05/how-to-install-mysql-in-centos-53-from.html
http://www.php.ph/2007/12/24/centos-5-make-command-not-found/





