Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Spin up machine

  2. Create 2 new drives following the instructions in Creating Drives under Build Box Changes
    a. If mounting drives for fedora-data or for the tmp directory for migration, make sure to change the owner to tomcat7 (sudo chown tomcat7:tomcat7 folder) for fedora-data and hydep:deploy for the tmp directory (sudo chown hydep:deploy folder)
  3. Deploy Sufia
  4. Ensure apache is off
  5. Activate maintenance mode on old server
  6. Move over minter
  7. Fedora Export - see below
  8. migrate postgres
  9. Fedora Import - see below
  10. run (currently nonexistent) verification job
  11. migrate dump.rdb
  12. Reindex solr

Box Build changes

The current build scripts in Ansible have problems with a few changes we need. They can be done in this order, or other orders if needed. Postgres must ALWAYS be done before the Fedora 4.7 configuration.

  1. Creating drives
  2. Migration from Postgresql 9.3 to 9.5
  3. Moving to Fedora 4.7
    1. Run ansible scripts

    2. Make sure groupvars/all has
      1. ec2_instance_type: c4.2xlarge

  1. Activate maintenance mode on old server

  2. Export Fedora data (in sufia 6 instance)

    1. Run audit script (takes 4 or 5 mins)

      1. RAILS_ENV=production bundle exec sufia_survey -v

    2. Make sure you have the latest deployment

    3. Make sure tmp/export is empty
    4. Run json export (takes < 10 mins)

      1. $ RAILS_ENV=production bundle exec sufia_export --models GenericFile=Chf::Export::GenericFileConverter,Collection=Chf::Export::CollectionConverter

    5. Open up fedora port to the other server so it can grab the binaries

    6. Change all the 127.0.0.1 URIs to reflect internal IPs, e.g.

      1. $ find tmp/export -type f -name "*.json" -print0 | xargs -0 sed -i "s/127\.0\.0\.1/[internal_ip_of_prod]/g"

      2. The internal IP of prod is: 172.31.48.168
      3. The internal IP of staging is: 172.31.58.101
    7. Move the resulting directory full of exported data from tmp/export to the new server's tmp/import (or wherever desired; this can be provided to the import script)
      1. $ cd tmp; tar -czf json_export_201611141510.tgz export
    8. Then from your own machine:
      1. $ scp -3 -i ~/.ssh/test.pem hydep@staging:/opt/sufia-project/current/tmp/json_export_201612141435.tgz hydep@new_box_ip:~/.
  3. Migrate postgres

    1. Run the following to generate the export.
      1. pg_dump -U postgres chf_hydra -Fp > chf_hydra_dump.sql
    2. Copy the file to the new machine

      1. scp -3 -i ~/.ssh/test.pem ubuntu@production_ip:~/chf_hydra_dump.sql ubuntu@new_box_ip:~
    3. Import the file

      1. psql -U postgres chf_hydra < chf_hydra_dump.sql
  4. Deploy chf-sufia to new server

  5. Create Drives

    1. In the AWS visual interface, go to EC2

    2. Go to Volumes

    3. Select Create Volumes

    4. Make

    sure the volume is
    1. two volumes with the following features:

      1. General Purpose SSD

      2. 150 GB

      3. Availability Zone b

    Create 2 of these
    1. Once each one is made, select it and under Actions choose Attach Volume. Type the name or id of the machine and attach the volume.

    2. ssh into the box

    Run
    1. sudo fdisk -l

      1. You should see /dev/vxdg and /dev/xvdh

      2. If not, check if the volumes are attached

    2. Create the filesystem for each disk

      1. sudo mkfs.xfs /dev/xvdg

      2. sudo mkfs.xfs /dev/xvdh

  6. Mount each disk
    1. sudo mount /dev/xvdg /opt/fedora-data
    2. sudo mount /dev/xvdh /opt/sufia-project/releases/XXXX/tmp
  7. Remove the old version of postgres:
    1. Edit the fstab file to retain these mounts

      1. sudo vi /etc/fstab

      2. /dev/xvdg /opt/fedora-data xfs defaults 0 0

      3. /dev/xvdh /opt/sufia-project/releases/XXXX/tmp xfs defaults 0 0

