Senin, 20 Agustus 2018

How To Install and Configure Redis on Ubuntu 16.04

Introduction

Redis is an in-memory key-value store known for its flexibility, performance, and wide language support. In this guide, we will demonstrate how to install and configure Redis on an Ubuntu 16.04 server.

Prerequisites

To complete this guide, you will need access to an Ubuntu 16.04 server. You will need a non-root user with sudo privileges to perform the administrative functions required for this process. You can learn how to set up an account with these privileges by following our Ubuntu 16.04 initial server setup guide.
When you are ready to begin, log in to your Ubuntu 16.04 server with your sudo user and continue below.

Install the Build and Test Dependencies

In order to get the latest version of Redis, we will be compiling and installing the software from source. Before we download the code, we need to satisfy the build dependencies so that we can compile the software.
To do this, we can install the build-essential meta-package from the Ubuntu repositories. We will also be downloading the tcl package, which we can use to test our binaries.
We can update our local apt package cache and install the dependencies by typing:
  • sudo apt-get update
  • sudo apt-get install build-essential tcl

Download, Compile, and Install Redis

Next, we can begin to build Redis.

Download and Extract the Source Code

Since we won't need to keep the source code that we'll compile long term (we can always re-download it), we will build in the /tmp directory. Let's move there now:
  • cd /tmp
Now, download the latest stable version of Redis. This is always available at a stable download URL:
  • curl -O http://download.redis.io/redis-stable.tar.gz
Unpack the tarball by typing:
  • tar xzvf redis-stable.tar.gz
Move into the Redis source directory structure that was just extracted:
  • cd redis-stable

Build and Install Redis

Now, we can compile the Redis binaries by typing:
  • make
After the binaries are compiled, run the test suite to make sure everything was built correctly. You can do this by typing:
  • make test
This will typically take a few minutes to run. Once it is complete, you can install the binaries onto the system by typing:
  • sudo make install

Configure Redis

Now that Redis is installed, we can begin to configure it.
To start off, we need to create a configuration directory. We will use the conventional /etc/redis directory, which can be created by typing:
  • sudo mkdir /etc/redis
Now, copy over the sample Redis configuration file included in the Redis source archive:
  • sudo cp /tmp/redis-stable/redis.conf /etc/redis
Next, we can open the file to adjust a few items in the configuration:
  • sudo nano /etc/redis/redis.conf
In the file, find the supervised directive. Currently, this is set to no. Since we are running an operating system that uses the systemd init system, we can change this to systemd:
/etc/redis/redis.conf
. . .

# If you run Redis from upstart or systemd, Redis can interact with your
# supervision tree. Options:
#   supervised no      - no supervision interaction
#   supervised upstart - signal upstart by putting Redis into SIGSTOP mode
#   supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET
#   supervised auto    - detect upstart or systemd method based on
#                        UPSTART_JOB or NOTIFY_SOCKET environment variables
# Note: these supervision methods only signal "process is ready."
#       They do not enable continuous liveness pings back to your supervisor.
supervised systemd

. . .
Next, find the dir directory. This option specifies the directory that Redis will use to dump persistent data. We need to pick a location that Redis will have write permission and that isn't viewable by normal users.
We will use the /var/lib/redis directory for this, which we will create in a moment:
/etc/redis/redis.conf
. . .

# The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
#
# The Append Only File will also be created inside this directory.
#
# Note that you must specify a directory here, not a file name.
dir /var/lib/redis

. . .
Save and close the file when you are finished.

Create a Redis systemd Unit File

Next, we can create a systemd unit file so that the init system can manage the Redis process.
Create and open the /etc/systemd/system/redis.service file to get started:
  • sudo nano /etc/systemd/system/redis.service
Inside, we can begin the [Unit] section by adding a description and defining a requirement that networking be available before starting this service:
/etc/systemd/system/redis.service
[Unit]
Description=Redis In-Memory Data Store
After=network.target
In the [Service] section, we need to specify the service's behavior. For security purposes, we should not run our service as root. We should use a dedicated user and group, which we will call redis for simplicity. We will create these momentarily.
To start the service, we just need to call the redis-server binary, pointed at our configuration. To stop it, we can use the Redis shutdown command, which can be executed with the redis-cli binary. Also, since we want Redis to recover from failures when possible, we will set the Restart directive to "always":
/etc/systemd/system/redis.service
[Unit]
Description=Redis In-Memory Data Store
After=network.target

[Service]
User=redis
Group=redis
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
ExecStop=/usr/local/bin/redis-cli shutdown
Restart=always
Finally, in the [Install] section, we can define the systemd target that the service should attach to if enabled (configured to start at boot):
/etc/systemd/system/redis.service
[Unit]
Description=Redis In-Memory Data Store
After=network.target

