目前公司的本地Linux账号采用NIS服务来统一验证登陆,而且共享/home目录供其余开发服务器挂载。bash
因为老的服务器硬盘空间已不足以支持使用,现新购了一台服务器取代旧服务器,NIS和NFS服务都要迁移到新服务器上。服务器
给新的服务器设置好磁盘阵列Raid 5后,安装Linux操做系统,并划分较大独立分区给/home目录供开发用户使用。ide
系统安装成功后,安装相应的应用软件, rpcbind, nfs-utils, ypbind, ypserv, yp-tools等。spa
接下来就是拷贝旧服务器上面的用户文件到新服务器, 将旧服务器的/home共享目录挂载在/mnt目录,而后执行copy命令
操作系统
cp -av /mnt/* /home/
为了防止之后用户过分使用磁盘空间,设置好磁盘的配额也是颇有必要,
orm
编辑/etc/fstab文件,将磁盘配额的选项添加上去并从新挂载home目录进程
UUID=60eee9bd-ddf0-4b42-9292-18fd2c5ef04a /home ext4 defaults,usrquota,grpquota 1 2
quotaon -a
将全部用户账号名保存为userlist.txt文件,先给user1设置好配额开发
edquota user1
而后再批量应用到其余用户rpc
for u in `cat userlist.txt`;do edquota -p user1 -u $u;done
查看全部用户配额
同步
repquota -a
设置用户磁盘占用满后给该用户发送邮件通知其清理,写一个检测磁盘用量和邮件通知用户的脚本,邮件正文写在mail_template.txt文件里
for u in `cat userlist.txt` do LIMIT=`quota -u $u | grep sda3 | awk '{print $2}'| sed 's/\*$//'` if [[ $LIMIT -gt 119000000 ]]; then quota -u $u mail -s "$u,your disk space of /home is full, please clean up them ASAP." $u@yourmail.com < mail_template.txt fi done
将该脚本加入crond任务,天天上下午各执行一次
0 10 * * * sh /root/warn_quota.sh 0 14 * * * sh /root/warn_quota.sh
若有必要再次同步旧服务器的文件,能够用rsync只复制新增的文件
rsync -av --progress /mnt/ /home/
新服务器准备好后,将其余开发服务器上的/home目录所有卸载,如有提示被占用没法卸载的话,能够pkill -U user 将某用户的进程杀掉,直到能够卸载为止
停掉各开发服务器的nis服务,
service ypbind stop
编辑/etc/yp.conf配置文件,将nis服务器地址修改成新服务器地址,再启动ypbind
service ypbind start
最后挂载home目录
mount -t nfs -o rsize=32768,wsize=32768 192.168.100.11:/home /home
至此完成了NIS/NFS服务器的迁移工做。