Postgres

    1. mount the disks
      1. sudo
      apt-get purge postgresql*
  1. Create the file /etc/apt/sources.list.d/pgdg.list
  2. Add the line  deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main to that
  3. Add the repo key with this command
    1. wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
  4. sudo apt-get update
  5. sudo apt-get install postgresql-9.5
  6. Log in as postgres and enter psql
    1. sudo su postgres
    2. psql
  7. In Postgres create the chf_hydra and fcrepo databases
    1. CREATE DATABASE chf_hydra;
    2. CREATE DATABASE fcrepo;
  8. In Postgres create the needed users
    1. CREATE USER chf_pg_hydra WITH PASSWORD 'SEE ANSIBLE GROUPVARS/ALL';
    2. CREATE USER trilby WITH PASSWORD 'porkpie2';
  9. Grant each user access to their table
    1. GRANT Create,Connect,Temporary ON DATABASE chf_hydra TO chf_pg_hydra;
    2. GRANT All Privileges ON DATABASE fcrepo TO trilby;
  10. Set the user password for postgres
    1. \password postgres
    2. Enter password from groupvars/all
  11. sudo nano /etc/postgresql/9.5/main/pg_hba.conf
  12. Change the sections under "Database administrative login by Unix domain socket"
    1. peer should be set to md5 for
      1. local all postgres
      2. local all all
      3. host all all
  13. Restart postgres, try to log in with
    1. psql -U postgres
  14. If it lets you use the password, it works!

Fedora

  • Stop Tomcat
    • sudo service tomcat7 stop
  • Replace the current /etc/default/tomcat7 with

# A backup of the original file with addition options is at /etc/default/tomcat7.bak
TOMCAT7_USER=tomcat7
TOMCAT7_GROUP=tomcat7
JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
#Postgres
JAVA_OPTS="-Dfcrepo.home=/opt/fedora-data -Dfcrepo.modeshape.configuration=classpath:/config/jdbc-postgresql/repository.json -Dfcrepo.postgresql.username=trilby -Dfcrepo.postgresql.password=porkpie2 -Dfcrepo.postgresql.host=localhost -Dfcrepo.postgresql.port=5432 -Djava.awt.headless=true -XX:+UseG1GC -XX:+UseCompressedOops -XX:-UseLargePagesIndividualAllocation -XX:MaxPermSize=128M -Xms512m -Xmx4096m -Djava.util.logging.config.file=/etc/tomcat7/logging.properties -server"

  • Start Tomcat
    • sudo service tomcat7 start

Fedora export

In sufia 6 instance:

  • Run audit script
RAILS_ENV=production bundle exec sufia_survey -v
  • Run json export
$ RAILS_ENV=production bundle exec sufia_export --models GenericFile=Chf::Export::GenericFileConverter,Collection=Chf::Export::CollectionConverter
  • Open up fedora port to the other server so it can grab the binaries
  • Change all the 127.0.0.1 URIs to reflect actual host, e.g.
$ find tmp/export -type f -name "*.json" -print0 | xargs -0 sed -i "s/127\.0\.0\.1/staging.hydra.chemheritage.org/g"
  • Move the resulting directory full of exported data from tmp/export to the new server's tmp/import (or wherever desired; this can be provided to the import script)
$ cd tmp; tar -czf json_export_201611141510.tgz export
  • Then from your own machine:
$ scp staging:/opt/sufia-project/current/tmp/json_export_201611141510.tgz new_box_ip:/opt/sufia-project/current/tmp/.

Fedora import