[Service]
User=redis
Group=redis
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
ExecStop=/usr/local/bin/redis-cli shutdown
Restart=always

[Install]
WantedBy=multi-user.target
Save and close the file when you are finished.

Create the Redis User, Group and Directories

Now, we just have to create the user, group, and directory that we referenced in the previous two files.
Begin by creating the redis user and group. This can be done in a single command by typing:
  • sudo adduser --system --group --no-create-home redis
Now, we can create the /var/lib/redis directory by typing:
  • sudo mkdir /var/lib/redis
We should give the redis user and group ownership over this directory:
  • sudo chown redis:redis /var/lib/redis
Adjust the permissions so that regular users cannot access this location:
  • sudo chmod 770 /var/lib/redis

Start and Test Redis

Now, we are ready to start the Redis server.

Start the Redis Service

Start up the systemd service by typing:
  • sudo systemctl start redis
Check that the service had no errors by running:
  • sudo systemctl status redis
You should see something that looks like this:
Output
● redis.service - Redis Server Loaded: loaded (/etc/systemd/system/redis.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2016-05-11 14:38:08 EDT; 1min 43s ago Process: 3115 ExecStop=/usr/local/bin/redis-cli shutdown (code=exited, status=0/SUCCESS) Main PID: 3124 (redis-server) Tasks: 3 (limit: 512) Memory: 864.0K CPU: 179ms CGroup: /system.slice/redis.service └─3124 /usr/local/bin/redis-server 127.0.0.1:6379 . . .

Test the Redis Instance Functionality

To test that your service is functioning correctly, connect to the Redis server with the command-line client:
  • redis-cli
In the prompt that follows, test connectivity by typing:
  • ping
You should see:
Output
PONG
Check that you can set keys by typing:
  • set test "It's working!"
Output
OK
Now, retrieve the value by typing:
  • get test
You should be able to retrieve the value we stored:
Output
"It's working!"
Exit the Redis prompt to get back to the shell:
  • exit
As a final test, let's restart the Redis instance:
  • sudo systemctl restart redis
Now, connect with the client again and confirm that your test value is still available:
  • redis-cli
  • get test
The value of your key should still be accessible:
Output
"It's working!"
Back out into the shell again when you are finished:
  • exit

Enable Redis to Start at Boot

If all of your tests worked, and you would like to start Redis automatically when your server boots, you can enable the systemd service.
To do so, type:
  • sudo systemctl enable redis
Output
Created symlink from /etc/systemd/system/multi-user.target.wants/redis.service to /etc/systemd/system/redis.service.

Conclusion

You should now have a Redis instance installed and configured on your Ubuntu 16.04 server. To learn more about how to secure your Redis installation, take a look at our How To Secure Your Redis Installation on Ubuntu 14.04 (from step 3 onward). Although it was written with Ubuntu 14.04 in mind, it should mostly work for 16.04 as well.
Share:

How to Install Apache Maven on Ubuntu 16.04


Introduction

Apache Maven is a free and open source project management tool used for Java projects. You can easily manage a project's build, reporting, and documentation from a central piece of information using Apache Maven. Apache Maven provides a complete framework to automate the project's build infrastructure.
In this tutorial, you will learn how to install Apache Maven on Ubuntu 16.04.

Prerequisites

  • A newly deployed Vultr Ubuntu 16.04 server.
  • A non-root user with sudo privileges created on your server.

Step 1: Update your server

First, update your system to the latest stable version by running the following command:
sudo apt-get update -y
sudo apt-get upgrade -y

Step 2: Install Java

Apache Maven requires Java to be installed on your server. By default, Java is not available in Ubuntu's repository. Add the Oracle Java PPA to Apt with the following command:
sudo add-apt-repository ppa:webupd8team/java
Next, update your Apt package database with the following command:
sudo apt-get update -y
Install the latest stable version of Oracle Java 8.
sudo apt-get install oracle-java8-installer
Verify the Java version by running the following command:
java -version
Output:
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

Step 3: Install Apache Maven

You can download the latest stable version of Apache Maven from its official website, otherwise you can download it directly with the following command:
cd /opt/
wget http://www-eu.apache.org/dist/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz
Once the download has completed, extract the downloaded archive.
sudo tar -xvzf apache-maven-3.3.9-bin.tar.gz
Next, rename the extracted directory.
sudo mv apache-maven-3.3.9 maven 

Step 4: Setup environment variables

Next, you will need to setup the environment variables such as M2_HOME, M2, MAVEN_OPTS, and PATH. You can do this by creating a mavenenv.sh file inside of the /etc/profile.d/ directory.
sudo nano /etc/profile.d/mavenenv.sh
Add the following lines:
export M2_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}
Save and close the file, update its permissions, then load the environment variables with the following command:
sudo chmod +x /etc/profile.d/mavenenv.sh
sudo source /etc/profile.d/mavenenv.sh

