分类 阿里云 下的文章

在CentOS6 系统里为 postfix 配置外部smtp服务器发邮件

1.yum update # 更新软件
2.hostname erow.org # 设置主机名
3.vi /etc/postfix/main.cf # 编辑 postfix 配置文件,设置 myhostname = erow.org
4.yum install stunnel # 安装 stunnel 软件,目的是转发465端口数据
5.vi /etc/stunnel/stunnel.conf # 编辑 stunnel 配置文件,内容如下:

[smtp-tls-wrapper]
accept = 11125
client = yes
connect = smtp.mxhichina.com:465

6.vi /etc/rc.d/init.d/stunnel # 编辑 stunnel 启动配置文件,内容如下:

#!/bin/bash
#
# Init Script to run stunnel in daemon mode at boot time.
#
# Author: Riccardo Riva - RPM S.r.l.
# Revision 1.0 - 2010 November, 11

#====================================================================
# Run level information:
#
# chkconfig: 2345 99 99
# description: Secure Tunnel
# processname: stunnel
#
# Run "/sbin/chkconfig --add stunnel" to add the Run levels.
# This will setup the symlinks and set the process to run at boot.
#====================================================================

#====================================================================
# Paths and variables and system checks.

# Source function library
. /etc/rc.d/init.d/functions

# Check that networking is up.
#
[ ${NETWORKING} ="yes" ] || exit 0

# Path to the executable.
#
SEXE=/usr/bin/stunnel

# Path to the configuration file.
#
CONF=/etc/stunnel/stunnel.conf

# Check the configuration file exists.
#
if [ ! -f $CONF ] ; then
echo "The configuration file cannot be found!"
exit 0
fi

# Path to the lock file.
#
LOCK_FILE=/var/lock/subsys/stunnel

#====================================================================

# Run controls:

prog=$"stunnel"

RETVAL=0

# Start stunnel as daemon.
#
start() {
if [ -f $LOCK_FILE ]; then
echo "stunnel is already running!"
exit 0
else
echo -n $"Starting $prog: "
$SEXE $CONF
fi

RETVAL=$?
[ $RETVAL -eq 0 ] && success
echo
[ $RETVAL -eq 0 ] && touch $LOCK_FILE
return $RETVAL
}

# Stop stunnel.
#
stop() {
if [ ! -f $LOCK_FILE ]; then
echo "stunnel is not running!"
exit 0

else

echo -n $"Shutting down $prog: "
killproc stunnel
RETVAL=$?
[ $RETVAL -eq 0 ]
rm -f $LOCK_FILE
echo
return $RETVAL

fi
}

# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
condrestart)
if [ -f $LOCK_FILE ]; then
stop
start
RETVAL=$?
fi
;;
status)
status stunnel
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|status}"
RETVAL=1
esac

exit $RETVAL

#--- End of file ---

7.chkconfig stunnel on # 启用 stunnel 服务
8.chmod +x /etc/init.d/stunnel # 为 stunnel 配置文件,添加执行权限
9.service stunnel start # 启动 stunnel 服务
10.mkdir /etc/postfix/sasl # 创建 sasl 目录
11.vi /etc/postfix/sasl/sasl_passwd # 创建邮箱账户登录信息配置文件,内容如下:

[localhost]:11125 postmaster@erwo.org:password