On sufia 7 instance:

  • Mount the /dev/xvdh drive on the tmp directory in sufia (/opt/sufia-project/releases/XXXXX/tmp)
  • Change the owner of the tmp directory
    • sudo chown hydep:deploy /opt/sufia-project/releases/XXXXX/tmp
  • unpack the exported json files

...

      1. mount -a
    1. Change the owner of the two mount locations

      1. sudo chown -R tomcat7:tomcat7 /opt/fedora-data

      2. sudo chown -R hydep:deploy /opt/sufia-project/releases/XXXX/tmp

  1. Restart Solr

    1. If this is the first time sufia has been deployed, Solr now runs outside of tomcat and needs to be restarted after deployment.

      1. sudo service solr restart

  2. Ensure apache is off on new server

    1. We don't want anyone doing stuff before we're ready.

  3. Restart Tomcat on new server

    1. sudo service tomcat7 restart
  4. Move over minter statefile

    1. On Production
      1. sudo cp /var/sufia/minter-state ~
      2. sudo chown ubuntu:ubuntu minter-state
    2. Then copy the file
      1. scp -3 -i ~/.ssh/test.pem ubuntu@production_ip:~/minter-state ubuntu@new_box_ip:~
    3. On New Box
      1. sudo mv minter-state /var/sufia
      2. sudo chown hydep:deploy /var/sufia/minter-state
  5. Import Fedora data (in sufia 7 instance)

    1. Start a screen or tmux session

    2. Become hydep

    3. Unpack the exported json files

      1. cd /opt/sufia-project/current/tmp/

      2. cp ~/json_export_201612141435.tgz .

      3. tar

...

      1. -

...

      1. xzf json_export_

...

      1. 201612141435.tgz

      2. mv

...

      1. export

...

      1. import

    1. configure sufia6_user and sufia6_password in config/application

    2. run the import

      1. $

...

      1. RAILS_ENV=production

...

      1. bundle

...

      1. exec

...

      1. sufia_import

...

      1. -d

...

      1. tmp/import

...

      1. --json_mapping

...

      1. Chf::Import::GenericFileTranslator=generic_file_,Sufia::Import::CollectionTranslator=collection

...

      1. _

...

      1. $

...

      1. time RAILS_ENV=production

...

      1. bundle

...

      1. exec

...

      1. sufia_import

...

      1. -d

...

      1. tmp/import --json_mapping

...

      1. Chf::Import::GenericFileTranslator=generic_file_,Sufia::Import::CollectionTranslator=collection_ &>> import.log
  1. run verification job

    1. Currently the job itself is hung up in a continuous integration mess / awaiting code review. Here's how to do it manually
      1. $ bin/rails c prodction

      2. validator = Sufia::Migration::Validation::Service.new
        validator.call
        Sufia::Migration::Survey::Item.migration_statuses.keys.each { |st| puts "#{st}: #{Sufia::Migration::Survey::Item.send(st).count}" }
        [:missing, :wrong_type].each do |status|
        puts "#{status} ids:"
        Sufia::Migration::Survey::Item.send(status).each do |obj|
        puts " #{obj.object_

...

Postgres export/Import

...

      1. id}"
        end
        end
  1. migrate dump.rdb

  2. Reindex solr

Downsizing

  1. Spin up machine

    1. Use ansible playbook, set groupvars/all to have
      1. ec2_instance_type: m4.large

  2. On the migration and downsize machine, stop tomcat.

    1. sudo service tomcat7 stop
  3. Install mdadm

    1. sudo apt-get install mdadm
  4. Create two new disks for the new machine

    1. In the AWS visual interface, go to EC2

    2. Go to Volumes

    3. Select Create Volumes

    4. Make two volumes with the following features:

      1. Magnetic

      2. 1 TB

      3. Availability Zone b

    5. Once each one is made, select it and under Actions choose Attach Volume. Type the name or id of the machine and attach the volume.

    6. ssh into the box

    7. sudo fdisk -l

      1. You should see /dev/vxdg and /dev/xvdh

      2. If not, check if the volumes are attached

    8. Create the filesystem for each disk

      1. sudo mkfs.xfs /dev/xvdg

      2. sudo mkfs.xfs /dev/xvdh

  5. Build a RAID 1 array with the two disks

    1. mdadm --create --verbose /dev/md0 --level=mirror --raid-devices=2 /dev/xvdg /dev/xvdh
  6. Mount the array

  7. Migrate postgres from old machine to new machine

    1. Run the following to generate the export.
      1. pg_dump -U postgres chf_hydra -Fp > chf_hydra_dump.sql

