Difference between revisions of "Migrate sbarjatiya.com VM"
From Notes_Wiki
m |
m |
||
Line 67: | Line 67: | ||
#:: rsync -aHz /home/ root@newcommonhosting:/home/ | #:: rsync -aHz /home/ root@newcommonhosting:/home/ | ||
#:: rsync -aHz --exclude ".ssh" --exclude ".bash_history" /root/ root@newcommonhosting:/root/ | #:: rsync -aHz --exclude ".ssh" --exclude ".bash_history" /root/ root@newcommonhosting:/root/ | ||
#:: rsync -aHz --delete /etc/postfix/ root@newcommonhosting:/etc/postfix/ | |||
#:</pre> | #:</pre> | ||
#If ssh to new server from old server stops then due to unprotected private key error then use: | #If ssh to new server from old server stops then due to unprotected private key error then use: | ||
Line 73: | Line 74: | ||
#:</pre> | #:</pre> | ||
#::on new server to fix the issue | #::on new server to fix the issue | ||
# Restart postfix on new server | |||
#:<pre> | |||
#:: systemctl restart postfix | |||
#:: systemctl status postfix | |||
#:</pre> | |||
# Run following on both servers and compare to ensure all things got copied successfully | |||
#:<pre> | |||
#:: du -sh /mnt/data1 | |||
#:: du -sh /home | |||
#:: getent passwd | |||
#:</pre> | |||
==Configure | ==Configure web server== | ||
# | # Install required packages on new server | ||
# | #:<pre> | ||
# yum -y install | #:: yum -y install httpd mod_ssl php-mysql php-pdo php-xml php | ||
# | #:</pre> | ||
# | # 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 | ||
# | #:<pre> | ||
# | #:: rsync -vtrp /etc/httpd/{conf,conf.d} root@newcommonhosting:/etc/httpd/ | ||
# | #:</pre> | ||
# | # Start and enable web server on new VM | ||
#:<pre> | |||
#:: systemctl start httpd | |||
#:: systemctl enable httpd | |||
#:: systemctl status httpd | |||
#:</pre> | |||
==Install and configure erlang/yaws== | ==Install and configure erlang/yaws== | ||
# yum -y install erlang | # Install erlang and yaws on new server | ||
# | #:<pre> | ||
# | #:: yum -y install erlang yaws | ||
# su - sbarjatiya | #:</pre> | ||
# cd ~/erlang/applications/interpreter; erlc *.erl | # Setup yaws using sbarjatiya user as follows | ||
# cd ~/erlang/applications/wol_application; erlc *.erl | #:<pre> | ||
# cd ~/erlang/erlangcentral.com; erlc *.erl | #:: su - sbarjatiya | ||
# | #:: cd ~/erlang/applications/interpreter; erlc *.erl | ||
#:: cd ~/erlang/applications/wol_application; erlc *.erl | |||
# | #:: cd ~/erlang/erlangcentral.com; erlc *.erl | ||
#:</pre> | |||
# erlc *.erl | # Edit <tt>start_yaws.sh</tt> and replace old hostname with new hostname | ||
# ./start_yaws.sh | # Edit <tt>start_applications.erl</tt> and replace old hostname with new hostname | ||
# yaws --ls | # Again compiled edited files | ||
#:<pre> | |||
#:: erlc *.erl | |||
#:</pre> | |||
# Try to start yaws using sbarjatiya user | |||
#:<pre> | |||
#:: ./start_yaws.sh | |||
#:</pre> | |||
# Verify whether yaws is running or not | |||
#:<pre> | |||
#:: yaws --ls | |||
#:</pre> | |||
# exit from sbarjatiya user | # exit from sbarjatiya user | ||
==Configure | ==Configure MySQL and migrate databases== | ||
# yum -y install | # Install Mariadb server, bzip2 and sshpass | ||
# | #:<pre> | ||
# | #:: yum -y install mariadb-server sshpass bzip2 | ||
# | #:</pre> | ||
# | # Start and enable mariadb database | ||
#:<pre> | |||
#:: systemctl start mariadb | |||
#:: systemctl enable mariadb | |||
#:: systemctl status mariadb | |||
#:</pre> | |||
# Look at '<tt>/mnt/data1/plain_folders/documents/public_html/notes_wiki/LocalSettings.php</tt>' file for MySQL credentials | |||
#:<pre> | |||
#:: mysql | |||
#:: > create database notes_wiki; | |||
#:: > grant all on notes_wiki.* to notes_wiki@localhost identified by '<redacted>'; | |||
#:: > flush privileges; | |||
#:</pre> | |||
# Import database backup | |||
#:<pre> | |||
#:: /mnt/data1/plain_folders/documents/public_html | |||
#:: ./import_notes_database.sh | |||
#:</pre> | |||
Revision as of 14:06, 12 August 2018
<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 -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
- 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/
- 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 and 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
- 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>