CentOS 7.x migrate CentOS 7.x postfix, dovecot, squirrelmail server
From Notes_Wiki
Home > CentOS > CentOS 7.x > Email configuration > CentOS 7.x migrate CentOS 7.x postfix, dovecot, squirrelmail server
There is updated article on this at CentOS 8.x migrate CentOS 7.x postfix, dovecot, squirrelmail server
Following steps can be used for migrating a running mail server setup from CentOS 7.x created using CentOS 7.x migrate CentOS 6.x postfix, dovecot, squirrelmail server to another CentOS 7.x machine:
- Create a new VM/machine/server with necessary resources (Eg t2.micro) in appropriate region and availability zone.
- Add elastic (static public) IP to instance if not done already
- In Instance firewall allow ports (22, 25, 80, 443, 143, 993, 110, 995, 587, 465). Or apply security group settings from old server to new server (HTTP, HTTPS, POP3, POP3S, SMTP, SMTPS, IMAP, IMAPS, SSH, Ping)
- Create /etc/hosts entry for old-<fqdn> and new-<fqdn> servers (On local workstation)
- SSH to new-<fqdn> as centos user (On new server)
- sudo su -
- yum -y install vim
- Allow direct root login with AWS security key pair (155x)
- copy self public-key as authorized
- Add swap space using CentOS 7.x adding swap space using file
- Add history date/time recording using Storing date / time along with commands in history
- set hostname as new-<fqdn> in /etc/hostname
- hostname new-<fqdn>
- Set correct time zone CentOS 7.x Change system timezone
- exit from root and centos
- Now ssh directly as root user and proceed (On new server)
- If new disk is added for /home create required partition and file-system. Then mount the disk or partition on /home as desired
- Remember to add /etc/fstab entries for additional partitions or disks.
- Open ssh to root@old-<fdqn> (On old server)
- ssh-keygen
- Add /etc/hosts entry in old server for pointing to new server with name (eg new-<fqdn>)
- Copy keys from old server to new server as authorized
- On ssh to root@old-<fqdn> (On old server)
- Start copy of home folder which might take considerable time
- rsync -aHz --delete /home/ root@new-<fqdn>:/home/
- Start copy of home folder which might take considerable time
- On root ssh (On new server)
- yum -y install httpd mod_ssl epel-release
- Install and configure firewalld using (refer CentOS 7.x firewalld)
- yum -y install firewalld
- #In /etc/sysconfig/network-scripts/ifcfg-eth0 append ZONE=public
- systemctl restart network
- systemctl restart firewalld
- systemctl enable firewalld
- firewall-cmd --zone=public --add-port=25/tcp --permanent #SMTP
- firewall-cmd --zone=public --add-port=80/tcp --permanent #HTTP
- firewall-cmd --zone=public --add-port=443/tcp --permanent #HTTPS
- firewall-cmd --zone=public --add-port=143/tcp --permanent #IMAP
- firewall-cmd --zone=public --add-port=993/tcp --permanent #IMAPS
- firewall-cmd --zone=public --add-port=110/tcp --permanent #POP3
- firewall-cmd --zone=public --add-port=995/tcp --permanent #POP3S
- firewall-cmd --zone=public --add-port=587/tcp --permanent #Submission
- firewall-cmd --zone=public --add-port=465/tcp --permanent #SMTPS
- firewall-cmd --reload
- TODO - Copy firewalld configuration from old server to new server
- Install and configure fail2ban by referring CentOS 7.x fail2ban
- If custom SSL certificates were used edit /etc/httpd/conf.d/ssl.conf with
- SSLCertificateFile /etc/httpd/conf/ssl.crt
- SSLCertificateKeyFile /etc/httpd/conf/ssl.key
- SSLCACertificateFile /etc/httpd/conf/ca-bundle.pem
-
- and copy corresponding files from old server to new server
- If Installing lets-encrypt SSL certificate was used then
- rsync /etc/letsencrypt/ from old server to new server (On old server)
- yum -y install python2-certbot-apache (On new server)
- crontab -l (On old server)
- Configure cron entries for automatic SSL renewal same as old server on new server using crontab -e (On new server)
- cat /etc/passwd on old server.
- Copy all lines for UID >=500 and append corresponding lines to /etc/passwd on new server.
- The number of lines should match 'ls -1 /home | grep -v lost | wc -l'
- Be watchful for IDs <500 which might appear in between (eg nscd, dovecot)
- Copy /etc/shadow lines of corresponding users from old server to new server
- Copy /etc/group lines of corresponding users from old server to new server
- Do ls -l /home and all user and group names should appear properly (On new server)
- copy custom aliases from /etc/aliases to new server and update root alias appropriately
- On new server
- newaliases
- yum -y install logwatch postfix dovecot
- In /etc/hosts add new-<fdqn> <fdqn> against 127.0.0.1
- Also change all auth values from 1000 to 500 in various /etc/pam.d files
- grep 1000 /etc/pam.d/*
- #update all files; :%s/1000/500/gc
- sed -i 's/1000/500/' *
- yum -y install wget squirrelmail
- Disable selinux (setenforce 0, edit /etc/sysconfig/selinux and set SELINUX=disabled)
- On old server
- rsync /etc/postfix to new-<fqdn>
- rsync /etc/dovecot to new-<fqdn>
- rsync /etc/httpd to new-<fqdn>
- rsync /etc/squirrelmail to new-<fqdn>
- rsync /var/www/html to new-<fqdn>
- rsync /etc/php.ini to new-<fqdn>
- On new server
- Start and enable services
- systemctl enable postfix
- systemctl start postfix
- systemctl status postfix
- systemctl start httpd
- systemctl status httpd
- systemctl enable httpd
- systemctl enable dovecot
- systemctl start dovecot
- systemctl status dovecot
- Start and enable services
- Add /etc/hosts entry for new server in laptop and try to open the new server with name and IP.
- Repeat /home/ rsync again after it finishes for a second sync
- ls -l /home on new-server should recognize all usernames and groupnames properly
- During downtime on old server
- Stop httpd, dovecot and postfix
- Again sync /home
- Change production public DNS entries to point to new server. If organization has local private DNS, then perhaps that may also require changes.
- Check updated entries via public DNS servers after waiting for a minute or two
- Manually copy entries from /root/.ssh/authorized_keys of old server to new server
- Comment /etc/host entry in laptop after DNS entry has been changed
- systemctl restart postfix (On new server)
- Before this it listens on 127.0.0.1:25, after this it changes to 0.0.0.0:25
- Send test email from gmail to server and wait for receiving email on new server
- Send test email from new server to gmail and wait for receiving email on Gmail account
- Stop old server and add reminder to terminate old server after a few days.
- Disassociate elastic IP or static IP of old server.
- Try to release it. Raise support ticket if AWS support is required to release the elastic IP.
- Fill AWS reverse entry form for new email server.
- For this first login into AWS account
- Then open https://aws.amazon.com/forms/ec2-email-limit-rdns-request
- Set hostname in /etc/hostname file (on new server)
- Use "hostname <fqdn>" command to set current hostname (on new server)
- CentOS 7.x Configure change password plugin for squirrelmail using poppassd
- ssh from backup machine to new server and ensure that new servers SSH keys are recognized preperly
Home > CentOS > CentOS 7.x > Email configuration > CentOS 7.x migrate CentOS 7.x postfix, dovecot, squirrelmail server