On Migration

...

      1. pg_dump -U postgres fcrepo -Fp > fcrepo_dump.sql
    1. Copy the files to the new machine

      1. scp -3 -i ~/

...

      1. .ssh/

...

      1. test.pem 

...

      1. ubuntu@pbig:~/chf_hydra_dump.sql

...

      1.  ubuntu@small:~
      2. scp -3 -i ~/.ssh/test.pem ubuntu@pbig:~/fcrepo_dump.sql ubuntu@small:~
    1. Drop the current chf_hydra and fcrepo
      1. psql -U postgres
        1. drop database chf_hydra;
        2. drop database fcrepo;
    2. Import the files

      1. psql -U postgres

...

      1.  chf_hydra < chf_hydra

...

      1. _dump.sql
      2. psql -U postgres fcrepo < fcrepo_dump.sql
    1. Grant database permissions
      1. GRANT

...

      1. Create,Connect,Temporary

...

      1. ON

...

      1. DATABASE

...

      1. chf_hydra

...

      1. TO

...

      1. chf_pg_hydra

...

      1. ;
      2. GRANT ALL privileges ON DATABASE fcrepo to trilby;
  1. Move the minter statefile from old machine to new machine

    1. On Bigbox
      1. sudo cp /var/sufia/minter-state ~
      2. sudo chown ubuntu:ubuntu minter-state
    2. Then copy the file
      1. scp -3 -i ~/.ssh/test.pem ubuntu@big_ip:~/minter-state ubuntu@small_box_ip:~
    3. On Small Box
      1. sudo mv minter-state /var/sufia
      2. sudo chown hydep:deploy /var/sufia/minter-state
  2. Move the derivative files from the old machine to the new machine

  3. Move dump.rdb from old machine to new machine

  4. Detach the fedora drive on the old machine

  5. Stop tomcat

  6. Attach the fedora drive on the new machine

    1. See visual guide
  7. Mount the fedora drive to /mnt

    1. sudo mount /dev/xvd? /mnt
  8. Copy the data from the fedora drive to the RAID array.

    1. sudo cp -ar /mnt/* /opt/fedora-data/
    2. sudo chown -R tomcat7:tomcat7 /opt/fedora-data/*
  9. Backup Solr and move the backup to the new machine

    1. curl 'http://localhost:8983/solr/collection1/replication?command=backup&name=migration&location=/solr-backup'
  10. Restore Solr on the new machine

    1. curl 'http://localhost:8983/solr/collection1/replication?command=restore&name=migration&location=/solr-backup'
  11. Go to Production and copy SSL certs and keyfiles

  12. Set up SSL redirection

How to check the statefile

...

  1. Stop Tomcat and Solr
  2. Remove all the folders in /opt/fedora-data.
  3. Remove all the files in /var/solr/data/collection1/data/index/, and /var/sufia/derivatives
  4. Remove all the upload files in the tmp directory of the version of sufia used.
  5. Enter into postgres (psql -U postgres)
  6. Drop the fcrepo database (DROP DATABASE fcrepo;)
  7. Build a new fcrepo database (CREATE DATABASE fcrepo;)
  8. Grant the fcrepo user (currently tribly until we get a better user) all privileges on fcrepo. (grant all privileges on fcrepo to tribly;)
  9. Restart tomcat and solrsol