database Archives - The Linux GURUS https://thelinuxgurus.com/tag/database/ Learn Linux & DevOPS from THE LINUX GURUS Wed, 06 Jan 2021 17:14:09 +0000 en-US hourly 1 https://i0.wp.com/thelinuxgurus.com/wp-content/uploads/2020/01/cropped-thelinuxgurus_transparent_name.png?fit=32%2C32&ssl=1 database Archives - The Linux GURUS https://thelinuxgurus.com/tag/database/ 32 32 148921671 How to setup Redis replication in Linux https://thelinuxgurus.com/how-to-setup-redis-replication-in-linux/ https://thelinuxgurus.com/how-to-setup-redis-replication-in-linux/#respond Wed, 06 Jan 2021 17:14:09 +0000 https://thelinuxgurus.com/?p=1289 One of the features that make REDIS a good caching application is the ability to configure a cluster with one master/primary & one or more...

The post How to setup Redis replication in Linux appeared first on The Linux GURUS.

]]>
One of the features that make REDIS a good caching application is the ability to configure a cluster with one master/primary & one or more slaves/secondary servers. In this tutorial, we will learn to set up redis replication in our Linux servers.

For the purpose of this tutorial, we will be creating a single Primary & a single secondary server. So let’s discuss the pre-requisites for setting up redis replication.

Recommended Read: How to create a free SSL certificate using Let’s Encrypt in Linux

Also Read: How to Schedule a Shutdown in Linux using Crontab?


Pre-Requisites

2 servers with Redis installed, one will act as the Primary server (10.10.10.10 IP address for our scenario) & another will act as the Secondary server (IP address 10.10.10.11 ).

You can read the following tutorials to install Redis in Ubuntu or in CentOS/RHEL. 

Now let’s move on to the configuration part.


Configuring the Redis replication

Primary Server

First, we will start with the Primary server & will configure it. Open the redis configuration file on the primary server. 

Depending on how you have installed it, the configuration file can be ‘/etc/redis/redis/conf’ or ‘/etc/redis/6379.conf’,

$ sudo vi /etc/redis/redis.conf

& look for ‘append’ & ‘appendfilename’, then change it to following,

appendonly yes

appendfilename “appendonly.aof​”

Now restart the redis service to implement the changes made,

$ sudo systemctl restart redis

OR

$ sudo systemctl restart redis_6379 

Now let’s move on to configuring the secondary server.


Secondary Server

Open the redis configuration file on the secondary server, 

$ sudo vi /etc/redis/redis.conf

& look for ‘slaveof’ & change it to following,

slaveof 10.10.10.10 6379

here, ‘10.10.10.10’ is the IP address for the Primary redis server. & ‘6379’ is the port number for redis on that server.  Once changes have been done, restart the service to implement changes,

$ sudo  systemctl restart redis

OR

$ sudo systemctl restart redis_6379

That’s it our setup for redis replication is complete, we will now verify it.


Checking the replication

To check if the master-slave setup is working, connect to the master redis instance using the following command,

$ redis-cli -h 10.10.10.10 -p 6379

 

& run command ‘info’,

10.10.10.10:6379> info

 

We will get the following output, here look for ‘replication’,

# Replication

role:master

connected_slaves:1

Slave0:

ip=10.10.10.11,

port=6379,

state=online,

offset=215,

lag=0

master_repl_offset:215

repl_backlog_active:1

repl_backlog_size:1048576

repl_backlog_first_byte_offset:2

repl_backlog_histlen:214

 

Here we can see the IP address for the secondary server i.e. 10.10.10.11, also it shows the number of secondary servers i.e. 1.  

We can also try adding a key on the Primary server, that will be replicated to the secondary server in real-time. To create a test key-value, login to redis instance & execute the following command,

10.10.10.10:6379> set test “testing”

 

now to check the key on the master, run command ‘get test’

10.10.10.10:6379> get test “testing”

 

Now, login to slave server & check if the key ‘test’ has been replicated or not,

$ redis-cli -h 10.10.10.11 -p 6379

 

& run ‘get test’ command,

10.10.10.11:6379> get test “testing”

 

This shows that the key has been replicated to the slave server as well & our master-slave data replication is working fine.


Promoting Secondary server as Primary

So in case, the Primary server fails or there is any other issue, we can promote the secondary server as the primary server. To do this connect to the redis instance of the secondary server,

$ redis-cli -h 10.10.10.11 -p 6379

& execute the following command,

10.10.10.11:6379> SLAVEOF NO ONE

Now the secondary server will act as the primary server. You will be required to update the IP address of redis to the application where you have configured it.

Also if there is more than one redis secondary server, then you are required to update the field,

slaveof 10.10.10.11 6379

on all the secondary servers to point to a new primary server.


Reconnecting to Original Primary server

Once the original primary server is up, we can then reconnect the secondary server to the primary server by the following method, connect to the redis instance of the secondary server,

$ redis-cli -h 10.10.10.11 -p 6379

& execute the following command,

10.10.10.11:6379> SLAVEOF 10.10.10.10 6379

That’s it, this was our tutorial on how setup Redis Replication in Linux. Please do send in any questions or queries using the comment box below.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter | Linkedin

TheLinuxGURUS are thankful for your continued support.

The post How to setup Redis replication in Linux appeared first on The Linux GURUS.

]]>
https://thelinuxgurus.com/how-to-setup-redis-replication-in-linux/feed/ 0 1289
Install Redis on CentOS / RHEL https://thelinuxgurus.com/install-redis-on-centos-rhel/ https://thelinuxgurus.com/install-redis-on-centos-rhel/#respond Mon, 14 Dec 2020 15:42:45 +0000 https://thelinuxgurus.com/?p=1268 Redis is an open-source in-memory key-value data structure store that can be used as a cache server, message broker, etc. We can use a number...

The post Install Redis on CentOS / RHEL appeared first on The Linux GURUS.

]]>
Redis is an open-source in-memory key-value data structure store that can be used as a cache server, message broker, etc. We can use a number of data types with redis like strings, lists, maps, sets, sorted sets, HyperLogs, bitmaps, streams, and spatial indexes.

It also provides a number of features like,

  • Replication
  • data persistence
  • LRU eviction
  • High availability using sentinel
  • Publish / Subscribe support for data
  • Keys with limited TTL
  • Automatic Failover
  • LUA scripting, etc

Recommended Read: Install Redis on Ubuntu

Also Read: How to Host Multiple Websites with Nginx in Linux

So let’s start the process to install Redis on CentOS or RHEL.


Install Redis on CentOS

Redis packages are available on EPEL repository, so we are required to install the EPEL repository on our CentOS/ RHEL system first. Install it with the following command,

# yum install epel-release

Once the epel repository has been installed, we can install redis with the following command,

# yum install redis

Start service using the following command,

# systemctl start redis


Another method to install Redis on CentOS

With this method, we can install the latest version of redis or for that matter any version we need. We will installing the latest version at this time, i.e. 6.0.9.. Download the redis package with the following command,

# wget https://download.redis.io/releases/redis-6.0.9.tar.gz

Next extract the redis package,

# tar -xvf  redis-6.0.9.tar.gz

Now goto the extracted folder,

# cd redis-6.0.9

& then goto folder ‘deps’,

$ cd deps

next compile packages, ,

$ make hiredis lua jemalloc linenoise

$ make geohash-int

Next, we will move back to the main directory i.e. ‘redis-6.0.9’

$ cd ../

execute  ‘make’ & ‘make install’ commands

$ make

$ make installation

Once these commands have been executed, we will install the init scripts, init script will setup a redis service with port number, config file, log file & a data directory. To run run init script,

$ cd utils\

& run the install_server.sh script,

$ ./install_server.sh

We will now be asked with some information regarding redis server, as shown below,

Welcome to the redis service installer

This script will help you easily set up a running redis server

Please select the redis port for this instance: [6379]

Selecting default: 6379

Please select the redis config file name [/etc/redis/6379.conf]

Selected default – /etc/redis/6379.conf

Please select the redis log file name [/var/log/redis_6379.log]

Selected default – /var/log/redis_6379.log

Please select the data directory for this instance [/var/lib/redis/6379]

Selected default – /var/lib/redis/6379

Please select the redis executable path [/usr/local/bin/redis-server]

Selected config:

Port : 6379

Config file : /etc/redis/6379.conf

Log file : /var/log/redis_6379.log

Data dir : /var/lib/redis/6379

Executable : /usr/local/bin/redis-server

Cli Executable : /usr/local/bin/redis-cli

Is this ok? Then press ENTER to go on or Ctrl-C to abort.

Copied /tmp/6379.conf => /etc/init.d/redis_6379

Installing service…

Successfully added to chkconfig!

Successfully added to runlevels 345!

Starting Redis server…

Installation successful!

Modify any settings as per your requirements & can also install more than one redis instances by just changing the redis port number.

Now to start the redis service, command is a bit different as service name will be different,

# systemctl start redis_6379

So just change the port number to start only a single redis instance.


Testing Redis installation

We can now check if the redis has been installed by running the following command,

$ redis-cli –version

We can also connect to the installed redis server with the following command,

$ redis-cli

then check the response to ping command for redis,

redis > PING

In response, we should get PONG as output.


Allowing remote connections to Redis installation

By default, we can only connect to redis server from the local server. To allow connections to redis installation from remote machines, we need to make changes to redis configuration file,

$ sudo vi /etc/redis/redis.conf

then look for section that says ‘bind 127.0.0.1’ & change it

bind 0.0.0.0 

to allow connections from all remote servers or we can also mention single or multiple IP addresses to allow connections from those servers only, like

bind 10.10.10.10 192.168.1.10

here, connections will be allowed from two machines with IP addresses 10.10.10.10 & from 192.168.1.10.

Once the changes have been made, we need to restart the redis service to apply changes,

$ sudo systemctl restart redis

This completes our tutorial on how to install Redis on CentOS & RHEL. Please do send in any questions or queries using the comment box below.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter | Linkedin

TheLinuxGURUS are thankful for your continued support.

The post Install Redis on CentOS / RHEL appeared first on The Linux GURUS.

]]>
https://thelinuxgurus.com/install-redis-on-centos-rhel/feed/ 0 1268
Beginner’s guide to Backup Postgres Database https://thelinuxgurus.com/beginners-guide-to-backup-postgres-database/ https://thelinuxgurus.com/beginners-guide-to-backup-postgres-database/#respond Tue, 28 Apr 2020 14:14:22 +0000 https://thelinuxgurus.com/?p=863 Backups are important & they are our only contingency for when we delete things that we should not or there are malfunctions hardware or otherwise....