Step 5: Verify installation

Once everything has been successfully configured, check the version of the Apache Maven.
mvn --version
You should see the following output:
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T22:11:47+05:30)
Maven home: /opt/maven
Java version: 1.8.0_101, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-oracle/jre
Default locale: en_US, platform encoding: ANSI_X3.4-1968
OS name: "linux", version: "3.13.0-32-generic", arch: "amd64", family: "unix"
Congratulations! You have successfully installed Apache Maven on your Ubuntu 16.04 server.
Share:

How To Install Java with Apt-Get on Ubuntu 16.04

Introduction

Java and the JVM (Java's virtual machine) are widely used and required for many kinds of software. This article will guide you through the process of installing and managing different versions of Java using apt-get.

Prerequisites

To follow this tutorial, you will need:

Installing the Default JRE/JDK

The easiest option for installing Java is using the version packaged with Ubuntu. Specifically, this will install OpenJDK 8, the latest and recommended version.
First, update the package index.
  • sudo apt-get update
Next, install Java. Specifically, this command will install the Java Runtime Environment (JRE).
  • sudo apt-get install default-jre
There is another default Java installation called the JDK (Java Development Kit). The JDK is usually only needed if you are going to compile Java programs or if the software that will use Java specifically requires it.
The JDK does contain the JRE, so there are no disadvantages if you install the JDK instead of the JRE, except for the larger file size.
You can install the JDK with the following command:
  • sudo apt-get install default-jdk

Installing the Oracle JDK

If you want to install the Oracle JDK, which is the official version distributed by Oracle, you will need to follow a few more steps.
First, add Oracle's PPA, then update your package repository.
  • sudo add-apt-repository ppa:webupd8team/java
  • sudo apt-get update
Then, depending on the version you want to install, execute one of the following commands:

Oracle JDK 8

This is the latest stable version of Java at time of writing, and the recommended version to install. You can do so using the following command:
  • sudo apt-get install oracle-java8-installer

Oracle JDK 9

This is a developer preview and the general release is scheduled for March 2017. It's not recommended that you use this version because there may still be security issues and bugs. There is more information about Java 9 on the official JDK 9 website.
To install JDK 9, use the following command:
  • sudo apt-get install oracle-java9-installer

Managing Java

There can be multiple Java installations on one server. You can configure which version is the default for use in the command line by using update-alternatives, which manages which symbolic links are used for different commands.
  • sudo update-alternatives --config java
The output will look something like the following. In this case, this is what the output will look like with all Java versions mentioned above installed.
Output
There are 5 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      auto mode
  1            /usr/lib/jvm/java-6-oracle/jre/bin/java          1         manual mode
  2            /usr/lib/jvm/java-7-oracle/jre/bin/java          2         manual mode
  3            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      manual mode
  4            /usr/lib/jvm/java-8-oracle/jre/bin/java          3         manual mode
  5            /usr/lib/jvm/java-9-oracle/bin/java              4         manual mode

Press <enter> to keep the current choice[*], or type selection number:
You can now choose the number to use as a default. This can also be done for other Java commands, such as the compiler (javac), the documentation generator (javadoc), the JAR signing tool (jarsigner), and more. You can use the following command, filling in the command you want to customize.
  • sudo update-alternatives --config command

Setting the JAVA_HOME Environment Variable

Many programs, such as Java servers, use the JAVA_HOME environment variable to determine the Java installation location. To set this environment variable, we will first need to find out where Java is installed. You can do this by executing the same command as in the previous section:
  • sudo update-alternatives --config java
Copy the path from your preferred installation and then open /etc/environment using nano or your favorite text editor.
  • sudo nano /etc/environment
At the end of this file, add the following line, making sure to replace the highlighted path with your own copied path.
/etc/environment
JAVA_HOME="/usr/lib/jvm/java-8-oracle"
Save and exit the file, and reload it.
  • source /etc/environment
You can now test whether the environment variable has been set by executing the following command:
  • echo $JAVA_HOME
This will return the path you just set.

Conclusion

You have now installed Java and know how to manage different versions of it. You can now install software which runs on Java, such as Tomcat, Jetty, Glassfish, Cassandra, or Jenkins.
Share:

Rabu, 27 Juni 2018

Cloud hosting vs VPS hosting

Pada umumnya environment dari VPS sama persis dengan Cloud. Sebuah cloud server bisa disebut sebagai VPS tapi sebuah VPS tidak bisa disebut sebagai cloud server.Dibawah berikut merupakan kunci perbedaan antara sebuah cloud hosting dan VPS atau VDS hosting.
1. Infrastructure
Dalam VPS hosting, sebuah dedicated server (misalkan sebuah dedicated server dengan 64 GB RAM) dipartisi menjadi beberapa server. Semua partisi ini divirtualisasikan lebih lanjut dan masing-masing berfungsi sebagai dedicated server, maka daro itu disebut Virtual dedicated server atau VDS atau VPS.
Tapi dalam sebuah Cloud hosting, disewakan sebagian kecil dari sebuah jaringan besar mesin yang terhubung bersama. (red:public cloud) Pengaturan besar mesin yang menawarkan resources yang terhubung bersama yang selanjutnya disewakan kepada klien. Anda selalu dapat meningkatkan resources nya sesuai kebutuhan dan ini dapat dilakukan dalam sekali klik dan beberapa menit
2. Availability
Pada VPS, jika sebuah mesin atau bagian dari mesin gagal berfungsi, VPS anda akan mati dan menyebabkan downtime sampai masalah tersebut diperbaiki, akan tetapi dalam kasus Cloud server, Jika terjadi kegagalan dalam hal apapun, sistem akan dialihkan ke fisik(mesin) lain yang memiliki resource sehingga seminimum mungkin terjadi downtime.
3. Payment Model
Pada Cloud, segala sesuatu sangat cepat. Setiap slot server tersedia dan selalu siap dijalani dalam hitungan detik, akan tetapi pada VPS, dibutuhkan waktu untuk memvirtualisasikan sebuah dedicated server dan membagikan irisan VPS kepada klien. Itulah alasan Cloud menggunakan resources yang optimal karena setiap orang dapat menempati setiap bagian resources hanya dengan melakukan pembayaran. Tapi pada VPS, Anda tidak dapat memastikan kapan semua slot akan dijual. Resources anda mungkin tidak dimanfaatkan dengan baik jika anda hanya menghosting satu klien di server induk.
4. Resource distribution
Dalam environment Cloud, Anda benar-benar terpisah dari yang lain. Anda akan mendapatkan dedicated resources dari apa yang Anda benar-benar inginkan. Tapi pada sebuah VPS, anda mendapatkan sebuah virtual environment dengan porsi disk space & bandwidth tertentu, namun CPU & memori dari mesin induk sama-sama didistribusikan di antara semua potongan VPSPerusahaan VPS biasanya menawarkan alokasi sumber daya minimum yang dijamin 24jam
Misalnya, hanya karena paket VPS mengklaim untuk menawarkan kinerja CPU 1 GHz dan memori 512 MBtidak berarti bahwa baik memori atau alokasi CPU tidak dibagi menjadi beberapa irisan, juga pada sebuah cloud, klien benar-benar terisolasi dari file-file dari klien lainnya, dimana ini membuat lebih aman daripada VPS hosting.
5. Choice of Operating system
Tergantung pada metode virtualisasi yang digunakan, sebuah VPS dapat menawarkan Anda hanya satu sistem operasi. Tapi pada sebuah cloud, Anda mendapatkan kebebasan untuk memilih sistem operasi apa pun yang Anda inginkanAnda dapat menginstal atau mengganti sistem operasi apa pun dari berbagai OS yang tersedia.
Cloud Hosting vs VPS Hosting
Perbandingan tabular berikut antara Cloud hosting and VPS hosting akan menyajikan gambaran yang lebih jelas dari dua model hosting ini
Which is better?
Ada beberapa parameter yang perlu dipertimbangkan saat memilih mana yang terbaikJika Anda memilih Private Cloud kemudian VPS akan lebih murah untuk Anda. Namun dalam kasus ini, Anda akan mendapatkan fitur terbatas dari VPS dan risiko keamanan karena private cloud jauh lebih aman.
Dan juga jika Anda memilih untuk meng-host file Anda di Public Cloud (DigitalOcean, Linode dll), itu relatif lebih murah tetapi kurang aman daripada private cloud. Tapi dibandingkan dengan VPS, hosting Cloud Pubic memiliki keunggulan dan itulah mengapa mereka populer.
Di Cloud hosting, Anda mendapatkan harga yang relatif lebih murah, environment yang aman, dan kebebasan dalam mengatur resource.

Below is a quick summation of what I've said.



Jika Anda mencari host yang bagus, DigitalOcean adalah perusahaan hosting Cloud yang sempurna, Anda dapat mencoba tautan afiliasi saya untuk mendapatkan kredit gratis $ 10
Sumber : https://www.quora.com/What-is-the-difference-between-cloud-hosting-and-VPS-hosting/answer/Amir-14


Share: