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
- 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
- setenforce 0 on new server
- edit /etc/sysconfig/selinux and set SELINUX=disabled on new server
- rsync /mnt/data1 from old server to new server
- rsync -vaHz --delete /mnt/data1/ root@newcommonhosting:/mnt/data1/
- cp /etc/profile.d/history.sh from old server to new
Copy user accounts and home folders
- rsync /etc/{passwd,shadow,group} to new server
- rsync /home to new server
- rsync -vtrp /root/ to new server
- Note this will overwrite history and .ssh configuration of root user
- vim /etc/ssh/sshd_config
- Allow root ssh with password
- service sshd restart
Configure email system
- service postfix stop
- chkconfig postfix off
- yum -y install sendmail
- verify in /etc/hosts first line has 127.0.0.1 <hostname> where hostname matches output of hostname command. There can be other names after hostname but first value should be hostname
- service sendmail start
- chkconfig sendmail on
- Copy {/etc/mail/,/etc/aliases,/etc/hosts} from old server to new
- newaliases
- cd /etc/mail; make
- service sendmail restart
Configure web server
- yum -y install mod_ssl php-mysql php-pdo php-xml php
- rsync -vtrp /etc/httpd/{conf,conf.d} from old server to new
- service httpd restart
- chkconfig httpd on
Install and configure erlang/yaws
- yum -y install erlang gcc pam-devel
- Download yaws sources and install it via ./configure; make; make install
- make test fails but yaws seems to work
- su - sbarjatiya
- cd ~/erlang/applications/interpreter; erlc *.erl
- cd ~/erlang/applications/wol_application; erlc *.erl
- cd ~/erlang/erlangcentral.com; erlc *.erl
- vim start_yaws.sh
- Replace old hostname with new hostname
- vim start_applications.erl
- Replace old hostname with new hostname
- erlc *.erl
- ./start_yaws.sh
- yaws --ls
- exit from sbarjatiya user
Configure DNS
- yum -y install bind bind-utils
- rsync -vaH /etc/named.conf to new server
- rsync -vaH /var/named/* to new server /var/named
- service named start
- chkconfig named on
Configure MySQL and migrate databases
- yum -y install mysql-server
- service mysqld start
- look at /documents/public_html/notes_wiki/LocalSetting.php file for MySQL credentials
- Create cooresponding db
- Create correspoding user with same password and grant all to created db. Remember to 'flush privileges;'.
- yum -y install sshpass
- run /documents/public_html/import_notes_database.sh
Configure AWStats, copy old logs
- yum -y install awstats perl-Geo-IP
- copy
- /etc/awstats
- /var/lib/awstats
- /var/log/httpd
- from old server to new server
- Run following:
- 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
- service httpd restart
Copy firewall, change DNS and check things
- copy /etc/sysconfig/iptables from old server to new
- Note old public IP and new public IP properly
- Add /etc/hosts entry for old public IP
- 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)
- Check following URLs:
- 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>