Web Application Environment Installation

I. Basic concepts

Package Management on Operating Systems

Debian/Ubuntu Package Management

Advanced Packaging Tool – APT

apt-get is a command line tool for interacting with the Advanced Package Tool (APT) library (a package management system for Linux distributions). It allows you to search for, install, manage, update, and remove software.

Configuration of the APT system repositories is stored in the /etc/apt/sources.list file and the /etc/apt/sources.list.d directory. You can add additional repositories in a separate file in the /etc/apt/sources.list.d directory, for example, redis.list, docker.list.

dpkg

dpkg is a package manager for Debian-based systems. It can install, remove, and build packages, but unlike other package management systems, it cannot automatically download and install packages – or their dependencies. APT and Aptitude are newer, and layer additional features on top of dpkg.

# install
sudo dpkg -i package_file.deb
# uninstall
sudo apt-get remove package_name

CentOS/RHEL Package Management

Yellow Dog Updater, Modified (YUM)

YUM is the primary package management tool for installing, updating, removing, and managing software packages in Red Hat Enterprise Linux. YUM performs dependency resolution when installing, updating, and removing software packages. YUM can manage packages from installed repositories in the system or from .rpm packages. The main configuration file for YUM is at /etc/yum.conf, and all the repos are at /etc/yum.repos.d.

# add repos config to /etc/yum.repos.d
...
# clear repo cache
yum clean all
# create repo cache
yum makecache
# search package
yum search {package_name}

# upgrade package
yum update

# install package
yum install {package_name}

# uninstall package
yum remove {package_name}

RPM (RPM Package Manager)

RPM is a popular package management tool in Red Hat Enterprise Linux-based distros. Using RPM, you can install, uninstall, and query individual software packages. Still, it cannot manage dependency resolution like YUM. RPM does provide you useful output, including a list of required packages. An RPM package consists of an archive of files and metadata. Metadata includes helper scripts, file attributes, and information about packages.

# install
sudo rpm -i package_file.rpm
sudo rpm --install package_file.rpm
# reinstall
sudo rpm --reinstall package_file.rpm
# uninstall
sudo rpm -e package_name
sudo rpm --erase package_name

Windows Package Management

Chocolatey

winget

Microsoft Store

MacOS Package Management

brew

Mac App Store

Service Manager

Systemd

II. Software Installation

JDK/JRE

Headless version

Headless is the same version than the latter without the support of keyboard, mouse and display systems. Hence it has less dependencies and it makes it more suitable for server application.

Debian/Ubuntu/Deepin

Install openjdk from Official APT Repositories

Supported Operating Systems

  • Ubuntu/Debian
  • Deepin

Installing

# insall
sudo apt-get install openjdk-8-jdk
# verify. If the installation was successful, you can see the Java version.
java -version

Installing Options

  • openjdk-8/11/17-jdk
  • openjdk-8/11/17-jdk-headless
  • openjdk-8/11/17-jre
  • openjdk-8/11/17-jre-headless

Maven

CentOS/RHEL

Install from the EPEL YUM repository

# Add the EPEL repository, and update YUM to confirm your change
sudo yum install epel-release
sudo yum update
# install
sudo yum install maven -y
# verify
mvn -v

Add Aliyun Mirror. Add the following lines to the tag <mirrors> in the /etc/maven/settings.xml

<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>

Python

Debian/Ubuntu

Install from the official APT repository

# Update the environment
sudo apt update
# install
sudo apt install python3 -y
# verify
python3 -V

CentOS/RHEL

Install from the Official YUM repository

# Update the environment. Make sure that we are working with the most up to date environment possible in terms of our packages
sudo yum update -y
# install
sudo yum install -y python3
# verify
python3 -V

Node.js

CentOS/RHEL

Install from the EPEL YUM repository

# Add the EPEL repository, and update YUM to confirm your change
sudo yum install epel-release
sudo yum update
# install
sudo yum install nodejs
# verify
node --version

Redis

Linux

Install from Snapcraft

The Snapcraft store provides Redis packages that can be installed on platforms that support snap. Snap is supported and available on most major Linux distributions.

sudo snap install redis

If your Linux does not currently have snap installed, install it using the instructions described in Installing snapd.

Debian/Ubuntu/Deepin

Install from the official APT repositories

sudo apt-get update
sudo apt-get install redis-server

Update config

sudo vim /etc/redis/redis.conf

Uncomment the following line

# supervised auto

