生产环境下ftp的迁移并构建高可用

       说明:这是1个小项目就两台DELL的服务器,和一台IP SAN存储(DELL MD3200i)。原来是4台小服务器,而且服务器太老了,经常有问题,这回相当于一次ftp的迁移,以前用的是proftp,这次换成了vsftp。数据量有2.5T。
拓扑很简单:

技术文章

系统:CENTOS 6.4(64bit)
高可用软件:corosync+pacemaker
host:ftp1 192.168.1.190
          ftp2  192.168.1.191
stonith(ipmi):ftp1 192.168.1.180 

                               ftp2 192.168.1.181

       MD3200i这个存储,配置很简单和FC SAN的存储配置没啥太大的区别,实在不行就打金牌服务,DELL的售后会给发相关的文档。我做了1个group,里面有2个主机,共享2个lun。这2个lun可以同时被2台服务器认到的,也就是说1台服务器挂载一个LUN,如果其中一台服务器坏了,另外一台可以挂载2个LUN,当然这个过程是靠双机软件来实现的。以前做很多项目都用的是RHCS,这次选择corosync+pacemaker

 

1.使用UDEV绑定iscsi  initiator

 

MD3200i,其实就是iscsi的target端,服务器就是iscsi的initiator,有人也许不用udev来绑定target提供的LUN。开始我也没用,但做的过程时,确实还是出现了怪问题,所以后来果断使用UDEV绑定别名。

[root@ftp1  ~]# iscsiadm -m discovery -t st -p 192.168.130.101:3260
[root@ftp1  ~]# iscsiadm -m node  -T iqn..... -p 192.168.130.101:3260 -l #iqn.....根据实际情况写, 192.168.130.101 是存储的控制卡ip。
[root@ftp1  ~]# scsi_id --whitelisted --replace-whitespace /dev/sdb
36f01faf000ec79db000004993e46b6a0
[root@ftp1  ~]# scsi_id --whitelisted --replace-whitespace /dev/sdc
36f01faf000ec77c2000003f95356cbab
[root@ftp1  ~]# vim /etc/udev/rules.d/99-ftp.rules     #这个文件是自己创建的
KERNEL=="sd*",SUBSYSTEM=="block",PROGRAM="/sbin/scsi_id --whitelisted --replace-whitespace /dev/$name",RESULT=="36f01faf000ec79db000004993e46b6a0",NAME="mydisk1"
KERNEL=="sd*",SUBSYSTEM=="block",PROGRAM="/sbin/scsi_id --whitelisted --replace-whitespace /dev/$name",RESULT=="36f01faf000ec77c2000003f95356cbab",NAME="mydisk2"
[root@ftp1  ~]#start_udev
这个还得配置多路径的,但是服务器的网卡 不够用了,就只配了一条,服务器和存储是直连的没有走交换机。
然后就去 /dev/下面验证是否有mydisk1,mydisk2,有则说明成功。
ftp2也进行上面相关的操作。
然后进行集群配置前的相关准备工作(最好装完系统就进行的):
1).进行时间同步
2).确认主机名是否解析正确,/etc/hosts 以及uname -n
3).确认NetworkManager是否关闭,这个东西必须关闭。(很鸡肋的东西)
 

2.安装,配置corosync

 