The post Beginner’s guide to Backup Postgres Database appeared first on The Linux GURUS.

]]>
Backups are important & they are our only contingency for when we delete things that we should not or there are malfunctions hardware or otherwise. Backups at regular intervals are essential for any organization to maintain a proper working environment. Same goes for database, database backups are extremely essential as it holds transactional, user data among other things.

In this tutorial, we will learn about PostgreSQL backup. Before we start this, you can also refer to our tutorials on installing Postgresql on CentOS/RHEL, also for installation on Ubuntu & installing Postgresql from the source.

Recommended Read: Important postgresql commands for beginners


Backup Postgres Database


Postgresql provides backup utilities when we install postgresql on the server, they are pg_dump & pg_dumpall. Pg_dump is most useful for taking postgresql backup of a single database, while pg_dumpall provides the postgresql backup for all databases on the server. Let’s see some examples.

Backup Postgres database, single DB

Start by switching to the user postgres,

# su – postgres

Now to back up a database, use the following command,

$ pg_dump -U user_name -d thelinuxgurus > thelinuxgurus.bak

Here, ‘thelinuxgurus’ is the name of the database we need to backup. We can also use .sql or .tar as extension to backup file.


Taking backup of one or more tables in postgres

Command to take the backup of a single table from a database is,

$ pg_dump -U User_name -d database_name -t public.users_table > users_table.bak

To take the backup of more tables,

$ pg_dump -U User_name -d database_name -t public.users_table public.test_table public.test_table_2 > 3_tables.bak


Restoring a database

Now if we need to restore the backup, we need to drop the old database & create an empty database,

$ dropdb thelinuxgurus

$ createdb new_db

Not to restore the backup, use the following command,

$ psql new_db < thelinuxgurus.bak

Or we can also use pg_restore utility to restore a database, use the following command to restore the database using pg_restore utility,

$ pg_restore -d db_name /path/to/your/file/thelinuxgurus.bak -c -U db_user


Restore one or more tables from backup

Similarly, we can also restore the backup of one or more tables,

$ pg_restore -U user_name –data-only -d target-db-name -t table_name /path/to/your/file/users_table.bak


Taking only schema backup

To take the backup of schema only, use the following command,

$ pg_dump –schema=schema_name db_name > schema.bak


Restoring schema backup

To restore schema backup, use the following command,

$ psql -d db_name -U user_name < schema.bak


Taking all database backup

The second backup utility i.e. pg_dumpall is used for taking backup of all the databases on postgreSQL. To take backup use the following command,

$ pg_dumpall > all_databases.bak


Restore all databases backup

To restore all database backup, use the following command,

$ psql -f all_databases.bak postgres

We can also use all or any of the above-mentioned commands & create a cron job for it to automate our backups. Please refer to our tutorial on Scheduling Cron jobs on Linux system. We now end this tutorial on backup Postgres database. Please feel free to send in any questions or queries using the comment box below.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter | Linkedin

TheLinuxGURUS are thankful for your continued support.

The post Beginner’s guide to Backup Postgres Database appeared first on The Linux GURUS.

]]>
https://thelinuxgurus.com/beginners-guide-to-backup-postgres-database/feed/ 0 863
Important PostgreSQL commands that every beginner should know https://thelinuxgurus.com/important-postgresql-commands-that-every-beginner-should-know/ https://thelinuxgurus.com/important-postgresql-commands-that-every-beginner-should-know/#respond Tue, 03 Mar 2020 06:05:03 +0000 https://thelinuxgurus.com/?p=894 PostgreSQL is one of the most widely used databases in the world & is also very easy to administer. In this tutorial, we will learn...

The post Important PostgreSQL commands that every beginner should know appeared first on The Linux GURUS.

]]>
PostgreSQL is one of the most widely used databases in the world & is also very easy to administer. In this tutorial, we will learn some important postgresql commands that every beginner should know.

In our previous tutorials, we have learned to install postgresql on CentOS/RHEL, on Ubuntu & also learned to install Postgresql from source. So if you need to install postgresql first, please refer to those tutorials.

Recommended Read: Scheduling CRON Jobs with Crontab for Beginners

Also Read: Beginner’s guide to Backup Postgres Database


PostgreSQL commands


1- Connect to the database

Connection from localhost,

# su – postgres

Now to connect to the database, we will run the command ‘psql’,

$ psql

Once into the database, we can use ‘\q’ to exit the database,

postgres=# \q

Connecting from Remote server,

# psql -h host_ip -U user_name -p port_number -d database_name


2- Create role/user

To create a role, first connect to database & then we will use command ‘createuser’,

postgres=# CREATE USER test;

Or we can also use the following,

postgres=# CREATE ROLE test;

To create a user with password,

$ CREATE USER test PASSWORD ‘enter password here’


3- Delete a role/user

To delete a role, we will use the DROP command,

postgres=# DROP ROLE test;


4- Show list of users (List of roles)

postgres=# \du


5- Create a new Database

To create a new database, use the following,

postgres=# CREATE DATABASE thelinuxgurus;


6- Delete a database

To delete a created database, use

