Wednesday, February 21, 2018

Linux Recovery and Boot Disk Creation


Creation of a floppy with GRUB on MBR:
GRUB: GRand Unified Bootloader
The GRUB bootloader is first run when the computer initially boots. After it runs, it passes control to the operating system kernel. GRUB is typically installed on the MBR of the hard drive but can also be installed on a floppy to rescue the system if the MBR is overwritten or corrupted.

Note: Grub "Legacy" refers to the 0.9x versions of Grub.

    Grub 0.95 (Red Hat Enterprise 4, Fedora Core 3, CentOS4) is configured with /etc/grub.conf (soft link to /boot/grub/grub.conf or /boot/grub/menu.1st)
    Grub 0.97 (Ubuntu 6.11) is configured with a multiple configuration files including:
        /boot/grub/menu.lst: Typical Grub directives (was grub.conf)
        /boot/grub/device.map: List devices e.g. (hd0) /dev/sda
        /boot/grub/default: Set with the command "grub-set-default". Typical value is "0" to boot the first kernel listed. Example: grub-set-default 0
        /boot/grub/stage1: Embedded in MBR (boot sector partition) thus is 512 bytes. Encodes location of stage 2.
        /boot/grub/stage2: Put on a filesystem, this is the core image of GRUB.
        ...

Links:

    GNU/GRUB Home page
    GNU/GRUB online manual
    GNU/GRUB FAQ

GRUB: Legacy (0.95)
GRUB is an operating system independant boot loader and shell. GRUB uses a device naming system which is different and independant of the one used by Linux. For example (hd0,0), the designation "hd0" refers to the first hard drive. The second designation refers the the partition number. Each begin counting from "0". Some systems like BSD may include more designations. Note that GRUB does not distinguish EIDE from SCSI.
Linux device name     GRUB name     Linux filesystem
(Examples)
/dev/hda1 (EIDE)
or
/dev/sda1 (SCSI)     (hd0,0)     /boot
/dev/hda2
or
/dev/sda2     (hd0,1)     /
/dev/hdb1
or
/dev/sdb1     (hd1,0)     /home
/dev/fd0     (fd0,0)     /mnt/floppy

Sample config file: /etc/grub.conf (Linked to actual file: /boot/grub/grub.conf).

    default=0
    timeout=10
    splashimage=(hd1,0)/grub/splash.xpm.gz     - Image to be displayed: /boot/grub/splash.xpm.gz which is on the 2nd hard drive, 1st partition.
    title Red Hat Linux (2.4.9-21)
            root (hd1,0)                       - Root of GRUB reference. Same as /boot. See above table.
            kernel /vmlinuz-2.4.9-21 ro root=/dev/sdb6  - Note that the command cat /proc/cmdline should be the same as "ro root=/dev/sdb6"
            initrd /initrd-2.4.9-21.img        - Referenced from GRUB root reference. Hence file: /boot/initrd-2.4.9-21.img
                   

Note: All GRUB paths are referenced from /boot, as defined by the "root" statement.

Create GRUB boot floppy:

    [root prompt]#  fdformat /dev/fd0H1440
    [root prompt]#  mke2fs /dev/fd0
    [root prompt]#  mount -t ext2 /dev/fd0 /mnt/floppy
    [root prompt]#  grub-install --root-directory=/mnt/floppy '(fd0)'
    [root prompt]#  cp /boot/grub/grub.conf /mnt/floppy/boot/grub/grub.conf
    [root prompt]#  umount /mnt/floppy

The small reduced kernel /boot/vmlinuz-...BOOT and support files in /boot can be loaded on the floppy to create other boot options.

GRUB: Legacy (0.97)
Method 1:
Creating a GRUB boot floppy:

    cd /lib/grub/i386-pc
    dd if=stage1 of=/dev/fd0 bs=512 count=1
    dd if=stage2 of=/dev/fd0 bs=512 seek=1

This will write files stage1 and stage2 to the first and second block of the floppy disk.

Method 2:

    mke2fs /dev/fd0
    mount -t ext2 /dev/fd0 /mnt/floppy
    grub-install --root-directory=/mnt/floppy fd0
    umount /mnt/floppy

Creation of a floppy with LILO on MBR:
Lilo is the "Boot Loader" for Linux which typically resides on the MBR of your hard drive. This may easily get wiped out on a multiboot system where a re-loading of the Windows operating system will reload the MBR. If the MBR is overwritten and LILO removed, there will be no way of booting to Linux. Thus it is wise to have a floppy with LILO residing on the MBR of the floppy which can point the system to boot off of the Linux kernel residing on your hard drive. Here is how it is created:

    fdformat /dev/fd0H1440 # Lay tracks on new diskette
    mkfs -t minix /dev/fd0 1440 # Create minix file system on floppy
    mount /dev/fd0 /mnt/floppy # Mount floppy
    cp -p /boot/chain.b /mnt/floppy # Copy chain loader
    cp -p /boot/boot* /mnt/floppy
    lilo -v -C /etc/lilo.floppy # Install lilo and the map onto floppy
    umount /mnt/floppy

Note that LILO sets the MBR to the settings as defined by the configuration file /etc/lilo.floppy.

Sample file: /etc/lilo.floppy

    boot=/dev/fd0                - Floppy drive (Location of Lilo boot sector)
    map=/mnt/floppy/map          - Locations on hard drive where the kernel can be found for boot
    prompt                       - Show prompt: LILO boot:
    linear                       - Specific to SCSI configurations
    timeout=50                   - Give the user time to decide (number of tenths of seconds) if there are multiple choices
    image=/boot/vmlinuz-2.2.17-14 - Boot this Linux kernel. This depends on your release of the operating system.
          label=hd_linux         - Label displayed to user which identifies this kernel
          root=/dev/sdb6         - System instructed to boot from this drive. Unique to your system. Example: /dev/hda4 Installation dependent.
          initrd=/boot/initrd-2.2.17-14.img  - This is specific to systems using SCSI hard drives. This line is omitted for IDE.
          read-only              - Mount partition read-only at first to run fsck
         

Note:

    Actual kernel name and version will depend on your Linux release.
    Most of the information for /etc/lilo.floppy should be copied from /etc/lilo.conf
    Actual names for the files to be used may be seen in the directory /boot
    The file initrd-2.2.17-14.img is required by systems using modular SCSI support.
    It is generated using the command: mkinitrd /boot/initrd-2.2.17-14.img 2.2.17-14
    and should also be copied to the floppy.

MBR restoration:
Once the system has rebooted using LILO on the MBR of the floppy to point to the kernel on your hard drive, the system will boot as before.

The last step. As root execute the command: /sbin/lilo -v
This will re-install LILO on the MBR of your hard drive using the configuration file /dev/lilo.conf.

Sample file /etc/lilo.conf:
(This should already reside on your system. Generated by a Linux installation)

    boot=/dev/sda                              - Location of Lilo boot sector. (i.e.: /dev/hda for first EIDE drive)
    map=/boot/map
    install=/boot/boot.b
    prompt
    linear
    default=linux
    timeout=50

    image=/boot/vmlinuz-2.2.17-14
          label=linux
          root=/dev/sdb6
          initrd=/boot/initrd-2.2.17-14.img     - This is specific to systems using SCSI hard drives. This line is omitted for IDE.
          read-only

    other=/dev/sda1
          label=win98
         

Explanation of files:

    /etc/lilo     LILO configuration file
    /boot/boot.b     Boot loader
    /boot/map     Boot map that contains the location of the kernel
    /sbin/lilo     Program to install lilo. Installs map.

Usage:
Just boot with the floppy in it's drive. The BIOS settings may have to be changed to allow the computer to boot from the floppy drive by changing the device seek order. The floppy (A:) needs to be ahead of the hard drive (C:). To enter the BIOS configuration utility, reboot the system and press the "DEL" key while booting. (Typically. Your system may be different)

Creation of a Recovery Disk:
As root user (on Red Hat), use the command: /sbin/mkbootdisk 2.2.17-14
You may specify the device: /sbin/mkbootdisk --device /dev/fd0 2.2.17-14

This will of course depend on the version of the Linux kernel you are using. To obtain the kernel version see your /etc/lilo.conf file or the name of the kernel modules library directory for the information. ( ls /lib/modules/ Use the directory name of the appropriate kernel. i.e. if the directory name is /lib/modules/2.4.9-34/ then use 2.4.9-34)

Usage:

    Boot computer with the floppy in it's drive.

    It will boot the kernel from the floppy but then try to use your hard drive. If successful, it will fully boot from your hard drive. It's Painless!!

Rescue Floppy Images:

    Toms.net Linux on 1 floppy disk
    Rescue images (ibiblio.org)

    Use the command: fdisk /dev/sda (SCSI) or fdisk /dev/hda (IDE) or whatever your drive is. Try hda3, hda4, hda5, etc.. untill you find your partitions.

        [root /root]# fdisk /dev/sdb

        The number of cylinders for this disk is set to 1106.
        There is nothing wrong with that, but this is larger than 1024,
        and could in certain setups cause problems with:
        1) software that runs at boot time (e.g., LILO)
        2) booting and partitioning software from other OSs
           (e.g., DOS FDISK, OS/2 FDISK)

        Command (m for help): p

        Disk /dev/sdb: 255 heads, 63 sectors, 1106 cylinders
        Units = cylinders of 16065 * 512 bytes

           Device Boot    Start       End    Blocks   Id  System
        /dev/sdb1   *         1         3     24066   83  Linux
        /dev/sdb2             4      1106   8859847+   5  Extended
        /dev/sdb5             4        36    265041   82  Linux swap
        /dev/sdb6            37      1106   8594743+  83  Linux

        Command (m for help): q

        [root /root]#
           

    The purpose of this is to determine your configuration. Disk partition and mount points are also held in the file: /etc/fstab (file systems table)

    Mount the partition you wish to operate on:
        mkdir /mntpoint
        mount /dev/sdb6 /mntpoint
        ls /mntpoint - Shows that it works and files are accessible.
        At this point you can tar files to a tape, run lilo to repair the MBR, perform a disk check (fsck or e2fsck) or repair your system.

Floppy Duplications:
Copying a 3.5 inch floppy (device /dev/fd0) using Linux:

        dd if=boot.img of=/dev/fd0 bs=1440k
       

Recovery using the installation CD:

    Insert Redhat binary install CD-ROM
    Boot from CD (You may have to change BIOS settings)
    At the boot: prompt, type linux rescue. You are then asked to chose an installation method.
    Instead of install, choose the Upgrade option but don't add any new packages. It will eventually prompt you to make a boot floppy.
    Boot from the boot floppy and mount your hard drive. i.e.: mount /dev/hda4 /hda4
    You can use fdisk as shown above to investigate your drives and partitions.

Creating a Bootable GRUB Legacy (V 0.57) CD:

This uses the GRUB files "menu.lst" and "stage2_eltorito".

    mkdir -p iso/boot/grub
    cp /lib/grub/i386-pc/stage2_eltorito iso/boot/grub
    cp /lib/grub/i386-pc/menu.1st iso/boot/grub
    Copy all files, OS files, etc to iso that you wish to put on the CD
    mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table -o grub.iso iso

This generates a file grub.iso which can burned to CD or DVD.
Tuesday, February 20, 2018

Basic Vi Commands


The default editor that comes with the UNIX operating system is called vi (visual editor). [Alternate editors for UNIX environments include pico and emacs, a product of GNU.]

The UNIX vi editor is a full screen editor and has two modes of operation:
Command mode commands which cause action to be taken on the file, and
Insert mode in which entered text is inserted into the file.

In the command mode, every character typed is a command that does something to the text file being edited; a character typed in the command mode may even cause the vi editor to enter the insert mode. In the insert mode, every character typed is added to the text in the file; pressing the <Esc> (Escape) key turns off the Insert mode.

While there are a number of vi commands, just a handful of these is usually sufficient for beginning vi users. To assist such users, this Web page contains a sampling of basic vi commands. The most basic and useful commands are marked with an asterisk (* or star) in the tables below. With practice, these commands should become automatic.

NOTE: Both UNIX and vi are case-sensitive. Be sure not to use a capital letter in place of a lowercase letter; the results will not be what you expect.

To Get Into and Out Of vi

To Start vi
To use vi on a file, type in vi filename. If the file named filename exists, then the first page (or screen) of the file will be displayed; if the file does not exist, then an empty file and screen are created into which you may enter text.
* vi filename edit filename starting at line 1
  vi -r filename recover filename that was being edited when system crashed

To Exit vi
Usually the new or modified file is saved when you leave vi. However, it is also possible to quit vi without saving the file.

Note: The cursor moves to bottom of screen whenever a colon (:) is typed. This type of command is completed by hitting the <Return> (or <Enter>) key.
* :x<Return> quit vi, writing out modified file to file named in original invocation
  :wq<Return> quit vi, writing out modified file to file named in original invocation
  :q<Return> quit (or exit) vi
