Migrate sbarjatiya.com VM
From Notes_Wiki
<yambe:breadcrumb>New_machine_configuration|New machine configuration</yambe:breadcrumb>
Migrate sbarjatiya.com VM
VM creation on AWS
- Create a new AWS account
- Create a CentOS 7.x VM with updates VM is same region and availability zone as previous VM with. Disk space should be at least same as previous VM.
- Obtain a elastic IP and associate with the VM
- Add entry in /etc/hosts of current machine with appropriate name for new elastic IP (eg newcommonhosting)
- Log into older AWS account using private browser
- Add entry in /etc/hosts of previous VM with appropriate name for previous elastic IP (eg oldcommonhosting)
- SSH to oldVM
- Set correct hostname using
- hostname oldcommonhosting
- Update /etc/hostname with oldcommonhosting name
- Exit from SSH and reconnect and verify oldcommonhosting name appears
- SSH to new VM using centos and root may not work
- Do "sudo su -" on new VM to get root console
- Install vim
- yum -y install vim
- Set correct hostname in /etc/hostname
- Set hostname for current run
- hostname newcommonhosting
- Edit /root/.ssh/authorized_keys and allow direct root ssh (150x on first line)
- Also copy saurabh@labpc as authorized on new VM root account
- Exit from new VM and SSH again as root without using any additional identity apart from saurabh@labpc. Verify newcommonhosting name appears.
- Fully update the VM to latest packages
- yum -y update --skip-broken
- Create swap file as mentioned at CentOS 7.x adding swap space using file
- Configure security group commonhosting-sg with same rules as existing VM. That is access to
- SSH (22)
- HTTP (80), HTTPS (443)
- SMTP (25), SMTPS (465)
- Custom Alt-web (8080)
- ICMP echo-request
- from anywhere
- setenforce 0 on new server
- edit /etc/sysconfig/selinux and set SELINUX=disabled on new server
- Reboot the new VM
Package installations
- yum -y install epel-release wget
- Copy old servers public key as authorized on new server. Run 'ssh-keygen' on old server if there is no existing public key.
- Create /etc/hosts entry on old server for pointing to new server
- ssh from oldserver to newserver with name (eg newcommonhosting) and accept the ssh fingerprint of new host
- rsync /mnt/data1 from old server to new server
- rsync -aHz --delete /mnt/data1/ root@newcommonhosting:/mnt/data1/
-
- Since this will take time, leave this shell running and open new root shell for previous server
- Use Storing date / time along with commands in history
- Exit and ssh again to newcommonhosting for history settings to take effect
Copy user accounts and home folders
- Run following commands:
- rsync /etc/{passwd,shadow,group} root@newcommonhosting:/etc/
- rsync -aHz /home/ root@newcommonhosting:/home/
- rsync -aHz --exclude ".ssh" --exclude ".bash_history" /root/ root@newcommonhosting:/root/
- rsync -aHz --delete /etc/postfix/ root@newcommonhosting:/etc/postfix/
- If ssh to new server from old server stops then due to unprotected private key error then use:
- chmod 600 /etc/ssh/*
-
- on new server to fix the issue
- Restart postfix on new server
- systemctl restart postfix
- systemctl status postfix
- Run following on both servers and compare to ensure all things got copied successfully
- du -sh /mnt/data1
- du -sh /home
- getent passwd
Configure web server
- Install required packages on new server
- yum -y install httpd mod_ssl php-mysql php-pdo php-xml php php-mbstring
- Update php version to 7.x for latest mediawiki using CentOS 7.x Installing PHP 7.x
- Copy web server configuration from old server to new
- rsync -vtrp /etc/httpd/{conf,conf.d} root@newcommonhosting:/etc/httpd/
- If Installing lets-encrypt SSL certificate was used copy /etc/letsencrypt from old server to new. Also copy crontab configuration (crontab -l on old server, crontab -e on new server). Also install python2-certbot-apache package on new server.
- Start and enable web server on new VM
- systemctl start httpd
- systemctl enable httpd
- systemctl status httpd
Install and configure erlang/yaws
- Install erlang and yaws on new server
- yum -y install erlang yaws
- Setup yaws using sbarjatiya user as follows
- su - sbarjatiya
- cd ~/erlang/applications/interpreter; erlc *.erl
- cd ~/erlang/applications/wol_application; erlc *.erl
- cd ~/erlang/erlangcentral.com; erlc *.erl
- Edit start_yaws.sh and replace old hostname with new hostname
- Edit start_applications.erl and replace old hostname with new hostname
- Again compiled edited files
- erlc *.erl
- Try to start yaws using sbarjatiya user
- ./start_yaws.sh
- Verify whether yaws is running or not
- yaws --ls
- exit from sbarjatiya user
Configure MySQL and migrate databases
- Install Mariadb server, bzip2, sshpass
- yum -y install mariadb-server sshpass bzip2
- Start and enable mariadb database
- systemctl start mariadb
- systemctl enable mariadb
- systemctl status mariadb
- Look at '/mnt/data1/plain_folders/documents/public_html/notes_wiki/LocalSettings.php' file for MySQL credentials
- mysql
- > create database notes_wiki;
- > grant all on notes_wiki.* to notes_wiki@localhost identified by '<redacted>';
- > flush privileges;
- Import database backup
- /mnt/data1/plain_folders/documents/public_html
- ./import_notes_database.sh
Configure AWStats, copy old logs
- Install awstats and related packages
- yum -y install awstats perl-Geo-IP
- Copy awstats configuration, running data and httpd logs from older server to new server
- rsync -aHz --delete /etc/awstats/ root@newcommonhosting:/etc/awstats/
- rsync -aHz --delete /var/lib/awstats/ root@newcommonhosting:/var/lib/awstats/
- rsync -aHz --delete /var/log/httpd/ root@newcommonhosting:/var/log/httpd/
- Configure GeoLocation data for awstats:
- cd /root
- wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
- gunzip GeoLiteCity.dat.gz
- mkdir /usr/local/share/GeoIP
- mv -f GeoLiteCity.dat /usr/local/share/GeoIP
- chmod -R 755 /usr/local/share/GeoIP
- Restart apache
- systemctl restart httpd
- systemctl status httpd
Make new VM primary by updating DNS
- Change DNS as follows on godaddy.com:
- rekallsoftware.com :: @
- energyconservationclub.in :: @
- erlangcentral.com :: @
- pbarjatiya.com :: @
- sbarjatiya.com :: @
- Shutdown old VM (Do not release elastic IP yet)
- Ping above domains and look for new IP. If old IP is shown try
- dig -t any sbarjatiya.com
-
- or +trace option
- Check following URLs:
- http://www.rekallsoftware.com/
- http://www.sbarjatiya.com/
- http://www.sbarjatiya.com/notes_wiki/
- http://www.energyconservationclub.in/
- http://pbarjatiya.com/
- http://www.erlangcentral.com/
- http://www.erlangcentral.com/interpreter/index.yaws
- http://www.sbarjatiya.com/awstats/awstats.pl?config=www.sbarjatiya.com
- Send email to saurabh@sbarjatiya.com, saurabh@energyconservationclub.in
- Release elastic IP from old VM
- Update ssh known_hosts keys on rekallcm1 for sbarjatiya.com and www.sbarjatiya.com.
- Take one full backup.
<yambe:breadcrumb>New_machine_configuration|New machine configuration</yambe:breadcrumb>