使用nginx运行wordpress

apache和nginx都能搭建网页服务。apache更老牌,功能模块更多,运行更稳定;而nginx运行性能更高,内存消耗更少。 使用apache时,每一个连接请求都对应服务器上一个进程,而在nginx中,多个连接(多达上万个)仅对应服务器上一个进程。相比于apache支持不超过3000个连接请求,nginx能支持高并发连接,每秒最多的并发连接请求理论可以道道5万个。本问讲解在不影响apache情况下额外使用nginx运行wordpress网站。

1. 安装wordpress软件

目前wordpress官网不再对中国内陆提供软件的下载了。需要使用代理下载wordpress软件。此外,最新版本的wordpress需要较高版本的PHP软件,而CentOS6或CentOS7自带的PHP软件版本较低,推荐使用较低版本的wordpress软件,例如:5.1.3版本。

cd /home/chenlianfu
wget https://cn.wordpress.org/latest-zh_CN.tar.gz
tar zxf latest-zh_CN.tar.gz

注意不管是使用apache还是nginx运行wordpress,最终其实都是使用apache用户来对软件目录进行读取或写入。需要使用root用户修改权
相关权限:

usermod -aG chenlianfu apache
chmod 750 /home/chenlianfu
chown -R apache:chenlianfu /home/chenlianfu/wordpress/

2. 安装nginx和php-fpm软件

使用root权限安装nginx和php-frm软件,后者用于让nginx识别php文件。此外,在安装CentOS系统时使用最大化安装,默认安装上了相应的一些mysql和php软件等。

yum install nginx php-fpm

3. 启动php-fpm软件

/etc/init.d/php-fpm restart
chkconfig php-fpm on

需了解的时是,在php-fpm的配置文件/etc/php-fpm.d/www.conf中,默认指定的使用者依然是apache。

4. 修改nginx配置文件

在nginx的主配置文件/etc/nginx/nginx.conf中修改端口号为8088。在CentOS6中可能是修改配置文件/etc/nginx/conf.d/default.conf。

    listen 8088;
#listen 80 default_server;
#listen [::]:80 default_server;

再增加nginx对wordpress的配置文件/etc/nginx/conf.d/wordpress_chenlianfu.conf,其内容为:

server {
    listen 8088;
    server_name www.chenlianfu.com;
    root /home/chenlianfu/wordpress;
    access_log  /var/log/nginx/host.access.log  main;
    location / { 
        try_files $uri $uri/ /index.php?$args;  
        index  index.php;
    }   
    
    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    } 
}

最后,启动php-fpm和nginx服务并设置开机自动启动:

/etc/init.d/nginx restart
chkconfig nginx on

此时,可以在网页上使用8088端口访问nginx运行的wordpress网站了。这需要在浏览器中输入www.chenlianfu.com:8088来访问网站(这使还需要购买该域名并指向服务器的IP地址),比较不方便。

5. 修改apache配置文件实现apache和nginx共用80端口

默认情况下nginx和apache都使用了80端口,形成了冲突。我一般优先使用apache构建网站,有利于对服务器中的文件夹在网页中以目录形式访问。nginx对目录访问的效果较差,访问时其网址最后面一定要加一个目录符号正斜线 / ,否则不能访问其目录。因此,我优先让apache占用80端口,而让nginx占用8088端口。从而两种建站方式同时支持。

为了让nginx的网站直接使用80端口访问,这时,只需要在apache配置文件中设置将对www.chenlianfu.com:80的访问自动转到www.chenlianfu.com:8088即可。在/etc/httpd/conf/httpd.conf最尾部添加信息:

<VirtualHost *:80>
ProxyPreserveHost On
ServerName www.chenlianfu.com
ProxyPass / http://127.0.0.1:8088/
ProxyPassReverse / htt://127.0.0.1:8088/
</VirtualHost>

以上配置信息表示,每当访问www.chenlianfu.com的80端口时,自动转到本地机器的8088端口,即使用nginx提供的网页服务了。从而实现apache和nginx共用80端口的效果了。然后重启apache服务:

/etc/init.d/httpd restart

若敢兴趣的话,其实也可以优先让nginx占用80端口,让apache软件占用8088端口,然后在nginx的配置文件中设置端口转发,实现两个软件对80端口的共用。修改配置文件/etc/nginx/nginx.conf实现端口转发:

location ~ /.*/ {
proxy_pass http://127.0.0.1:8088;
}

将以上信息添加到server { }块中。location能以这则表达式的方法对网址进行解析。上述 ~ / / 表示正则匹配,和perl类似;.* 表示匹配任意内容。因此,上述内容表示将任意网址都转到8088端口上。

搭建邮箱服务并批量化做多个邮箱帐号用于KAAS注释

在使用KAAS网页工具进行注释时,一个邮箱同一时刻仅允许计算一个任务。若需要同时对许多物种进行KAAS分析时,则需要多个邮箱帐号。

若在各公共平台上申请邮箱会比较麻烦。此外,每使用一个邮箱帐号去进行KAAS分析时,然后登录一个个邮箱确认提交任务和查看结果是很麻烦的。因此,我在我的Aliyun服务器上直接创建很多邮箱帐号,然后用这些帐号进行KAAS分析,KAAS返回的邮件统一转到我的个人帐号,再进行后续的提交和结果查询。

1. 在万网上购买域名并进行域名解析

我购买的域名是chenlianfu.com,并将该域名解析中的A指向我的Aliyun服务器的IP地址,将MX指向chenlianfu.com。从而能让邮件识别我的域名并发送到我的Aliyun服务器上。

2. 在Aliyun服务器上通过postfix启动邮箱服务

默认设置下,CentOS6系统自带postfix软件。首先,修改postfix的配置文件/etc/postfix/main.cf内容,需要修改的几行如下:

myhostname = chenlianfu.com  # 用于设置主机名,表示邮箱账户为linux系统用户后加 @chenlianfu.com 。
inet_interfaces = all  # 能接受所有来源的邮件
#inet_interfaces = localhost  # 关闭默认的设置,默认仅接收来源本机的邮件
mydestination = $myhostname, localhost.$mydomain, localhost, chenlianfu.com

message_size_limit = 100000000
mailbox_size_limit = 200000000 # 在centos8系统中要添加该参数值比message_size_limit值大,否则postfix后台运行状态不正常,导致用户没法查看邮件信息。

然后,防火墙开放25号端口:

iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 25 -j ACCEPT
service iptables save
/etc/init.d/iptables restart

最后启动postfix服务,则CentOS6系统中的用户可以接收来自其余人发送的邮件了。

/etc/init.d/postfix restart

若需要查看或寄送邮件,则输入命令 mail 即可:

mail

3. 在Aliyun服务器上创建多个系统用户

使用root权限创建50个账户:

perl -e 'foreach (1..50) { $_ = '0' . $_ if length($_) == 1; print "um$_\n"; } ' > users.txt
for i in `cat users.txt`
do
    useradd $i
    echo '123456' | passwd --stdin $i
done

为了简单演示,以上创建的用户密码都为123456,这里不太推荐使用如此简单的密码。

同时,需要设置当邮件发送到这些用户时,会自动转发到我的常用帐号所对应的邮箱中。我在Aliyun服务器上的账号名称是chenlianfu,对应的邮箱名称为chenlianfu@chenlianfu.com。通过使用root权限修改配置文件/etc/aliases文件来实现邮件转发。

for i in `cat users.txt`
do
    echo "$i:    chenlianfu,$i"
done >> /etc/aliases

为了使配置文件/etc/aliases生效,重启postfix即可:

/etc/init.d/postfix restart

4. 现在,即可使用这50个账号了。

封禁一些IPs的SSH登录,保护服务器安全

登录服务器的root用户时,可能会收到如下提示:

There were 3225 failed login attempts since the last successful login.

这表示有很黑客在尝试用一些用户和密码登录服务器。为了保障服务器安全,则可以在日志文件/var/log/secure中查看攻击的IPs来源和其失败登录的次数。例如:

Invalid user neisius from 211.144.12.75 port 34041
Failed password for invalid user server from 219.94.99.133 port 15139 ssh2
pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=106.12.217.39

若某个IP次数很高,则将其IP信息添加到/etc/hosts.deny文件中进行封禁。例如,修改/etc/hosts.deny文件内容:

sshd:101.109.83.140
sshd:103.27.238.202
sshd:104.236.94.202
sshd:106.12.200.13
sshd:106.12.217.39
sshd:106.54.19.67
sshd:111.230.73.133
sshd:117.50.45.254
sshd:118.24.38.53
sshd:122.155.223.119

为了能自动地封禁IPs,编写名为IP_denied_for_ssh_security.pl的perl程序:

#! /usr/bin/perl
use strict;

my $usage = <<USAGE;
Usage:
    $0 <num>

    运行程序后,程序读取/var/log/secure文件中信息。若存在某个IP登录失败(含有Invalid user|Failed password|authentication failure等信息)次数超过指定的次数,则是需要封禁的IP。此外,程序再读取/etc/hosts.deny文件中的IP信息,得到所有需要封禁的IP。然后程序将这些IP信息全部写入到/etc/hosts.deny文件中进行封禁。
    程序需要以root权限运行,因为只有root权限才能读取/var/log/secure文件,对/etc/hosts.deny进行写入。
    程序运行完毕后,会清空/var/log/secure文件内容。

USAGE
if(@ARGV==0){die $usage}

open IN, "/var/log/secure" or die "Can not open file /var/log/secure, $!";
my %num;
while (<IN>) {
    if (m/Invalid user/ or m/Failed password/ or m/authentication failure/) {
        $num{$1} ++ if m/(\d+\.\d+\.\d+\.\d+)/;
    }
}
close IN;

my %deny;
my $deny_num = 0;
foreach (keys %num) {
    if ($num{$_} >= $ARGV[0]) {
        $deny{$_} = 1;
        $deny_num ++;
    }
}
print STDERR "$deny_num IPs were detected for blocking from file /var/log/secure.\n";

open IN, "/etc/hosts.deny" or die "Can not open file /etc/hosts.deny, $!";
while (<IN>) {
    $deny{$1} = 1 if m/(\d+\.\d+\.\d+\.\d+)/;
};
close IN;

open OUT, ">", "/etc/hosts.deny" or die "Can not create file /etc/hosts.deny, $!";
my $total_num = 0;
foreach (sort keys %deny) {
    print OUT "sshd:$_\n";
    $total_num ++;
}
close OUT;
print STDERR "Total $total_num IPs were banned by file /etc/hosts.deny for SSH security.\n";

open OUT, ">", "/var/log/secure" or die "Can not  create file /var/log/secure, $!";
close OUT;

使用root用户执行该perl程序,若登录失败次数>=3次,则封禁对应的IP。

IP_denied_for_ssh_security.pl 3

基因正选择分析原理

一、 正选择分析的目的:

  1. 两两基因的密码子序列进行比较,从而计算dN/dS,即omega(ω)值。若该值<1,则表示纯化选择;omega = 1,则中性进化;omega > 1,则正选择。若分析基因在两个物种中的序列,可以计算dN/dS的值,若omega > 1,即表明该基因在物种进化过程中,即由其祖先物种分化成这两个物种时,基因受到了正选择。对于两个物种/序列的正选择分析,比较简单。而实际情况中,要分析的物种数量很多,包含多个类群。这个时候的正选择分析相对复杂些。
  2. 对多个物种的基因序列进行正选择分析,若仍然按照两个物种时的要求,即分析该基因在物种进化中是否受到了正选择?这种结果可能不好说清楚。因为该基因可能在某一类群中序列很相似,其两两比较时,omega <= 1;而在另外一类群中两两比较时,很多时候omega > 1。最后软件可以从总体上给一个omega值,该值不可以拿来简单地评价该基因是否受到了正选择。所以,对多个物种进行正选择分析时,没法直接评价该基因是否受到了正选择。正选择只有在进行两两序列比较的时候,才能计算omega值,从而得到结果。
  3. 对基因在多个物种上的正选择分析,分析的目的则是:比较某个分枝上祖先节点和后裔节点(可以理解成,对无根树上某分枝两侧的两组物种进行比较,依然属于两两比较),从而计算该分枝的omega值。而在实际数据中,基因在不同的进化分枝上具有不同的omega值,同时在序列不同的位点也具有不同的omega值。目标分枝两侧的物种数量较多时,可以对序列上的每个位点进行omega值分析,从而鉴定正选择位点。所以,对基因在多个物种上的正选择分析,需要同时分析分析目标分枝的omega值和序列位点的omega值,从而判断基因是否受到正选择压。