* :q!<Return> quit vi even though latest changes have not been saved for this vi call

Moving the Cursor
Unlike many of the PC and MacIntosh editors, the mouse does not move the cursor within the vi editor screen (or window). You must use the the key commands listed below. On some
UNIX platforms, the arrow keys may be used as well; however, since vi was designed with the Qwerty keyboard (containing no arrow keys) in mind, the arrow keys sometimes produce strange effects in vi and should be avoided.

If you go back and forth between a PC environment and a UNIX environment, you may find that this dissimilarity in methods for cursor movement is the most frustrating difference between the two.

In the table below, the symbol ^ before a letter means that the <Ctrl> key should be held down while the letter key is pressed.
* j or <Return>
  [or down-arrow]
move cursor down one line
* k [or up-arrow] move cursor up one line
* h or <Backspace>
  [or left-arrow]
move cursor left one character
* l or <Space>
  [or right-arrow]
move cursor right one character
* 0 (zero) move cursor to start of current line (the one with the cursor)
* $ move cursor to end of current line
  w move cursor to beginning of next word
  b move cursor back to beginning of preceding word
  :0<Return> or 1G move cursor to first line in file
  :n<Return> or nG move cursor to line n
  :$<Return> or G move cursor to last line in file

Screen Manipulation

The following commands allow the vi editor screen (or window) to move up or down several lines and to be refreshed.
  ^f move forward one screen
  ^b move backward one screen
  ^d move down (forward) one half screen
  ^u move up (back) one half screen
  ^l redraws the screen
  ^r redraws the screen, removing deleted lines

Adding, Changing, and Deleting Text
Unlike PC editors, you cannot replace or delete text by highlighting it with the mouse. Instead use the commands in the following tables.

Perhaps the most important command is the one that allows you to back up and undo your last action. Unfortunately, this command acts like a toggle, undoing and redoing your most recent action. You cannot go back more than one step.
* u UNDO WHATEVER YOU JUST DID; a simple toggle

The main purpose of an editor is to create, add, or modify text for a file.

Inserting or Adding Text
The following commands allow you to insert and add text. Each of these commands puts the vi editor into insert mode; thus, the <Esc> key must be pressed to terminate the entry of text and to put the vi editor back into command mode.
* i insert text before cursor, until <Esc> hit
  I insert text at beginning of current line, until <Esc> hit
* a append text after cursor, until <Esc> hit
  A append text to end of current line, until <Esc> hit
* o open and put text in a new line below current line, until <Esc> hit
* O open and put text in a new line above current line, until <Esc> hit

Changing Text
The following commands allow you to modify text.
* r replace single character under cursor (no <Esc> needed)
  R replace characters, starting with current cursor position, until <Esc> hit
  cw change the current word with new text,
starting with the character under cursor, until <Esc> hit
  cNw change N words beginning with character under cursor, until <Esc> hit;
  e.g., c5w changes 5 words
  C change (replace) the characters in the current line, until <Esc> hit
  cc change (replace) the entire current line, stopping when <Esc> is hit
  Ncc or cNc change (replace) the next N lines, starting with the current line,
stopping when <Esc> is hit

Deleting Text
The following commands allow you to delete text.
* x delete single character under cursor
  Nx delete N characters, starting with character under cursor
  dw delete the single word beginning with character under cursor
  dNw delete N words beginning with character under cursor;
  e.g., d5w deletes 5 words
  D delete the remainder of the line, starting with current cursor position
* dd delete entire current line
  Ndd or dNd delete N lines, beginning with the current line;
  e.g., 5dd deletes 5 lines

Cutting and Pasting Text
The following commands allow you to copy and paste text.
  yy copy (yank, cut) the current line into the buffer
  Nyy or yNy copy (yank, cut) the next N lines, including the current line, into the buffer
  p put (paste) the line(s) in the buffer into the text after the current line

Other Commands

Searching Text
A common occurrence in text editing is to replace one word or phase by another. To locate instances of particular sets of characters (or strings), use the following commands.
  /string search forward for occurrence of string in text
  ?string search backward for occurrence of string in text
  n move to next occurrence of search string
  N move to next occurrence of search string in opposite direction

Determining Line Numbers
Being able to determine the line number of the current line or the total number of lines in the file being edited is sometimes useful.
  :.= returns line number of current line at bottom of screen
  := returns the total number of lines at bottom of screen
  ^g provides the current line number, along with the total number of lines,
in the file at the bottom of the screen

Saving and Reading Files
These commands permit you to input and output files other than the named file with which you are currently working.
  :r filename<Return> read file named filename and insert after current line
(the line with cursor)
  :w<Return> write current contents to file named in original vi call
  :w newfile<Return> write current contents to a new file named newfile
  :12,35w smallfile<Return> write the contents of the lines numbered 12 through 35 to a new file named smallfile
  :w! prevfile<Return> write current contents over a pre-existing file named prevfile

Upgrade ownCloud From Packages


The best method for keeping ownCloud current on Linux servers is by configuring your system to use ownCloud’s Open Build Service repository. Then stay current by using your Linux package manager to install fresh ownCloud packages. After installing upgraded packages you must run a few more steps to complete the upgrade. These are the basic steps to upgrading ownCloud:

Make sure that you don’t skip a major release when upgrading via repositories. For example you can’t upgrade from 8.1.x to 9.0.x directly as you would skip the 8.2.x major release. See Upgrading Across Skipped Releases for more information.

-Disable all third-party apps.
-Make a fresh backup.
-Upgrade your ownCloud packages.
-Run occ upgrade (Optionally disable the Migration Test which might take a long time on large installations).
-Apply strong permissions to your ownCloud directories.
-Take your ownCloud server out of maintenance mode.
-Re-enable third-party apps.

When upgrading from oC 9.0 to 9.1 with existing Calendars or Addressbooks please have a look at the 9.0 release notes for important information about the needed migration steps during that upgrade.
Upgrade Tips

Upgrading ownCloud from our Open Build Service repository is just like any normal Linux upgrade. For example, on Debian or Ubuntu Linux this is the standard system upgrade command:

apt-get update && apt-get upgrade

Or you can upgrade just ownCloud with this command:

apt-get update && apt-get install owncloud

On Fedora, CentOS, and Red Hat Linux use yum to see all available updates:

yum check-update

You can apply all available updates with this command:

yum update

Or update only ownCloud:

yum update owncloud

Your Linux package manager only downloads the current ownCloud packages. Then your ownCloud server is immediately put into maintenance mode. You may not see this until you refresh your ownCloud page.

Then use occ to complete the upgrade. You must run occ as your HTTP user. This example is for Debian/Ubuntu:

sudo -u www-data php occ upgrade

This example is for CentOS/RHEL/Fedora:

sudo -u apache php occ upgrade

Optionally disable the Migration Test which might take a long time on large installations.

See Using the occ Command to learn more.
Setting Strong Directory Permissions

After upgrading, verify that your ownCloud directory permissions are set according to Setting Strong Directory Permissions.
Upgrading Across Skipped Releases

It is best to update your ownCloud installation with every new point release (e.g. 8.1.10), and to never skip any major release (e.g. don’t skip 8.2.x between 8.1.x and 9.0.x). If you have skipped any major release you can bring your ownCloud current with these steps:

-Add the repository of your current version (e.g. 8.1.x)
-Upgrade your current version to the latest point release (e.g. 8.1.10) via your package manager
-Run the occ upgrade routine (see Upgrade Quickstart above)
-Add the repository of the next major release (e.g. 8.2.x)
-Upgrade your current version to the next major release (e.g. 8.2.8) via your package manager
-Run the occ upgrade routine (see Upgrade Quickstart above)
-Repeat from step 4 until you reach the last available major release (e.g. 9.1.x)

You’ll find repositories of previous ownCloud major releases in the ownCloud Server Changelog.

Upgrading PostgreSQL Version on Ubuntu Server


When you need to upgrade the PostgreSQL version on Ubuntu, the process is pretty straightforward. This works for upgrading any version from Postgres 9.1, 9.2, 9.3, 9.4, 9.5, and 9.6.

We're going to be upgrading PostgreSQL server on Ubuntu in this guide. It doesn't matter which version you're upgrading from or to. You can do this with Postgres 9.1, 9.2, 9.3, 9.4, 9.5, and 9.6 or whatever is the most recent version. In this example, I'm upgrading Postgres 9.3 to Postgres 9.5 but all you have to do is replace the version numbers in the commands below to match which old version you're using and the new version you're upgrading to.

This only takes a couple minutes if you have a small database, so let's get started!

1. Install the latest version of Postgres
If you're using the default version available on Ubuntu, you can just upgrade to the latest postgres by running the following:

sudo apt-get upgrade

Otherwise if you want to upgrade to the very latest Postgres version, you can follow the instructions on their website here: https://www.postgresql.org/download/linux/ubuntu/

To find the installed versions that you currently have on your machine, you can run the following:

$ dpkg --get-selections | grep postgres
postgresql                  install
postgresql-9.3                  install
postgresql-9.6                  install
postgresql-client-9.3               install
postgresql-client-9.6               install
postgresql-client-common            install
postgresql-common               install
postgresql-contrib              install
postgresql-contrib-9.3              install
postgresql-contrib-9.6              install

You can also list the clusters that are on your machine by running

$ pg_lsclusters
Ver Cluster Port Status Owner    Data directory               Log file
9.3 main    5433 down   postgres /var/lib/postgresql/9.3/main /var/log/postgresql/postgresql-9.3-main.log
9.6 main    5432 online postgres /var/lib/postgresql/9.6/main /var/log/postgresql/postgresql-9.6-main.log

2. Stop Postgres before we make any changes
First thing's first, we need to stop any services using postgres so we can safely migrate our database.

sudo service postgresql stop

3. Rename the new Postgres version's default cluster
When Postgres packages install, they create a default cluster for you to use. We need to rename the new postgres cluster so that when we upgrade the old cluster the names won't conflict.

sudo pg_renamecluster 9.6 main main_pristine

4. Upgrade the old cluster to the latest version
Just replace the version (9.3) here with the old version of Postgres that you're currently using.

sudo pg_upgradecluster 9.3 main

5. Make sure everything is working again
We can start Postgres back up again and this time it should be running the new postgres 9.6 cluster.

sudo service postgresql start

You should also see that the old cluster is down and the new version of Postgres is up:

$ pg_lsclusters
Ver Cluster Port Status Owner    Data directory               Log file
9.3 main    5433 down   postgres /var/lib/postgresql/9.3/main /var/log/postgresql/postgresql-9.3-main.log
9.6 main    5432 online postgres /var/lib/postgresql/9.6/main /var/log/postgresql/postgresql-9.6-main.log

6. Drop the old cluster
Optionally, you can drop the old 9.3 cluster once you've verified the new one works and you don't need the old cluster anymore.

sudo pg_dropcluster 9.3 main

How to update cURL to the latest version?


The current cURL version installed on a server differs from the latest version on the cURL website.

How to update cURL to the latest version?

Answer
-Connect to a Plesk server via SSH.
-Update cURL to the latest version with the command:

# yum update curl.x86_64

Verify the version:

# curl --version

If a newer version has not been found or after an update the version is still not the latest, perform the following steps:

Create a city-fan.org yum repository file:

# touch /etc/yum.repos.d/city-fan.repo

Open the file /etc/yum.repos.d/city-fan.repo in any text editor and put the content below:

[CityFan]
name=City Fan Repo
baseurl=http://www.city-fan.org/ftp/contrib/yum-repo/rhel$releasever/$basearch/
enabled=1
gpgcheck=0

Enable the EPEL repository:

# yum install epel-release -y

   
Rerun the update:

# yum update curl.x86_64

Verify the version:

# curl --version

How to Upgrade MongoDB to Latest Stable Version


As usual with any software, old versions of MongoDB accumulate a number of security issues that if not addressed properly, could leave your data unprotected from attackers.

In order to ensure the best security and support possible, the MongoDB developers recommend to always install the latest stable version of MongoDB, which is 3.4.1 as of Feb 2017.

This guide explains:

-How to upgrade to MongoDB 3.4.1 via package manager
-How to upgrade to MongoDB 3.4.1 manually

Upgrading to MongoDB 3.4.1 via package manager
If you installed MongoDB from the MongoDB apt, yum, dnf, or zypper repositories, you should upgrade to 3.4.1 using your package manager.
Upgrading MongoDB on Ubuntu and other Debian derivatives

Debian package management tools (i.e. dpkg and apt) ensure package consistency and authenticity by requiring that distributors sign packages with GPG keys. Issue the following command to import the MongoDB public GPG Key:

$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6

Create the /etc/apt/sources.list.d/mongodb-org-3.4.list file replacing ubuntu xenial with the codename appropriate for your version of Ubuntu or Debian:

$ echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list

    Ubuntu 12.04: ubuntu precise
    Ubuntu 14.04: ubuntu trusty
    Ubuntu 16.04: ubuntu xenial
    Debian 7: debian wheezy
    Debian 8: debian jessie

Now issue the following command to reload the local package database and directly install the latest stable version of MongoDB:

$ sudo apt-get update
$ sudo apt-get install -y mongodb-org

Upgrading MongoDB on Amazon Linux, Red Hat Enterprise Linux, CentOS and Fedora
First of all, you need to create a /etc/yum.repos.d/mongodb-org-3.4.repo file so that yum knows where to find latest MongoDB packages. Please replace redhat/7 with the codename appropriate for your distribution and version as listed below:

[mongodb-org-3.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/7/mongodb-org/3.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc

    RHEL 5 | CentOS 5 | Fedora Core 6: redhat/5
    RHEL 6 | CentOS 6 | Fedora 12–14: redhat/6
    RHEL 7 | CentOS 7 | Fedora 19–25: redhat/7
    Amazon Linux: amazon/2013.03

Now you can simply issue the following command to install the latest version of MongoDB:

$ sudo yum install -y mongodb-org

On recent Fedora releases (>22), you may need to use dnf instead:

$ sudo dnf install -y mongodb-org

Upgrading MongoDB on SUSE, SLES and OpenSUSE
First of all, you will need to import the MongoDB public GPG Key:

$ sudo rpm --import https://www.mongodb.org/static/pgp/server-3.4.asc

Then add the MongoDB repository origin using zypper. Feel free to replace the version number 12 to match yours:

$ sudo zypper addrepo — gpgcheck “https://repo.mongodb.org/zypper/suse/12/mongodb-org/3.4/x86_64/" mongodb

Now you can simply issue the following command to install the latest version of MongoDB:

$ sudo zypper -n install mongodb-org

Upgrading MongoDB manually
If you have not installed MongoDB using a package manager, you can manually download the MongoDB binaries from the MongoDB Download Center.

For example, to download the latest release through the shell, issue the following:

$ curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.4.1.tgz

Then extract the files from the downloaded archive. From a system shell, you can extract through the tar command:

$ tar -zxvf mongodb-linux-x86_64-3.4.1.tgz

Now copy the extracted folder to the location from which you wish MongoDB to run:

$ mkdir -p mongodb
$ cp -R -n mongodb-linux-x86_64-3.4.1/ mongodb

The MongoDB binaries are in the bin/ directory of the archive. To ensure that the binaries are in your PATH, you can modify your PATH.

For example, you can add the following line to your shell’s rc file (e.g. ~/.bashrc):

export PATH=<mongodb-install-directory>/bin:$PATH

Remember to replace <mongodb-install-directory> with the path to the extracted MongoDB archive.

Now reload mongod and that’s all!

$ sudo service mongodb reload

How to upgrade to PHP 7 on CentOS 7 Linux Server


The objective is to install or replace existing PHP 5 with PHP 7 on CentOS 7 Linux server. As you will see, this procedure is fairly simple when using Remi Repository.

Requirements
Privileged access to your CentOS Linux system either directly as root user or via sudo command is required.

Difficulty
EASY

Conventions
# - requires given command to be executed with root privileges either directly as a root user or by use of sudo command
$ - given command to be executed as a regular non-privileged user

Instructions
The following guide will either upgrade your current PHP 5 to PHP 7 or will install new PHP 7 on your CentOS system. Check your current PHP version ( if applicable ):

# php --version
PHP 5.4.16 (cli) (built: Nov  6 2016 00:29:02)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

Download Remi and EPEL Repository packages
First, download Remi and EPEL Repository packages:

$ wget -q http://rpms.remirepo.net/enterprise/remi-release-7.rpm
$ wget -q https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

Enable Remi and EPEL Repository
Install both previously downloaded packages and enable Remi PHP 7 repo:

# rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm
FOR PHP 7.0 EXECUTE:
# yum-config-manager --enable remi-php70
FOR PHP 7.1 EXECUTE:
# yum-config-manager --enable remi-php71

Current latest PHP version from Remi repository is 7.1. Amend the above command for any other subsequent PHP releases.

Install or Upgrade to PHP 7
Whether you already have PHP 5 installed on your system or you are performing a new PHP 7 installation, the below command will cater for both:

# yum install php

Alternatively, upgrade entire system with yum update command:

# yum update

Check your current PHP version

# php --version
PHP 7.1.0 (cli) (built: Dec  1 2016 08:13:15) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.1.0-dev, Copyright (c) 1998-2016 Zend Technologies