postgres=# DROP DATABSE thelinuxgurus;


7- Show list of databases

postgres=# \l


8- Change DB when you are connected to other DB

postgres=# \c thelinuxgurus;

Or we can also user the following command,

postgres-# \connect new_database


9- Create a table

To create a table, connect to the desired database & create a table with the following command,

thelinuxgurus=> CREATE TABLE USERS (Serial_No int, First_Name varchar, Last_Name varchar);

Now insert some records into it,

thelinuxgurus=> INSERT INTO USERS VALUES (1, ‘Dan’, ‘Prince’);


10- Delete a table

To delete a table from the database, we will use,

thelinuxgurus=> DROP TABLE USERS;


11- List tables

postgres=# \dt


12- Describe a table to show its structure

postgres=# \d table_name


13- Adding a column to a table

Once a table has been created, it can be altered to add new columns to it using the following command,

thelinuxgurus=> ALTER TABLE USERS ADD date_of_birth date;


14- Updating a Row

We can not only alter the columns of a table but can also update the records that are entered in rows,

thelinuxgurus=> UPDATE USERS SET date_of_birth = ‘03-04-1990’ WHERE Seriel_No = ‘1’;

thelinuxgurus=> SELECT * FROM USERS;

The last command was to verify the changes that were made.


15- Remove a Column

To remove a column from a table, run

thelinuxgurus=> ALTER TABLE USERS DROP date_of_birth;


16- Remove a Row

To delete a row, use the following example,,

thelinuxgurus=> DELETE FROM USERS WHERE Seriel_No = ‘1’;


17- List of all functions

To check all the functions on the database, use

postgres=# \df


18- To edit function

To edit a function, use the following command,

postgres=# \ef function_name


19- List of all schema in DB

To see all the schemas on the database, use

postgres=# \dn


20- To check the current Installed version

postgres=# select version();


21- To display the command history

postgres=# \s


22- Execute psql commands using a file

So if we have a file (like a .sql file) & we need to execute the file into our database, then use the following command

postgres=# \i /path/file_name


23- To turn on query execution time

postgres=# \timing


24) To list database views

postgres=# \dv


25) Check current date

postgres=# select now();

These were some of the important PostgreSQL commands that everyone should know about to maintain & administer the PostgreSQL database. Please feel free to send in any question or queries using the comment box below.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter | Linkedin

TheLinuxGURUS are thankful for your continued support.

The post Important PostgreSQL commands that every beginner should know appeared first on The Linux GURUS.

]]>
https://thelinuxgurus.com/important-postgresql-commands-that-every-beginner-should-know/feed/ 0 894
Simple guide to install MongoDB on Ubuntu 18.04 https://thelinuxgurus.com/simple-guide-to-install-mongodb-on-ubuntu-18-04/ https://thelinuxgurus.com/simple-guide-to-install-mongodb-on-ubuntu-18-04/#respond Fri, 24 Jan 2020 07:04:22 +0000 https://thelinuxgurus.com/?p=1037 MongoDB is a free & open-source No-SQL database, it uses JSON like document format to store data in the database which is unlike the SQL...

The post Simple guide to install MongoDB on Ubuntu 18.04 appeared first on The Linux GURUS.

]]>
MongoDB is a free & open-source No-SQL database, it uses JSON like document format to store data in the database which is unlike the SQL database, where data is stored in a row & column-based format.

MongoDB is very fast & has great performance when compared to the SQL database. MongoDB databases are very easy to scale & they also address various shortcomings that other SQL databased present. MongoDB is completely ideal for the types of DB required to handle the data that we have today i.e. big data, IoT, online gaming, etc.

Recommended Read: Scheduling CRON Jobs with Crontab for Beginners

Also Read: Ultimate guide to install PYTHON from source

In this tutorial, we will learn to install MongoDB on Ubuntu 18.04. There are two methods with which we can install MongoDB on Ubuntu 18.04,

1- Install using apt manager,

2- Install using tar packages.


1- Install MongoDB on Ubuntu 18.04 using apt

We need to first make sure that “gnupg” package is installed on the system or not, cause we will receive an error while importing the public keys for mongodb if it’s not installed. Install it with the following command,

$ sudo apt-get install gnupg

Next, we will import the public keys for MongoDB,

$ wget -qO – https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add –

Next, we will create the list file for MongoDB with the following command,

$ echo “deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse” | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list

Now reload the repositories for packages,

$ sudo apt-get update

Now to install MongoDB on Ubuntu 18.04, execute

$ sudo apt-get install -y mongodb-org

Or to install a specific version, use

$ sudo apt-get install -y mongodb-org=4.2.2 mongodb-org-server=4.2.2 mongodb-org-shell=4.2.2 mongodb-org-mongos=4.2.2 mongodb-org-tools=4.2.2


2- Install MongoDB on Ubuntu 18.04 using tar packages

Before we can download & install mongodb using tar packages. We must have some packages installed on our servers,

$ sudo apt-get install libcurl4 openssl

We will create a directory for keeping the mongodb packages,

$ mkdir -p /data/mongodb

Next, we have to download the package using the following command,

$ wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1804-4.2.2.tgz

Next, we need to extract the file to the created directory,

$ tar -xvzf mongodb-linux-x86_64-ubuntu1804-4.2.2.tgz -C /data/mongodb

Next, we will create symbolic links to the binaries directory,

$ sudo ln -s /data/mongodb/bin/* /usr/local/bin/

Now, we need to create a data directory & log directory as well,

$ sudo mkdir -p /var/lib/mongo

$ sudo mkdir -p /var/log/mongo

Next, we have change ownership of these folders to mongod,

$ sudo chown -R mongod:mongod /var/lib/mongo

$ sudo chown -R mongod:mongod /var/log/mongo

Note: When installing using apt package manager, all these folders are created by the system only with required permissions.


Starting & connecting MongoDB

Once we have installed mongodb, we can start the database with the following command,

$ sudo systemctl start mongod

Also, we can use the following command to start db,

$ mongod –dbpath /var/lib/mongo –logpath /var/log/mongodb/mongod.log –fork

Now to connect to the database,

$ mongo


Connecting database from remote systems

By default, we can only connect the database from the localhost & to be able to connect the database from other systems, we need to make configuration in mongodb configuration file,

$ sudo vi /etc/mongod.conf

& look for “net.bindIp”, then change it the following

net.bindIp 0.0.0.0

You can also change & mention a single remote IP address if you only need to connect from a single remote system. After making the changes, you need to restart the database to implement the changes made,

$ sudo systemctl stop mongod

$ sudo systemctl start mongod

Note:- If running database through CLI, we can mention the parameter “–bind_ip” followed by ‘0.0.0.0’ for connecting from all remote IPs or we can also mention a single IP address.

That’s it guys, we now end this tutorial on how to install MongoDB on 18.04. Please do send us your questions, queries & suggestions using the comment box below.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter | Linkedin

TheLinuxGURUS are thankful for your continued support.

The post Simple guide to install MongoDB on Ubuntu 18.04 appeared first on The Linux GURUS.

]]>
https://thelinuxgurus.com/simple-guide-to-install-mongodb-on-ubuntu-18-04/feed/ 0 1037
Install MongoDB on Ubuntu 16.04 https://thelinuxgurus.com/install-mongodb-on-ubuntu-16-04/ https://thelinuxgurus.com/install-mongodb-on-ubuntu-16-04/#respond Fri, 24 Jan 2020 05:52:28 +0000 https://thelinuxgurus.com/?p=1026 MongoDB is a free & open-source No-SQL database, it uses JSON like document format to store data in the database which is unlike the SQL...

The post Install MongoDB on Ubuntu 16.04 appeared first on The Linux GURUS.

]]>
MongoDB is a free & open-source No-SQL database, it uses JSON like document format to store data in the database which is unlike the SQL database, where data is stored in a row & column-based format.

MongoDB is very fast & has great performance when compared to the SQL database. MongoDB databases are very easy to scale & they also address various shortcomings that other SQL databased present. MongoDB is completely ideal for the types of DB required to handle the data that we have today i.e. big data, IoT, online gaming, etc.

Recommended Read: Important PostgreSQL commands that every beginner should know

Also Read: Complete guide to install MongoDB on CentOS/RHEL

In this tutorial, we will learn to install MongoDB on Ubuntu 16.04. There are two methods with which we can install MongoDB on Ubuntu 16.04,

1- Install using apt manager,

2- Install using tar packages.


1- Install MongoDB on Ubuntu 16.04 using apt

We need to first make sure that “gnupg” package is installed on the system or not, cause we will receive an error while importing the public keys for mongodb if it’s not installed. Install it with the following command,

$ sudo apt-get install gnupg

Next, we will import the public keys for MongoDB,

$ wget -qO – https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add –

Next, we will create the list file for MongoDB with the following command,

$ echo “deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.2 multiverse” | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list

Now reload the repositories for packages,

$ sudo apt-get update

Now to install MongoDB on Ubuntu 16.04, execute

$ sudo apt-get install -y mongodb-org

Or to install any specific versions, use the command,

$ sudo apt-get install -y mongodb-org=4.2.2 mongodb-org-server=4.2.2 mongodb-org-shell=4.2.2 mongodb-org-mongos=4.2.2 mongodb-org-tools=4.2.2


2- Install MongoDB on Ubuntu 16.04 using tar packages

Before we can download & install mongodb using tar packages. We must have some packages installed on our servers,

$ sudo apt-get install libcurl3 openssl

We will create a directory for keeping the mongodb packages,

$ mkdir -p /data/mongodb

Next, we have to download the package using the following command,

$ wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1604-4.2.2.tgz

Next, we need to extract the file to the created directory,

$ tar -xvzf /mongodb-linux-x86_64-ubuntu1604-4.2.2.tgz -C /data/mongodb

Next, we will create symbolic links to the binaries directory,

$ sudo ln -s /data/mongodb/bin/* /usr/local/bin/

Now, we need to create a data directory & log directory as well,

$ sudo mkdir -p /var/lib/mongo

$ sudo mkdir -p /var/log/mongo

Next, we have change ownership of these folders to mongod,

$ sudo chown -R mongod:mongod /var/lib/mongo

$ sudo chown -R mongod:mongod /var/log/mongo

Note: When installing using apt package manager, all these folders are created by the system only with required permissions.


Starting & connecting MongoDB

Once we have installed mongodb, we can start the database with the following command,

$ sudo systemctl start mongod

Also, we can use the following command to start db,

$ mongod –dbpath /var/lib/mongo –logpath /var/log/mongodb/mongod.log –fork

Now to connect to the database,

$ mongo


Connecting database from remote systems

By default, we can only connect the database from the localhost & to be able to connect the database from other systems, we need to make configuration in mongodb configuration file,

$ sudo vi /etc/mongod.conf

& look for “net.bindIp”, then change it the following

net.bindIp 0.0.0.0

You can also change & mention a single remote IP address if you only need to connect from a single remote system. After making the changes, you need to restart the database to implement the changes made,

$ sudo systemctl stop mongod

$ sudo systemctl start mongod

Note:- If running database through CLI, we can mention the parameter “–bind_ip” followed by ‘0.0.0.0’ for connecting from all remote IPs or we can also mention a single IP address.

That’s it guys, we now end this tutorial on how to install MongoDB on 16.04. Please do send us your questions, queries & suggestions using the comment box below.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter | Linkedin

TheLinuxGURUS are thankful for your continued support.

The post Install MongoDB on Ubuntu 16.04 appeared first on The Linux GURUS.

]]>
https://thelinuxgurus.com/install-mongodb-on-ubuntu-16-04/feed/ 0 1026
How to install MySQL on Ubuntu https://thelinuxgurus.com/how-to-install-mysql-on-ubuntu/ https://thelinuxgurus.com/how-to-install-mysql-on-ubuntu/#respond Tue, 31 Dec 2019 06:04:10 +0000 https://thelinuxgurus.com/?p=879 MySQL is a popular Open Source Relational Database System aka RDBMS. MySQL uses a relational database & structured query language (SQL) to manage all the...

The post How to install MySQL on Ubuntu appeared first on The Linux GURUS.

]]>
MySQL is a popular Open Source Relational Database System aka RDBMS. MySQL uses a relational database & structured query language (SQL) to manage all the data. It’s used for developing all sorts of web-based applications.

It’s one of the most widely used database servers in the world & also the main component of the LAMP stack. In this tutorial, we will learn how we can install MySQL on Ubuntu.

Recommended Read: Simple guide to install POSTGRESQL on Ubuntu

Also Read: How to setup SSH login without password on Linux systems


Install MySQL on Ubuntu

Installation of MySql is fairly simple as the mysql packages are available with the default Ubuntu repositories. In order to install Mysql on Ubuntu, we only have run the following command from the terminal,

$ sudo apt-get update && sudo apt-get upgrade -y

$ sudo apt-get install mysql-server

Once the installation starts, we will be asked to enter a root password for MySQL. Enter a password and remember it as it will be required after installation, for configuration of mysql as well,

install mysql on ubuntu

Once the mysql has been installed, we need not start the mysql service as its started by default but we can check to make sure that its up & running by executing the following command,

$ sudo systemctl status mysql

Commands to start, stop & restart mysql service are,

$ sudo systemctl start mysql

$ sudo systemctl stop mysql

$ sudo systemctl restart mysql


Configuring MySQL

Next step after installing mysql is to secure the mysql installation, run the following command from the terminal,

$ sudo secure_mysql_installation

We will now be required to secure the installation of mysql by answering the following questions. To answer the questions positively. Press ‘Y’ or we can press any other key from the keyboard to answer in the negative,

1- Do we need to have a password policy for users accessing the DB. This is done with VALIDATE PASSWORD PLUGIN. If yes, what level of password policy & what should be the strength of password,

2- Remove anonymous users

3- Disallow root login remotely

4- Remove test database & its accessing

5- & lastly, Reload privileges table now.

install mysql on ubuntu

After completing the installation, we can now use the database. To connect to the database, run the following command from the terminal,

$ sudo mysql

Here we need to enter the root password that we created earlier during the installation of mysql. So that’s it, we now end our tutorial on how to install MySQL on Ubuntu. Please feel free to send in any questions or queries using the comment box below.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter | Linkedin

TheLinuxGURUS are thankful for your continued support.

The post How to install MySQL on Ubuntu appeared first on The Linux GURUS.

]]>
https://thelinuxgurus.com/how-to-install-mysql-on-ubuntu/feed/ 0 879
Recommended guide to install POSTGRESQL from Source https://thelinuxgurus.com/recommended-guide-to-install-postgresql-from-source/ https://thelinuxgurus.com/recommended-guide-to-install-postgresql-from-source/#respond Sat, 28 Dec 2019 15:59:22 +0000 https://thelinuxgurus.com/?p=859 PostgreSQL (also called postgres) is a very famous, powerful, open-source object-relational database management system that has been around for almost 30 years. PostgreSQL requires very...

The post Recommended guide to install POSTGRESQL from Source appeared first on The Linux GURUS.

]]>
PostgreSQL (also called postgres) is a very famous, powerful, open-source object-relational database management system that has been around for almost 30 years. PostgreSQL requires very minimum maintained efforts because of its stability. Therefore, if you develop applications based on PostgreSQL, the total cost of ownership is low in comparison with other database management systems.

Recommended Read: Simple guide to install POSTGRESQL on Ubuntu

Also Read: How to setup SSH login without password on Linux systems

In this tutorial, we will learn to install PostgreSQL from source. So let’s start the tutorial,


Pre-requisites

We need to install some packages on servers before we can install PostgreSQL from source,

CentOS/RHEL

# yum groupinstall “Development Tools” -y

# yum install gcc zlib-devel readline-devel systemd-devel -y

Ubuntu

# sudo apt-get install build-essential -y

# sudo apt install gcc zlib1g-dev libreadline6-dev libsystemd-dev -y

Now we can start the process to install PostgreSQL from source.


Install Postgres from source

The first step would be to download the source package for Postgres. Here we will be installing PostgreSQL 11.6,

# wget -O – https://ftp.postgresql.org/pub/source/v11.6/postgresql-11.6.tar.bz2 | tar jxf –

# cd postgresql-11.6

We will now configure postgresql,

# ./configure –with-systemd

Next, run the following commands,

# make

# make install

So these commands will install postgresql from the source. Next step would be to create a user for the postgres installation,

# useradd postgres

# passwd -d postgres

Next, we will also create a data directory for postgres,

# mkdir /usr/local/pgsql/data

# chown postgres /usr/local/pgsql/data

The next step would be to initialize the database. To do that, change the user to postgres & execute the following command,

# su – postgres

$ /usr/local/pgsql/bin/initdb -A trust -D /usr/local/pgsql/data

Once this is done, we can start the database but we need to create a service file to start the database. Revert back to superuser & create a service file,

# vi /etc/systemd/system/postgresql.service

[Unit]

Description=PostgreSQL database server

Documentation=man:postgres(1)

[Service]

Type=notify

User=postgres

ExecStart=/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data

ExecReload=/bin/kill -HUP \\\$MAINPID

KillMode=mixed

KillSignal=SIGINT

TimeoutSec=0

[Install]

WantedBy=multi-user.target

EOF

Save the file & exit. Then run the following command to start the database service,

# systemctl daemon-reload

# systemctl enable postgresql.service

# systemctl start postgresql.service

That’s it, the database is now ready to use.

Note: The Same method can be used to install other postgresql versions as well, the only change would download link for the version you wish to install.

We now end this tutorial on how to install postgresql from source, in our future tutorial we will discuss some other important Postgresql commands. Please feel free to send in any questions or queries using the comment box below.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter | Linkedin

TheLinuxGURUS are thankful for your continued support.

The post Recommended guide to install POSTGRESQL from Source appeared first on The Linux GURUS.

]]>
https://thelinuxgurus.com/recommended-guide-to-install-postgresql-from-source/feed/ 0 859
Simple guide to install POSTGRESQL on Ubuntu https://thelinuxgurus.com/simple-guide-to-install-postgresql-on-ubuntu/ https://thelinuxgurus.com/simple-guide-to-install-postgresql-on-ubuntu/#respond Sat, 28 Dec 2019 15:27:54 +0000 https://thelinuxgurus.com/?p=846 PostgreSQL (also called postgres) is very famous, powerful, open-source object-relational database management system that has been around for almost 30 years. PostgreSQL requires very minimum...

The post Simple guide to install POSTGRESQL on Ubuntu appeared first on The Linux GURUS.

]]>
PostgreSQL (also called postgres) is very famous, powerful, open-source object-relational database management system that has been around for almost 30 years. PostgreSQL requires very minimum maintained efforts because of its stability.  Therefore, if you develop applications based on PostgreSQL, the total cost of ownership is low in comparison with other database management systems.

Recommended Read: Simple guide to install POSTGRESQL on Centos/RHEL

Also Read: How to setup SSH login without password

In this tutorial, we will learn to install PostgreSQL on Ubuntu. So let’s start the tutorial,


Install PostgreSQL on Ubuntu

There are two methods using which we can install Postgresql on Ubuntu systems,

1- Using the default Ubuntu repositories,

2- Using the official PostgreSQL repositories


1- Install Postgresql using default repositories

Ubuntu also maintains Postgresql on official Ubuntu repositories but they might be an older version. So if you don’t have any concern for the Postgres version, then use this method & if you want to install a particular version, then the second method is the way to go.

This method is quite simple, to install PostgreSQL  execute the following command,

$ sudo apt-get install postgresql postgresql-contrib

Once the database has been installed, we can start the database & also enable it to start at boot time,

# sudo systemctl start postgresql

# sudo systemctl enable postgresql

So our database is now up & ready to be used.


2- Install Postgresql using Official Postgresql repositories

Using this method, we will install a stable version 11 of PostgreSQL Install the official repository with the following command,

$ wget –quiet -O – https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add –

Next, execute the following command for add repository contents,

$ RELEASE=$(lsb_release -cs)

$ echo “deb http://apt.postgresql.org/pub/repos/apt/ ${RELEASE}”-pgdg main | sudo tee  /etc/apt/sources.list.d/pgdg.list

Now to install Postgresql on Ubuntu, we will run the following commands,

$ sudo apt update

$ sudo apt -y install postgresql-11

Now we will start the database service & also enable it to start at boot time,

# sudo systemctl start postgresql-11

# sudo systemctl enable postgresql-11


PostgreSQL Configuration


Set the Admin user password

To change the database admin user password, first switch to postgres user,

# su – postgres

Next, execute the following command from the terminal,

$ psql -c “alter user postgres with password ‘NEWPASSWORDhere'”


Create a new user & a new database

To create a new database, run the following command,

$ createuser new_user

$ createdb new_db -O new_user

$ grant all privileges on database new_db to new_user;


Connect to a database

To connect to a database, use the following command,

$ psql -U new_user -h localhost -d new_db


Connecting to the database from a remote system

The above command will only work from localhost but if we want to access the database from a remote host, we need to make some changes as by default we can’t connect to the database from a remote system.

To allow access from remote systems, open the following file,

$ sudo vi /etc/postgresql/11/main/postgresql.conf

& look for the following line,

listen_addresses =

& change to

listen_addresses = ‘*’

Next, we will make changes on another file,

$ sudo  vi /etc/postgresql/11/data/pg_hba.conf

& add the following lines,

# Accept from anywhere

host all all 0.0.0.0/0 md5

# Accept from trusted subnet

host all all 10.10.0.0/16 md5

We need to restart the database server to implement the changes.

# sudo systemctl restart postgresql-11

We now end this tutorial on how to install postgresql on Ubuntu, please also see our tutorial on some of the important Postgresql commands that you should know. Please feel free to send in any questions or queries using the comment box below.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter | Linkedin

TheLinuxGURUS are thankful for your continued support.

The post Simple guide to install POSTGRESQL on Ubuntu appeared first on The Linux GURUS.

]]>
https://thelinuxgurus.com/simple-guide-to-install-postgresql-on-ubuntu/feed/ 0 846
Simple guide to install POSTGRESQL on Centos/RHEL https://thelinuxgurus.com/simple-guide-to-install-postgresql-on-centos-rhel/ https://thelinuxgurus.com/simple-guide-to-install-postgresql-on-centos-rhel/#respond Sat, 28 Dec 2019 15:12:21 +0000 https://thelinuxgurus.com/?p=842 PostgreSQL (also called postgres) is a very famous, powerful, open-source relational database system that has been around for almost 30 years. It has a strong...

The post Simple guide to install POSTGRESQL on Centos/RHEL appeared first on The Linux GURUS.

]]>
PostgreSQL (also called postgres) is a very famous, powerful, open-source relational database system that has been around for almost 30 years. It has a strong reputation for reliability, performance & is feature robust. It is designed to handle a range of workloads, from single machines to data warehouses or Web services with many concurrent users.

Recommended Read: How to setup SSH login without password

In this tutorial, we will learn to install PostgreSQL on CentOS & RHEL systems. So let’s start,


Install PostgreSQL on CentOS/RHEL

There are two methods using which we can install Postgresql on CentOS/RHEL systems,

1- Using the default CentOS repositories,

2- Using the official PostgreSQL repositories


1- Install Postgresql using default repositories

This method is quite simple, we can just run the following command to install postgresql on the server,

# yum install postgresql-server postgresql-contrib

Once the database has been started, we need to initialize the database before we can start using it,

# postgresql-setup initdb

Now we can start the database & also enable it to start at boot time,

# systemctl start postgresql

# systemctl enable postgresql

So our database is now up & ready to be used. The only downside to installing postgresql using this method is that we might not get the latest version as the default Centos or RHEL repositories don’t always maintain the latest versions.

So to install the desired version we must use the second method.


2- Install Postgresql using Official Postgresql repositories

Using this method, we will install a stable version 11 of PostgreSQL Install the official repository with the following command,

# yum install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm

When prompted, press ‘y’ to install. Next, we can run the yum install command to install postgresql,

# yum install postgresql11-server postgresql11

Next, we will initialize the DB,

# /usr/pgsql-11/bin/postgresql-11-setup initdb

Now we will start the database service & also enable it to start at boot time,

# systemctl start postgresql-11

# systemctl enable postgresql-11

PostgreSQL configuration


Set the Admin user password

To change the database admin user password, first switch to postgres user,

# su – postgres

Next, execute the following command from the terminal,

$ psql -c “alter user postgres with password ‘NEWPASSWORDhere'”


Create a new user & a new database

To create a new database, run the following command,

$ createuser new_user

$ createdb new_db -O new_user

$ grant all privileges on database new_db to new_user


Connect to a database

To connect to a database, use the following command,

$ psql -U new_user -h localhost -d new_db


Connecting to the database from a remote system

The above command will only work from the localhost but if we want to access the database from a remote host, we need to make some changes as by default we can’t connect to the database from the remote system.

To allow access from remote systems, open the following file,

# vi /var/lib/pgsql/11/data/postgresql.conf

& look for the following line,

listen_addresses =

& change to

listen_addresses = ‘*’

Next, we will make changes on another file,

# vi /var/lib/pgsql/11/data/pg_hba.conf

& add the following lines,

# Accept from anywhere

host all all 0.0.0.0/0 md5

# Accept from trusted subnet

host all all 10.10.0.0/16 md5

We need to restart the database server to implement the changes.

# systemctl restart postgresql-11

We now end this tutorial, please also see our tutorial on some of the important Postgresql commands that you should know. Please feel free to send in any questions or queries using the comment box below.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter | Linkedin

TheLinuxGURUS are thankful for your continued support.

The post Simple guide to install POSTGRESQL on Centos/RHEL appeared first on The Linux GURUS.

]]>
https://thelinuxgurus.com/simple-guide-to-install-postgresql-on-centos-rhel/feed/ 0 842