二、使用PAM对基因进行正选择分析,有三种方法:

  1. PAML site model: 主要用于检测基因中的正选择位点。该方法分析时,认为进化树中各分枝的omega值是一致的,并比较两种模型:(1)模型m1是null model,认为所有位点的omega值<1或=1; (2)模型m2是正选择模型,存在omega <1、=1或> 1的位点。比较两个模型的似然值(lnL)差异,利用卡方检验(自由度为2)算出p值。若p值 < 0.05,则否定null model,认为存在正选择位点。此外,推荐采用比较模型m7和m8,它们将omega值分成了10类,其p值结果比上一种比较方法更宽松,能检测到更多的正选择基因。使用PAML site model方法能在整体水平上检测基因的正选择位点,而不能表明基因在某个进化分枝上是否受到正选择压。
  2. PAML branch-site model: 主要用于检测基因在某个进化枝上是否存在的正选择位点。该分析方法认为目标分化枝具有一个omega值,其它所有分枝具有一个相同的omega值,然后再检测正选择位点。同样对两种模型进行比较:(1)第一种模型为模型2,将omega值分成<1、=1、>1的三类,这和site model中的一样;(2)第二种模型和前者一致,只是将omega固定成1,作为null model。比较两种模型的似然差异,利用卡方检验(自由度为2)算p值(chi2命令算出的值除以2)。若p值< 0.05,则能通过Bayes Empirical Bayes (BEB)方法计算正选择位点的后验概率,若存在概率值 > 0.95正选择位点,则表示基因在目标分枝上受到正选择压。PAML软件在branch-site模式下,并不给出分枝上的omega值。这表示branch-site模式虽然考虑了目标分枝上具有不同的omega值,但仍然以分析位点上的omega为主。值得注意的是,在branch-site模式下可能检测到正选择位点,但在目标分枝上的omega值仍然可能低于1。可能软件作者基于这点考虑,就没有给出目标分枝上的omega值,以免影响一些人对正选择结果的判断。
  3. PAML branch model: 主要用于检测在某个分枝上,其omega值是否显著高于背景分枝,即基因在目标分枝上进化速度加快。该方法认为基因序列上所有位点的omega值是一致的,对两种模型进行比较:(1)第一种模型为null model,所有分枝具有相同的omega值;(2)第二种模型认为目标分枝具有一个omega值,其它所有分枝具有一个相同的omega值。比较两种模型的似然差异,利用卡方检验(自由度为1)算p值。若p值 <= 0.05,且目标分枝上的omega值高于背景值,则认为该基因为快速进化基因。一般情况下,该方法计算得到的p值会低于第二种方法的结果。

三、其它注意事项

Branch-site model相比于site model的优点是考虑了不同的分枝具有不同的选择压,即具有不同的omega值。该方法让目标分枝具有一个不同的omega值,并没有让所有分枝的omega值独立进行计算(理论上这样是最好的)。这样算法很复杂,程序运行非常非常消耗时间。但其实也没必要这样做,因为正选择分析其实是两条序列比较后,分析dN/dS,再找正选择位点,其分析结果就应该是某个分枝上基因是否受到正选择,在序列那个位点上受到正选择。