12.postmap /etc/postfix/sasl/sasl_passwd # 生成postfix密码配置文件
13.chmod 600 /etc/postfix/sasl/* # 为了保护smtp的登录信息,需要修改上边两个文件为root用户只读写
14.vi /etc/postfix/main.cf # 修改 /etc/postfix/main.cf 文件,修改 relayhost = [localhost]:11125 , 添加SMTP信息:

relayhost = [localhost]:11125

#### SMTP
# Enable SASL authentication
smtp_sasl_auth_enable = yes
# Disallow methods that allow anonymous authentication
smtp_sasl_security_options = noanonymous
# Location of sasl_passwd
smtp_sasl_password_maps = hash:/etc/postfix/sasl/sasl_passwd
# Enable STARTTLS encryption
# smtp_tls_security_level = encrypt
# Location of CA certificates
smtp_tls_CAfile = /etc/ssl/certs/ca-bundle.crt
smtp_generic_maps = hash:/etc/postfix/generic

15.因为多数免费邮箱限定发信人是登录名(如postmaster@erwo.org),所以在 /etc/postfix/generic 文件里填写可能发信的地址,如:apache

apache postmaster@erwo.org

16.postconf -e 'smtp_host_lookup = dns, native' # 设置postfix dns解析
17./etc/init.d/postfix restart # 重启postfix
18.tail /var/log/maillog # 如有错误,可查看日志

参考:https://randomcentos.wordpress.com/2015/04/21/installing-stunnel-client-on-centos-6-6/

在Debian 9里vi(m)用鼠标远程选定复制文本

场景:日常用ssh远程登录到Debian,用vi来查看配置文件或日志文件,如nginx的,需要复制一些文本内容。

过程:

  1. Debian 8 系统里,vi 命令是 vi “原版”程序

    [root@iZj6c8af]# whereis vi
    vi: /bin/vi /usr/share/man/man1/vi.1.gz
    [root@iZj6c8af]# ls -l /bin/vi
    -rwxr-xr-x. 1 root root 907248 Jul 24  2015 /bin/vi
    [root@iZj6c8af]#
  2. 但在Debian 9系统里,vi命令是指向 vim 了

    root@AY130221:~# whereis vi
    vi: /usr/bin/vi /usr/share/man/man1/vi.1.gz
    root@AY130221:~# ls -l /usr/bin/vi
    lrwxrwxrwx 1 root root 20 Oct 25 14:08 /usr/bin/vi -> /etc/alternatives/vi
    root@AY130221:~# ls -l /etc/alternatives/vi
    lrwxrwxrwx 1 root root 18 Oct 25 14:11 /etc/alternatives/vi -> /usr/bin/vim.basic
  3. vim 相对于 vi 来说,可以提供额外的一些功能,如语法高亮显示等。对于本人的使用习惯,默认的vim配置,当用鼠标选中两个或多个字符时,会自动进入可视化(VISUAL),在vim程序中复制和粘贴,不是复制到本地
  4. vi ~/.vimrc # 创建个人的vim配置文件
  5. syntax on # 添加这行内容,目的是增加语言高亮显示功能,但清除在vim中鼠标选定等功能
  6. 再次运行vi测试,可以在ssh里用鼠标选定和复制文本内容到本地了

参考:

在Debian 9 里安装 strongSwan

strongSwan能提供方便、快捷的加密和认证,适合远程办公,信息交换等场合。

环境:Debian 9,经典网络的阿里云ECS实例。
目的:服务端使用SSL证书,客户端凭用户名和密码登录。

过程:

  1. apt-get update # 更新软件仓库
  2. apt-get install strongswan # 安装 strongswan (5.5.1-4+deb9u1)
  3. apt-get install libcharon-extra-plugins # 安装额外的 plugin,支持Windows客户端常用的MSCHAPV2加密
  4. /etc/ipsec.conf # 编辑配置文件,添加相应的连接配置内容,如下例

     config setup
        # strictcrlpolicy=yes
        uniqueids=never
    
     conn sample-with-ca-cert
      left=%defaultroute
      leftsubnet=0.0.0.0/0
      leftcert=1_yun.anqun.org_bundle.crt
      right=%any
      rightauth=eap-mschapv2
      rightsourceip=10.2.0.0/16
      rightsendcert=never
      eap_identity=%any
      auto=add
    
     conn networkmanager-strongswan
      keyexchange=ikev2
      left=%defaultroute
      leftauth=pubkey
      leftsubnet=0.0.0.0/0
      leftcert=1_yun.anqun.org_bundle.crt
      right=%any
      rightauth=pubkey
      rightsourceip=10.2.0.0/16
      rightcert=client.cert.pem
      auto=add  
    
     conn ios_ikev2
      keyexchange=ikev2
      rekey=no
      leftid=yun.anqun.org
      leftsendcert=always
      leftsubnet=0.0.0.0/0
      leftcert=1_yun.anqun.org_bundle.crt
      right=%any
      rightauth=eap-mschapv2
      rightsourceip=10.2.0.0/16
      rightsendcert=never
      eap_identity=%any
      dpdaction=clear
      fragmentation=yes
      auto=add
    
     conn windows7
      keyexchange=ikev2
      rekey=no
      left=%defaultroute
      leftauth=pubkey
      leftsubnet=0.0.0.0/0
      leftcert=1_yun.anqun.org_bundle.crt
      leftsendcert=always
      right=%any
      rightauth=eap-mschapv2
      rightsourceip=10.2.0.0/16
      rightsendcert=never
      eap_identity=%any
      auto=add
  5. 将SSL证书中的ca文件保存在 /etc/ipsec.d/cacerts 目录,SSL证书中的服务器文件保存在 /etc/ipsec.d/certs , SSL证书的私匙保存在 /etc/ipsec.d/private
  6. /etc/ipsec.secrets # 编辑内容,写明私匙文件名称及用户名和密码等
  7. /etc/sysctl.conf # 如需经服务端转发,请在该文件中添加 net.ipv4.ip_forward=1
  8. iptables -t nat -A POSTROUTING -s 10.2.0.0/16 -o eth1 -j MASQUERADE # 如需iptables筛选流量,请根据出网网卡及用户端IP段设置
  9. 在Windows 7系统及安装有strongSwan应用的安卓手机里测试,可成功连接
  10. 如苹果客户设备没有收到DNS配置信息,可以在 /etc/strongswan.d/charon.conf 里设置dns1和dns2的值

参考:

在nginx里用 http_referer 阻止指定站点的 Referer 请求访问

有网友提问,想在 nginx 阻止指点站点的 referer 来路访问。

环境:CentOS 7,nginx 1.12

过程:

  1. 如想来自 www.baidu.com 和 www.360.cn 的 referer 返回403错误
  2. 在 server 站点配置内容中,在 location 的命令位置上添加以下内容:

    location / {
             valid_referers www.baidu.com www.360.cn;
             if ($invalid_referer = ''){
                     return 403;
             }
     }
  3. 重启nginx后测试,能收到效果

参考:

在 Ubuntu 16 里安装SMRT Analysis 2.3

感谢张天给机会安装。

SMRT Analysis 软件能帮助科研人员对基因测序。单安装包集成tomcat, mysql等,自动安装,挺方便。

环境:Ubuntu 16.04 64位(或许Ubuntu 14更合适些), SMRT Analysis 2.3,计划安装在 /home/smrtanalysis,单机安装,无job manager system。

过程:

  1. sudo adduser smrtanalysis # 添加 smrtanalysis 用户和组
  2. 将安装文件,smrtanalysis_2.3.0.140936.run 和 smrtanalysis-patch_2.3.0.140936.p5.run 上传到 /home/smrtanalysis 目录
  3. su smrtanalysis # 切换到 smrtanalysis 用户
  4. bash smrtanalysis_2.3.0.140936.run -p smrtanalysis-patch_2.3.0.140936.p5.run --rootdir /home/smrtanalysis/ # 开始安装
  5. 问,是否使用 smrtanalysis 运行,保持默认
  6. 环境检测,图中提示ubuntu版本不支持,可能过新(16.04);提示至少需要8个CPU, 本例测试机仅有1个CPU
  7. 问,用什么网址来访问测序程序入口,本例是用swas.anqun.org,默认是用系统中的IP地址
  8. 问,tomcat用哪些端口,本例保持默认的8080
  9. 问,临时目录和数据目录设置在哪里,本例保持默认
  10. 问,mysql使用什么端口,本例保持默认 53306
  11. 问,是否有 job management system,本例选择没有,NONE
  12. 之后就会根据回答,生成配置文件
  13. 安装成功
  14. /home/smrtanalysis/admin/bin/smrtportald-initd start # 启动 tomcat 和 mysql
  15. /home/smrtanalysis/admin/bin/kodosd start # 启动 kodosd
  16. 如果顺利,可以在进程中查询到 tomcat, mysql 和 kodosd 的进程信息
  17. 在 Chrome 浏览器里输入网址,本例是: swas.anqun.org:8080/smrtportal 就可以看到页面内容了
  18. 首次可以点击右上角的 Register 链接,注册默认的 administrator 用户
  19. 注册用户时,要求密码至少八位,且须包含一个特殊字符,如#

参考: