Difference between revisions of "Migrate sbarjatiya.com VM"

From Notes_Wiki
m
m
Line 54: Line 54:
# rsync /mnt/data1 from old server to new server
# rsync /mnt/data1 from old server to new server
#:<pre>
#:<pre>
#::rsync -vaHz --delete /mnt/data1/ root@newcommonhosting:/mnt/data1/
#::rsync -aHz --delete /mnt/data1/ root@newcommonhosting:/mnt/data1/
#:</pre>
#:</pre>
# cp /etc/profile.d/history.sh from old server to new
#:: 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==
==Copy user accounts and home folders==
# rsync /etc/{passwd,shadow,group} to new server
# Run following commands:
# rsync /home to new server
#:<pre>
# rsync -vtrp /root/ to new server
#:: rsync /etc/{passwd,shadow,group} root@newcommonhosting:/etc/
#* Note this will overwrite history and .ssh configuration of root user
#:: rsync -aHz /home/ root@newcommonhosting:/home/
# vim /etc/ssh/sshd_config
#:: rsync -aHz --exclude ".ssh"  --exclude ".bash_history" /root/ root@newcommonhosting:/root/
#* Allow root ssh with password
#:</pre>
# service sshd restart
#If ssh to new server from old server stops then due to unprotected private key error then use:
#:<pre>
#::chmod 600 /etc/ssh/*
#:</pre>
#::on new server to fix the issue





Revision as of 13:38, 12 August 2018

<yambe:breadcrumb>New_machine_configuration|New machine configuration</yambe:breadcrumb>

Migrate sbarjatiya.com VM

VM creation on AWS

  1. Create a new AWS account
  2. 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.
  3. Obtain a elastic IP and associate with the VM
  4. Add entry in /etc/hosts of current machine with appropriate name for new elastic IP (eg newcommonhosting)
  5. Log into older AWS account using private browser
  6. Add entry in /etc/hosts of previous VM with appropriate name for previous elastic IP (eg oldcommonhosting)
  7. SSH to oldVM
  8. Set correct hostname using
    hostname oldcommonhosting
  9. Update /etc/hostname with oldcommonhosting name
  10. Exit from SSH and reconnect and verify oldcommonhosting name appears
  11. SSH to new VM using centos and root may not work
  12. Do "sudo su -" on new VM to get root console
  13. Install vim
    yum -y install vim
  14. Set correct hostname in /etc/hostname
  15. Set hostname for current run
    hostname newcommonhosting
  16. 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
  17. Exit from new VM and SSH again as root without using any additional identity apart from saurabh@labpc. Verify newcommonhosting name appears.
  18. Fully update the VM to latest packages
    yum -y update --skip-broken
  19. Create swap file as mentioned at CentOS 7.x adding swap space using file
  20. 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
  21. Reboot the new VM


Package installations

  1. yum -y install epel-release wget
  2. Copy old servers public key as authorized on new server. Run 'ssh-keygen' on old server if there is no existing public key.
  3. Create /etc/hosts entry on old server for pointing to new server
  4. ssh from oldserver to newserver with name (eg newcommonhosting) and accept the ssh fingerprint of new host
  5. setenforce 0 on new server
  6. edit /etc/sysconfig/selinux and set SELINUX=disabled on new server
  7. 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
  8. Use Storing date / time along with commands in history
  9. Exit and ssh again to newcommonhosting for history settings to take effect


Copy user accounts and home folders

  1. 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/
  2. 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


Configure email system

  1. service postfix stop
  2. chkconfig postfix off
  3. yum -y install sendmail
  4. 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
  5. service sendmail start
  6. chkconfig sendmail on
  7. Copy {/etc/mail/,/etc/aliases,/etc/hosts} from old server to new
  8. newaliases
  9. cd /etc/mail; make
  10. service sendmail restart


Configure web server

  1. yum -y install mod_ssl php-mysql php-pdo php-xml php
  2. rsync -vtrp /etc/httpd/{conf,conf.d} from old server to new
  3. service httpd restart
  4. chkconfig httpd on


Install and configure erlang/yaws

  1. yum -y install erlang gcc pam-devel
  2. Download yaws sources and install it via ./configure; make; make install
    • make test fails but yaws seems to work
  3. su - sbarjatiya
  4. cd ~/erlang/applications/interpreter; erlc *.erl
  5. cd ~/erlang/applications/wol_application; erlc *.erl
  6. cd ~/erlang/erlangcentral.com; erlc *.erl
  7. vim start_yaws.sh
    • Replace old hostname with new hostname
  8. vim start_applications.erl
    • Replace old hostname with new hostname
  9. erlc *.erl
  10. ./start_yaws.sh
  11. yaws --ls
  12. exit from sbarjatiya user


Configure DNS

  1. yum -y install bind bind-utils
  2. rsync -vaH /etc/named.conf to new server
  3. rsync -vaH /var/named/* to new server /var/named
  4. service named start
  5. chkconfig named on


Configure MySQL and migrate databases

  1. yum -y install mysql-server
  2. service mysqld start
  3. look at /documents/public_html/notes_wiki/LocalSetting.php file for MySQL credentials
  4. Create cooresponding db
  5. Create correspoding user with same password and grant all to created db. Remember to 'flush privileges;'.
  6. yum -y install sshpass
  7. run /documents/public_html/import_notes_database.sh


Configure AWStats, copy old logs

  1. yum -y install awstats perl-Geo-IP
  2. copy
    • /etc/awstats
    • /var/lib/awstats
    • /var/log/httpd
    from old server to new server
  3. 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
  4. service httpd restart


Copy firewall, change DNS and check things

  1. copy /etc/sysconfig/iptables from old server to new
  2. Note old public IP and new public IP properly
  3. Add /etc/hosts entry for old public IP
  4. Change DNS as follows on godaddy.com:
    • rekallsoftware.com :: @
    • energyconservationclub.in :: @
    • erlangcentral.com :: @
    • pbarjatiya.com :: @
    • sbarjatiya.com :: @
  5. Shutdown old VM (Do not release elastic IP yet)
  6. Check following URLs:
  7. Send email to saurabh@sbarjatiya.com, saurabh@energyconservationclub.in
  8. Release elastic IP from old VM
  9. Update ssh known_hosts keys on rekallcm1 for sbarjatiya.com and www.sbarjatiya.com.
  10. Take one full backup.


<yambe:breadcrumb>New_machine_configuration|New machine configuration</yambe:breadcrumb>