to

supervised auto

Enable and restart Redis service

sudo systemctl enable redis.service
sudo systemctl restart redis.service

Verify

systemctl status redis
redis-cli ping

Install from the Redis APT repository

Most major Linux distributions provide packages for Redis.

# prerequisites
sudo apt install lsb-release curl gpg
# add the repository to the apt index, update it. and then install redis. 

curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg

echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list

sudo apt-get update
sudo apt-get install redis

# verify
systemctl status redis
redis-cli ping

CentOS/RHEL

Install from the EPEL YUM repository

  1. Add the EPEL repository, and update YUM to confirm your change:

    sudo yum install epel-release
    sudo yum update
  2. Install Redis:

    sudo yum install redis
  3. Start Redis:

    sudo systemctl start redis

    Optional: To automatically start Redis on boot:

    sudo systemctl enable redis

Verify the Installation

Verify that Redis is running with redis-cli:

redis-cli ping

If Redis is running, it will return:

PONG

Windows

Redis is not officially supported on Windows.

Install from Source

Supported Operating Systems

  • All Linux distros (distributions)
  • MacOS

You can compile and install Redis from source on variety of platforms and operating systems including Linux and macOS. Redis has no dependencies other than a C compiler and libc.

# Download source files
wget https://download.redis.io/redis-stable.tar.gz
# Compiling
tar -xzvf redis-stable.tar.gz
cd redis-stable
make
# make sure the build is correct
make test

If the compile succeeds, you’ll find several Redis binaries in the src directory, including:

  • redis-server: the Redis Server itself
  • redis-cli is the command line interface utility to talk with Redis.

Starting and stopping Redis

cd redis-stable
# starting redis server
./src/redis-server &
# starting redis server with config
./src/redis-server redis.conf &
# stopping redis server
ps -ef | grep redis-server | awk '{print $2}' | head -1 | xargs kill -9
# connect to redis
./src/redis-cli
# auth
127.0.0.1:6379> auth YOUR_PASSWORD

update password in redis.conf

# requirepass foobared

to

requirepass YOUR_STRONG_PASSWORD

Manage Redis service using systemd

Create the /etc/systemd/system/redis.service file, and add the following line to the file

[Unit]
Description=Redis
After=network.target

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

[Install]
WantedBy=multi-user.target

copy the files

cd /path/to/redis/source/dir
sudo mkdir /etc/redis
sudo cp redis.conf /etc/redis/
sudo cp src/redis-server /usr/local/bin/
sudo cp src/redis-cli /usr/local/bin/

Edit config

sudo vim /etc/redis/redis.conf

Uncomment the following line

# supervised auto

to

supervised auto

Enable and start Redis service

systemctl enable redis
systemctl start redis
systemctl status redis

To verify Redis is up and running, run the following command:

redis-cli PING

MySQL

Linux

Install from binary distributions

Aim: Creating a MySQL service starts automatically when the computer starts up.

Download generic Unix/Linux binary package

Linux - Generic (glibc 2.12) (x86, 64-bit), Compressed TAR Archive. For example: mysql-5.7.44-linux-glibc2.12-x86_64.tar.gz

Installing

# Install dependency `libaio` library
yum search libaio
yum install libaio

# Create a mysql User and Group
groupadd mysql
useradd -r -g mysql -s /bin/false mysql

# Obtain and Unpack the Distribution
cd /usr/local
tar zxvf /path/to/mysql-VERSION-OS.tar.gz
# This enables you to refer more easily to it as /usr/local/mysql.
ln -s full-path-to-mysql-VERSION-OS mysql
# add the `/usr/local/mysql/bin` directory to your `PATH` variable
cp /etc/profile /etc/profile.bak.$(date '+%Y-%m-%d_%H-%M-%S')
echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile
cat /etc/profile
source /etc/profile

# Creating a Safe Directory For Import and Export Operations
cd /usr/local/mysql
mkdir mysql-files
chown mysql:mysql mysql-files
chmod 750 mysql-files

# Initialize the data directory.
bin/mysqld --initialize --user=mysql # A temporary password is generated for root@localhost: Trbgylojs1!w
bin/mysql_ssl_rsa_setup

# Start mysql server
bin/mysqld_safe --user=mysql &

# Next command is optional
cp support-files/mysql.server /etc/init.d/mysql.server

Note: This procedure assumes that you have root (administrator) access to your system. Alternatively, you can prefix each command using the sudo (Linux) or pfexec (Solaris) command.

Managing MySQL Server with systemd


Create a user for remote access

  1. Enable MySQL server port in the firewall

If the firewall management on Linux uses ufw, you can run the following command to enable MySQL server port.

ufw allow 3306/tcp
  1. Update bind-address in /etc/my.cnf

Change 127.0.0.1 to Local IP like 192.168.1.100

bind-address=192.168.1.100
  1. Create a MySQL user for remote login
mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;
mysql> CREATE USER 'root'@'%' IDENTIFIED BY 'password';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;
  1. Verify

Connect the remote MySQL server from your local computer

# testing the port is open
$ telnet {server_ip} 3306
# test MySQL connection
$ mysql -h {server_ip} -u root -p
Enter password:

Errors

Error: mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory

When you run mysql -u root -p.

Solutions

# centos
yum install ncurses-compat-libs

Error: ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

To set up your password for the first time:

mysql> SET PASSWORD = PASSWORD('new password');

Windows

Docker

docker run --name={mysql_container_name} -d -p {exposed_port}:3306 \
-e MYSQL_ROOT_HOST='%' -e MYSQL_ROOT_PASSWORD='{your_password}' \
--restart unless-stopped \
-v mysql_data:/var/lib/mysql \
mysql/mysql-server:{version}

Elasticsearch

Kibana

CentOS/RHEL

Install from the elastic YUM repository

Download and install the public signing key:

rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch

Create a file called kibana.repo in the /etc/yum.repos.d/ directory for RedHat based distributions, or in the /etc/zypp/repos.d/ directory for OpenSuSE based distributions, containing:

[kibana-8.x]
name=Kibana repository for 8.x packages
baseurl=https://artifacts.elastic.co/packages/8.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md

You can now install Kibana with one of the following commands:

# older Red Hat based distributions
sudo yum install kibana
# Fedora and other newer Red Hat distributions
sudo dnf install kibana
# OpenSUSE based distributions
sudo zypper install kibana

Install by downloading RPM file

Downloading the Kibana RPM file

wget https://artifacts.elastic.co/downloads/kibana/kibana-8.8.2-x86_64.rpm
wget https://artifacts.elastic.co/downloads/kibana/kibana-8.8.2-x86_64.rpm.sha512
shasum -a 512 -c kibana-8.8.2-x86_64.rpm.sha512
sudo rpm --install kibana-8.8.2-x86_64.rpm

Start Elasticsearch and generate an enrollment token for Kibana

When you start Elasticsearch for the first time, the following security configuration occurs automatically:

  • Authentication and authorization are enabled, and a password is generated for the elastic built-in superuser.
  • Certificates and keys for TLS are generated for the transport and HTTP layer, and TLS is enabled and configured with these keys and certificates.

The password and certificate and keys are output to your terminal.

Run Kibana with systemd

To configure Kibana to start automatically when the system starts, run the following commands:

sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable kibana.service

Kibana can be started and stopped as follows:

sudo systemctl start kibana.service
sudo systemctl stop kibana.service

Log information can be accessed via journalctl -u kibana.service.

Configure Kibana via the config file

Kibana loads its configuration from the /etc/kibana/kibana.yml file by default. The format of this config file is explained in Configuring Kibana.

Nginx

Apache Tomcat

Docker

Debian/Ubuntu/Deepin

Install from the Docker APT repository

Set up the repository

  1. Update the apt package index and install packages to allow apt to use a repository over HTTPS
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
  1. Add Docker’s official GPG key:
sudo install -m 0755 -d /etc/apt/keyrings

# 中科大源 docker - debian/deepin
curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
# Official docker - debian
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
# Official docker - ubuntu
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

sudo chmod a+r /etc/apt/keyrings/docker.gpg
  1. Use the following command to set up the repository
# 中科大源 docker - debian/deepin
echo 'deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.ustc.edu.cn/docker-ce/linux/debian buster stable' | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Official docker - debian
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Official docker - ubuntu
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Install Docker Engine

  1. Update the apt package index:
sudo apt-get update
  1. Install Docker Engine, containerd, and Docker Compose.
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
  1. Verify that the Docker Engine installation is successful by running the hello-world image
sudo docker run hello-world

View Docker version and status

docker version
systemctl status docker

References

Linux package management with YUM and RPM

Package management - Ubuntu

systemd.unit — Unit configuration

Installing Redis

MySQL