若在目标分枝上,其omega值小于1,但是却能找到正选择位点。即该基因在该分枝上的dN/dS < 1,但是在某些位点上,dN/dS > 1。那么该基因是否属于正选择基因?我认为:属于。之所以为正选择基因,主要是因为基因的个别位点或多个位点存在正选择。当只有个别位点受到正选择压时,而其它多个位点存在纯化选择时,可能导致整体上的omega值小于1。此时,该基因也应该是属于正选择基因。

四、参考文献中的正选择分析方法描述

Science文章(https://science.sciencemag.org/content/364/6446/eaav6202)中的正选择基因分析方法:To estimate the lineage-specific evolutionary rate for each branch, the Codeml program in the PAML package (version 4.8) (134) with the free-ratio model (model = 1) was run for each ortholog. Positive selection signals on genes along specific lineages were detected using the optimized branch-site model following the author’s recommendation. A likelihood ratio test (LRT) was conducted to compare a model that allowed sites to be under positive selection on the foreground branch with the null model in which sites could evolve either neutrally and under purifying selection.[ The p values were computed based on Chi-square statistics, and genes with p value less than 0.05 were treated as candidates that underwent positive selection. We identified PSGs at the ancestral branch of Ruminantia (table S22), the ancestral branch of Pecora (table S23), each ancestral family branch of Ruminantia (tableS24), and each ancestral subfamily branch of Bovidae (table S24). We also compared the dN/dS values of Ruminantia families with outgroup mammals (fig. S52).

Science文章(https://science.sciencemag.org/content/364/6446/eaav6202)中快速进化基因分析方法:The branch model in PAML was used, with the null model (model=0) assuming that all branches have been evolving at the same rate and the alternative model (model=2), allowing the foreground branch to evolve under a different rate. An LRT with df =1 was used to discriminate between alternative models for each ortholog in the gene set. Genes with a p value less than 0.05 and a higher ω value for the foreground than the background branches were considered as evolving with a significantly faster rate in the foreground branch.


https://journals.plos.org/plosntds/article?id=10.1371%2Fjournal.pntd.0007463文献中对正选择基因的分析方法:

A calculation of mutational rate ratio ω between two gene sequences was the basis for the positive selection analysis. The ω was calculated as a ratio of nonsynonymous to synonymous mutational rates. The ratio indicates negative purifying selection (0 < ω < 1), neutral evolution (ω = 1), and positive selection (ω > 1) [54]. A set of selected genes from complete genomes was tested relative to positive selection using the maximum likelihood method using the CODEML of the PAML software package [55]. PAML version 4 [56] and its user interface PAMLX [57] were used in our study. For each analyzed gene, its maximum likelihood phylogenetic tree was used as an input tree. The CODEML offers several different codon evolutionary models, and the statistical likelihood ratio test (LRT) was used to compare the codon evolutionary model to the null model. The Bayes empirical Bayes method (BEB) [58] was then used to evaluate the posterior probability of sites considered to have been positively selected.

The CODEML models could produce different results (i.e., a list of sites under positive selection) since they calculate different parameter estimates. Site models allow ω to vary in each site (codon) within the gene. Statistical testing was required for sites with ω > 1. Two pairs of models were predominantly used since their LRTs have low false-positive rates. M1a (nearly neutral evolution) was compared to M2a (positive selection) [58,59] and M7 (beta) was compared to M8 (beta & ω) [60]. Our preliminary testing found that the two model pairs gave the same or very similar results. Therefore we chose to use the M7-M8 model pair. The M7 model is a null model that allows 10 classes of sites with a ω beta-distribution within the interval 0 ≤ ω ≤ 1. Sites with ω > 1 are not allowed. The alternative M8 model adds an eleventh class of sites with ω > 1. Each site was tested to determine the class to which it belongs. The LRT compares twice the log-likelihood difference 2Δl = 2(l1-l0) between the M7 model (log likelihood value l0) and the M8 model (log likelihood value l1) to the χ2 distribution [61]. If the twice log-likelihood difference is above a critical χ2 value, then the null model is rejected, and the positive selection is statistically significant.

A considerable disadvantage of the site models is that ω was calculated as an average over all codons of the site. Therefore, the site models are not suitable for the data where ω also varies between lineages. In contrast, the branch-site models search for positive selection in sites and pre-specifies lineages where different rates of ω may occur [62]. Sequences of lineages are a priori divided into a group of foreground lineages where positive selection may occur and group of background lineages where only purifying selection or neutral evolution occurs. We used branch-site model A, which allows four classes of sites and different setups of foreground lineages to be tested depending on the gene phylogeny. In branch-site model A, all lineages under purifying selection with a low value of ω0 belong to site class 0. Weak purifying selection and neutral evolution with ω1 near to value 1 are allowed in site class 1. In site class 2a, a proportion of class 0 sites in foreground lineages is under positive selection with ω2 > 1. Similarly, site class 2b is a proportion of class 1 sites under positive selection with ω2 > 1. The null model for LRT has ω2 = 1. Critical values of LRT (2Δl) are 2.71 at 5% and 5.41 at 1% [63]. The posterior probabilities of suggested sites under positive selection were calculated using the BEB method.

使用squid搭建代理服务器

使用squid可以搭建代理服务器,可以用于翻墙访问国外网站。这里讲解通过在校内服务器上搭建squid代理服务,用于校外通过校内的代理服务器下载文献。

1. 在校内服务器上安装squid软件,并启动squid服务。

使用root权限在学校内网中安装有CentOS7系统的服务器上安装squid软件:

yum install squid

再修改squid配置文件,以让所有其它IP地址的用户可以访问校内服务器:

perl -p -i -e 's/http_access deny all/http_access allow all/' /etc/squid/squid.conf

启动squid服务:

systemctl start squid.service

2. 将代理服务器的3128端口映射到外网Aliyun服务器上的31280端口

squid代理服务器使用的默认端口是3128。若此时将内网服务器的防火墙开放3128端口,则在个人电脑上代理设置上填写内网服务器的固定IP和3128端口(见本文第4部分),在个人电脑上的浏览器访问网络时,就是通过代理服务器来访问了。

若是国外服务器上做的代理,则防火墙开放3128端口,可以在国内访问国外代理服务器进行翻墙。

firewall-cmd --add-port=3128/tcp --permanent 
systemctl restart firewalld.service 

由于学校内网一般对外封闭了所有的端口,在校外依然是无法使用代理服务器的。因此,需要通过一个具有外网固定IP的服务器来进行中转。我这儿就使用了Aliyun上购买的一台具有固定IP的云服务器进行中转。中转时不需要校内的服务器开放防火墙3128端口。

中转的方法是使用ssh进行反向隧道连接,在内网服务器上输入反向隧道命令,将内网服务器的3128端口映射到Aliyun服务器的31280端口。这样当访问Aliyun服务器的31280端口时,就等同于在内网服务器上直接访问3128端口了。

ssh -f -N -R 31280:localhost:3128 chenlianfu@115.29.105.xxx

3. 在校外有固定IP的Aliyun服务器防火墙上开放31280端口的访问

使用root用户在Aliyun服务器上操作,开放防火墙31280端口,以利于个人电脑能访问Aliyun服务器的31280端口。

firewall-cmd --add-port=31280/tcp --permanent 
systemctl restart firewalld.service

4. 个人Windows10电脑上设置代理访问

按windows+x键,再按字母n,打开系统设置界面;点击网络和internet,再点击代理;在下半个页面的手动设置代理部分,打开使用代理服务器开关,然后在地址栏填写Aliyun服务器的IP地址115.29.105.xxx,在端口栏填写31280,最后点击保存。

然后打开浏览器,输入网址,即可通过校内的代理服务器访问网络。这时等同于在学校连接校园网后的网络访问。当用IE浏览器访问网址,若代理服务器没生效,IE浏览器会报告正在使用某个IP某个端口进行代理访问,代理不成功等信息。

成功后,示例访问文献https://doi.org/10.1016/j.molp.2020.05.005,若能查看文献全文和下载PDF全文,则表示成功。