[root@ftp1  ~]# yum install pacemaker corosync rpm-build -y
[root@ftp1  ~]#yum install python-lxml  cluster-glue-libs-devel pacemaker-libs-devel asciidoc  autoconf automake libtool redhat-rpm-config  -y
安装crmsh,以前有编译好的rpm包,所以可以使用
[root@ftp1  ~]#yum install --nogpgcheck localinstall crmsh-1.2.6-4.el6.x86_64.rpm
[root@ftp1  ~]# vim /etc/corosync/ corosync.conf
compatibility: whitetank
totem {
version: 2
secauth: on
threads: 0
interface {
ringnumber: 0
bindnetaddr: 192.168.1.0
mcastaddr: 226.94.1.1
mcastport: 5405
ttl: 1
}
}
logging {
fileline: off
to_stderr: no
to_logfile: yes
to_syslog: no
logfile: /var/log/cluster/corosync.log
debug: off
timestamp: on
logger_subsys {
subsys: AMF
debug: off
}
}
amf {
mode: disabled
}
service {
ver: 0
name: pacemaker
}
aisexec {
user: root
group: root
}
[root@ftp1 corosync]#corosync-keygen #生成key,使用/dev/random生成随机数,这时可能需要敲击键盘,安装些包,卸载包来生成随机数
[root@ftp1 corosync]# scp corosync.conf authkey ftp2:/etc/corosync/
[root@ftp1 ~]#/etc/init.d/corosync start
校验是否正常工作:
查看corosync引擎是否正常启动:
[root@ftp1 ~]# grep -e "Corosync Cluster Engine" -e "configuration file" /var/log/cluster/corosync.log
corosync [MAIN  ] Corosync Cluster Engine (‘1.4.1‘): started and ready to provide service.
corosync [MAIN  ] Successfully read main configuration file ‘/etc/corosync/corosync.conf‘.
查看初始化成员节点通知是否正常发出:
[root@ftp1 ~]# grep  TOTEM  /var/log/cluster/corosync.log
corosync [TOTEM ] Initializing transport (UDP/IP Multicast).
corosync [TOTEM ] Initializing transmit/receive security: libtomcrypt SOBER128/SHA1HMAC (mode 0).
corosync [TOTEM ] The network interface [172.16.0.11] is now up.
corosync [TOTEM ] A processor joined or left the membership and a new membership was formed.
corosync [TOTEM ] A processor joined or left the membership and a new membership was formed.
检查启动过程中是否有错误产生。下面的错误信息表示packmaker不久之后将不再作为corosync的插件运行,因此,建议使用cman作为集群基础架构服务;此处可安全忽略。
[root@ftp1 ~]# grep ERROR: /var/log/cluster/corosync.log | grep -v unpack_resources
Apr 02 21:55:08 corosync [pcmk  ] ERROR: process_ais_conf: You have configured a cluster using the Pacemaker plugin for Corosync. The plugin is not supported in this environment and will be removed very soon.
Apr 02 21:55:08 corosync [pcmk  ] ERROR: process_ais_conf:  Please see Chapter 8 of ‘Clusters from Scratch‘ (http://www.clusterlabs.org/doc) for details on using Pacemaker with CMAN
[root@ftp1 ~]# ps auxf
corosync
\_ /usr/libexec/pacemaker/cib    #集群信息基库
\_ /usr/libexec/pacemaker/stonithd  #stonish
\_ /usr/libexec/pacemaker/lrmd    #ra需要本地代理  本地资源管理器
\_ /usr/libexec/pacemaker/attrd   #管理集群资源属性
\_ /usr/libexec/pacemaker/pengine #策略引擎
\_ /usr/libexec/pacemaker/crmd  #资源管理

ftp2 做类似的操作,两边都OK了,就开始使用crmsh 来进行资源配置。

 

3.使用crm进行资源配置

 

[root@ftp1 corosync]# yum install ipmitool -y
[root@ftp1 corosync]# /etc/init.d/ipmi start
[root@ftp1 corosync]# chkconfig ipmi on
[root@ftp1 corosync]# ipmitool lan set 1 ipaddr 192.168.1.180
[root@ftp1 corosync]# ipmitool lan set 1 netmask 255.255.255.0
[root@ftp1 corosync]# ipmitool user list 1 # 显示当前用户列表
#[root@ftp1 corosync]#ipmitool lan set 1 password 123123 #这个我没修改,使用的DELL的默认密码 calvin
这个是ftp1做的设置,配置ftp2一样换个ip,192.168.1.181
这个也可以在bios中设置ipmi的。
[root@ftp1 corosync]#yum install fence_agents #安装fence agents,这里面有我想要的fence_ipmilan,也就是stonith设备
[root@ftp1 corosync]# crm configure property  no-quorum-policy=ignore  #在双节点集群中,由于票数是偶数,当心跳出现问题(脑裂)时,两个节点都将达不到法定票数,默认quorum策略会关闭集群服务,为了避免这种情况,配置quorum策略为【ignore】。
[root@ftp1 corosync]# crm configure #配置stonith
crm(live)configure# primitive ipmi_1 stonith:fence_ipmilan params ipaddr=192.168.1.180 login=root passwd=calvin action=reboot pcmk_reboot_action=reboot pcmk_host_list="ftp1 ftp2" pcmk_monitor_action=status op monitor interval=30 timeout=60 op start timeout=120 op stop timeout=120
crm(live)configure# primitive ipmi_2 stonith:fence_ipmilan params ipaddr=192.168.1.181 login=root passwd=calvin action=reboot pcmk_reboot_action=reboot pcmk_host_list="ftp1 ftp2" pcmk_monitor_action=status op monitor interval=30 timeout=60 op start timeout=120 op stop timeout=120
crm(live)configure# location fence1 ipmi_1 100: ftp2
crm(live)configure# location fence2 ipmi_2 100: ftp1
crm(live)configure# location fence1_on_2 ipmi_1 -inf: ftp1
crm(live)configure# location fence2_on_1 ipmi_1 -inf: ftp2
crm(live)configure# verify
crm(live)configure# commit

配置2个LUN的lv

[root@ftp1 ~]# mkdir -pv /ftp/data1
[root@ftp1 ~]# mkdir -pv /ftp/data2 #ftp2 也创建
[root@ftp1 ~]# pvcreate /dev/mydisk1
[root@ftp1 ~]# pvcreate /dev/mydisk2
[root@ftp1 ~]# vgcreate vg_ftp1 /dev/mydisk1
[root@ftp1 ~]# vgcreate vg_ftp2 /dev/mydisk2
[root@ftp2 ~]# vgscan #在ftp2上检查vg是否存在
[root@ftp1 ~]# lvcreate -L 1.7t -n lv_ftp1 vg_ftp1
[root@ftp1 ~]# lvcreate -L 1.7t -n lv_ftp2 vg_ftp2
[root@ftp1 ~]# mkfs.ext4 /dev/vg_ftp1/lv_ftp1
[root@ftp1 ~]# mkfs.ext4 /dev/vg_ftp2/lv_ftp2
[root@ftp2 ~]# lvscan #没有的话就用lvchange -ay 来激活lv,然后挂载试试,来判断是否操作成功。
#我没对mydisk1进行分区操作,然后变成8e,再然后进行pvcreate,这是个规范的流程吧,我图省事。

进行lv以及文件系统的资源操作:

[root@ftp1 ~]# crm configure
crm(live)configure# primitive ftp1_lvm ocf:heartbeat:LVM params volgrpname=vg_ftp1 op monitor interval=30 timeout=60 op start timeout=60 op stop timeout=60 on-fail=restart
crm(live)configure# primitive ftp2_lvm ocf:heartbeat:LVM params volgrpname=vg_ftp2 op monitor interval=30 timeout=60 op start timeout=60 op stop timeout=60 on-fail=restart
crm(live)configure# primitive ftp1_store ocf:heartbeat:Filesystem params device="/dev/vg_ftp1/lv_ftp1" directory=/ftp/data1 fstype=ext4 op monitor interval=30 timeout=60 op start timeout=60 op stop timeout=60 on-fail=restart
crm(live)configure# primitive ftp2_store ocf:heartbeat:Filesystem params device="/dev/vg_ftp2/lv_ftp2" directory=/ftp/data2 fstype=ext4 op monitor interval=30 timeout=60 op start timeout=60 op stop timeout=60 on-fail=restart
crm(live)configure# order lvm1_before_store inf: ftp1_lvm: start ftp1_store: start
crm(live)configure# order lvm2_before_store inf: ftp2_lvm: start ftp2_store: start

配置ip(这个ip 是公网IP),但是我就写172.16网段来代替了。

crm(live)configure#  primitive ftp1_ip cof:heartbeat:IPaddr2 params ip=172.16.1.1 cidr_netmask=24 nic=em1 iflabel=1 op monitor interval=20 timeout=20 on-fail=restart
crm(live)configure#  primitive ftp2_ip cof:heartbeat:IPaddr2 params ip=172.16.1.2 cidr_netmask=24 nic=em1 iflabel=1 op monitor interval=20 timeout=20 on-fail=restart

配置group 把ip和lvm,文件系统绑到一个组里

crm(live)configure# ftp1_server ftp1_lvm ftp1_store ftp1_ip
crm(live)configure# ftp2_server ftp2_lvm ftp2_store ftp2_ip
配置默认路由,由于使用的是vip,来提供服务,所以得需要配置vip相关的默认路由
crm(live)configure# primitive ftp_gw ocf:heartbeat:Route params destination=default gateway=172.16.1.254 op monitor interval=20 on-fail=restart
crm(live)configure# clone cl_ftp_gw ftp_gw meta clone-max=2 clone-node-max=1 notify=true

配置ip与路由的关系,ip要在路由之前启动

crm(live)configure# order ip1_before_gw inf: ftp1_ip cl_ftp_gw
crm(live)configure# order ip2_before_gw inf: ftp2_ip cl_ftp_gw
#

配置ftp1_server 组在 ftp1 节点上,ftp2_server 在ftp2 节点上

crm(live)configure# location server1_on_ftp1 ftp1_server 200: ftp1
crm(live)configure# location server2_on_ftp2 ftp2_server 200: ftp2
crm(live)configure# verify
crm(live)configure# commit
最后commit,进行验证:
crm status 来查看,正常的话会显示ftp1_server 在ftp1 上 然后检查ip,挂载点;同理检查ftp2。
到这corosync+pacemaker的双机配置完成,但是这只是做的ip+文件系统以及路由的双机配置,而vsftpd没有加入,因为两台都启动vsftpd服务,我在两台都分别启动vsftpd,并做相关配置以及对vsftpd进行监控。我写了个简单的检测vsftpd服务的脚本,如果发现vsftpd提供不了服务会进行自动重启。

#!/bin/bash
LOG_FILE=/var/log/watch.log
vsftpd="/etc/init.d/vsftpd"
FTPPORTNUM=`netstat -lnt|grep 21 | grep -v grep|wc -l`
FTPPRONUM=`ps -ef | grep vsftpd | grep -v grep | wc -l`
[ ! -f $LOG_FILE ] && touch $LOG_FILE
if [[ "$FTPPORTNUM" < "1" || "$FTPPRONUM" < "1" ]];then
echo -e "vsftpd is not running\n" >> $LOG_FILE
echo "Preparing start vsftpd..." >> $LOG_FILE
sleep 1
while true
do
killall vsftpd > /dev/null 2>&1
[ $? -ne 0 ] &&  break;
sleep 1
done
$vsftpd restart > /dev/null 2>&1 &&  echo "vsftpd already restared" >> $LOG_FILE
fi

把脚本放到crontab中。

接着进行数据迁移,这个数据同步是个很纠结的过程,因为线上的FTP还不能断,所以是漫长的等待。我把corosync给关闭,vsftpd也关闭,只把lv进行挂载:

[root@ftp1 ~]# mount  /dev/vg_ftp1/lv_ftp1 /ftp/data1
[root@ftp2 ~]# mount /dev/vg_ftp2/lv_ftp2 /ftp/data2 #每台机器挂一个LUN。

接着使用的rsync来同步,这个rsync 基本谁都会的,不是重点就略过了。

 

4.进行vsftd的配置

 

这个vsftp的配置,网上一搜一大把,我这个包含了虚拟用户的配置

[root@ftp1 ~]# vim /etc/vsftpd/vsftpd.conf
anonymous_enable=YES
local_enable=YES
write_enable=YES
local_umask=022
ftp_username=ftp
anon_root=/ftp
anon_upload_enable=NO
anon_world_readable_only=NO
anon_mkdir_write_enable=NO
anon_other_write_enable=NO
max_per_ip=4
max_clients=2000
anon_max_rate=100000
guest_enable=YES
guest_username=user1
virtual_use_local_privs=YES
pam_service_name=vsftpd.vu
user_config_dir=/etc/vsftpd/vsftpd_user_conf
chroot_local_user=YES
chroot_list_enable=NO
pasv_enable=yes
cmds_denied=LIST
pasv_min_port=3000
pasv_max_port=3500
dirmessage_enable=YES
xferlog_enable=YES
xferlog_file=/var/log/vsftpd.log
xferlog_std_format=YES
listen=YES
userlist_enable=YES
tcp_wrappers=YES
#我们规定是不允许匿名用户list的,也就是说只给用户下载链接,不让用户随便list下载的。

建立虚拟用户:

[root@ftp1  ~]# vim /tmp/user.txt
ftp1
password1
ftp2
password2
[root@ftp1  ~]# db_load -T -t hash -f /tmp/user.txt /etc/vsftpd/vsftpd_login.db
配置pam文件
[root@ftp1  ~]# vim /etc/pam.d/vsftpd.vu
auth required /lib64/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login
account required /lib64/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login

建立虚拟用户对应的真实用户:

[root@ftp1 ~]# useradd user1 -s /sbin/nologin
[root@ftp1 ~]# chown -R user1 /ftp/data1
[root@ftp1 ~]# chown -R user1 /ftp/data2

配置虚拟用户配置文件:

[root@ftp1 ~]# vim  /etc/vsftpd/vsftpd_user_conf/ftp1
write_enable=YES
anon_world_readable_only=YES
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
local_umask=022
download_enable=YES
local_root=/ftp/data1
cmds_denied=none
[root@ftp1 ~]# vim  /etc/vsftpd/vsftpd_user_conf/ftp2
write_enable=YES
anon_world_readable_only=YES
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
local_umask=022
download_enable=YES
local_root=/ftp/data1
cmds_denied=none
       ftp1和ftp2 用户是作为上传文件使用的用户,这个是有专门人来上传资料,然后给会员提供下载(只给链接)。

        ftp2做同样的操作,测试vsftpd服务,进行下载,上传。没有问题的话,启动corosync,再做下测试,同时也可以做下拔网线,看另外一台是否会被stonithd掉(重启)。这样两台ftp都同时使用,一台有问题时,还可以进行切换,属于双活的状态吧。实际中,我们的用户和密码不是这么简单的。

注意:selinux要关闭,以及iptables配置前要关闭,所有的服务都配置好了之后,关闭不用的服务,只留ssh与vsftpd以及corosync的相关服务,最后都测试正常了再写iptables规则,vsftpd使用的是被动模式,这个配置防火墙时要注意了,要放行min_port和max_port,ssh也要修改端口,禁止root登录,我使用的pubkey认证没有使用密码。(小项目,没有使用跳转机)



本文出自 “小鱼儿” 博客,请务必保留此出处http://xiaoyuer3.blog.51cto.com/8622790/1405180

生产环境下ftp的迁移并构建高可用,布布扣,bubuko.com

文章来自:http://xiaoyuer3.blog.51cto.com/8622790/1405180
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3