Category Archives: Linux

Discover DevOps roles and learn Linux from basics to advanced at DevOpsRoles.com. Detailed guides and in-depth articles to master Linux for DevOps careers.

Step by step Install JDK on CentOS

In this tutorial, How to Install JDK on CentOS step by step. How to switch between JDK 7 and JDK 8?

Precondition

  1. Open the terminal and log in as root or you use sudo before each command with another user.
  2. Working on a Linux system operating: Centos/REHL

Search for JDK on CentOS

You use the command below to search the packages

$ yum search openjdk

The output terminal console as below

Install JDK 1.8

$ sudo yum install java-1.8.0-openjdk

Confirmation is complete when the installed Java version is displayed.

$ java --version
# Output
# openjdk version "1.8.0_212"
# OpenJDK Runtime Environment (build 1.8.0_212-b04)
# OpenJDK 64-Bit Server VM (build 25.212-b04, mixed mode)

How to switch JDK 7 to JDK 8

Use the command “sudo alternatives –config java” to switch to JDK.

How to switch JDK 8 to JDK 7

Conclusion

Through the article,  How to Install JDK on CentOS step by step. How to switch between JDK 7 and JDK 8? as above. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Install Grafana on Centos 7

Grafana is tool monitoring and Data visualization with support InfluxDB, Graphite, Prometheus, Elasticsearch, and many more databases.

In this tutorial, How to install Grafana on Linux. Link download manually here

Install Grafana on Centos 7

Add Grafana yum repository

[vagrant@DevopsRoles ~]$ cat <<EOF | sudo tee /etc/yum.repos.d/grafana.repo
[grafana]
name=grafana
baseurl=https://packages.grafana.com/oss/rpm
repo_gpgcheck=1
enabled=1
gpgcheck=1
gpgkey=https://packages.grafana.com/gpg.key
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
EOF

Update cache index as below

[vagrant@DevopsRoles ~]$ sudo yum makecache

Install Grafana

[vagrant@DevopsRoles ~]$ sudo yum -y install grafana

Start Grafana service

[vagrant@DevopsRoles ~]$ sudo systemctl enable --now grafana-server.service

The default port of Grafana used is 3000

Grafana write logs to /var/log/grafana directory and its SQLite database is located under /var/lib/grafana/grafana.db

Open firewall port for Grafana

[vagrant@DevopsRoles ~]$ sudo firewall-cmd --add-port=3000/tcp --permanent
[vagrant@DevopsRoles ~]$ sudo firewall-cmd --reload

Access Grafana Dashboard on Centos 7

Grafana web dashboard on http://[Server IP|Hostname]:3000

The default login as below

username: admin
Password: admin

The change password first login as below

You have Installed Grafana on Centos 7. Thank you for reading the DevopsRoles page!

Install nslookup on Linux

Introduction

In this tutorial, How to install on Linux. is part of the bind-utils package. The package bind-utils is not yet installed on Linux, then you type command not found on Linux.

To install nslookup on Linux, you need to install the dnsutils package, which contains the nslookup utility. The process for installing the package can vary depending on the Linux distribution you are using. Here are the commands for some popular distributions:

How to Install nslookup on Linux

Install nslookup for Centos

[vagrant@DevopsRoles ~]$ sudo yum install bind-utils

Install nslookup for Ubuntu

Use apt-cache to search the package for nslookup command.

[vagrant@DevopsRoles ~]$ apt-cache search nslookup

The result found 2 packages that are related to nslookup.

dnsutils - Clients provided with BIND
libnet-nslookup-perl - simple DNS lookup module for perl

so install nslookup

[vagrant@DevopsRoles ~]$ sudo apt-get install dnsutils

Once the installation is complete, you can use nslookup from the command line.

[vagrant@DevopsRoles ~]$ nslookup x.x.x.x

Conclusion

In this guide, we have covered how to install and use the nslookup command on Linux, specifically for CentOS and Ubuntu. Whether you’re troubleshooting DNS issues or simply querying domain name records, nslookup is a powerful and essential tool for network administrators and IT professionals.

By following the simple installation steps, you can quickly enable nslookup on your system and start resolving domain names with ease. If you encounter any issues, ensure that your system’s package manager is up to date and that you have the necessary permissions to install packages.

We hope this guide has been helpful! If you have any questions or need further assistance, feel free to leave a comment or check out our other Linux tutorials. Thank you for reading the DevopsRoles page!

Install Prometheus on RHEL / CentOS 7

In this tutorial, How to install Prometheus on RHEL / CentOS 7. Prometheus is an open-source applications and microservices. Prometheus releases Github

Install Prometheus

Create user and group Prometheus system

sudo groupadd --system prometheus
sudo useradd -s /sbin/nologin --system -g prometheus prometheus

Create the data directory for Prometheus

sudo mkdir /var/lib/prometheus

Prometheus creates the configuration directory

sudo mkdir -p -m 775 /etc/prometheus/{rules,rules.d,files_sd}

Download and extract Prometheus

cd /tmp
export RELEASE=2.8.1
wget https://github.com/prometheus/prometheus/releases/download/v${RELEASE}/prometheus-${RELEASE}.linux-amd64.tar.gz
tar xvf prometheus-${RELEASE}.linux-amd64.tar.gz
cd prometheus-${RELEASE}.linux-amd64/

Copy Prometheus binary, consoles and console_libraries

sudo cp prometheus promtool /usr/local/bin/
sudo cp -r consoles/ console_libraries/ /etc/prometheus/

Create a Prometheus configuration file.

sudo vi /etc/prometheus/prometheus.yml

The content as below

# Global config
global: 
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.  
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.  
  scrape_timeout: 15s  # scrape_timeout is set to the global default (10s).

# A scrape configuration containing exactly one endpoint to scrape:# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
    - targets: ['localhost:9090']

Create a Prometheus systemd service unit file.

sudo vi /etc/systemd/system/prometheus.service

The content Prometheus systemd service as below

[Unit]
Description=Prometheus
Documentation=https://prometheus.io/docs/introduction/overview/
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
Environment="GOMAXPROCS=2"
User=prometheus
Group=prometheus
ExecReload=/bin/kill -HUP $MAINPID
ExecStart=/usr/local/bin/prometheus \
  --config.file=/etc/prometheus/prometheus.yml \
  --storage.tsdb.path=/var/lib/prometheus \
  --web.console.templates=/etc/prometheus/consoles \
  --web.console.libraries=/etc/prometheus/console_libraries \
  --web.listen-address=0.0.0.0:9090 \
  --web.external-url=

SyslogIdentifier=prometheus
Restart=always

[Install]
WantedBy=multi-user.target

Note: You remember to edit the line: Environment=”GOMAXPROCS=2 with replacing 2 is the number of vcpus on the server.

Clean install

rm -rf prometheus-${RELEASE}.linux-amd64.tar.gz
rm -rf prometheus-${RELEASE}.linux-amd64/

Change directory permission.

sudo chown -R prometheus:prometheus /etc/prometheus
sudo chown -R prometheus:prometheus /var/lib/prometheus/

Reload systemd daemon and start the Prometheus service

sudo systemctl daemon-reload
sudo systemctl start prometheus

Configure firewalld

sudo firewall-cmd --permanent --add-rich-rule 'rule family="ipv4" \
source address="192.168.10.0/24" port protocol="tcp" port="9090" accept'
sudo firewall-cmd --reload

Test access Prometheus service on port 9090

$ telnet localhost 9090

Access Prometheus Web dashboard on server

You have to install Prometheus on your system! You got it. Thank you for reading the DevopsRoles page!

Install InfluxDB on RHEL / Centos 7

In this tutorial, How to install InfluxDB on RHEL / Centos 7. InfluxDB is an open-source time-series database. It is High availability storage and optimized for fast and metrics analysis.

To install InfluxDB on RHEL/CentOS 7, you can follow the steps below:

Install InfluxDB on RHEL / Centos 7

First, You add InfluxDB repository to your system using the command below

[vagrant@DevopsRoles ~]$ sudo vi  /etc/yum.repos.d/influxdb.repo

Add the content below:

[influxdb]
name = InfluxDB Repository
baseurl = https://repos.influxdata.com/rhel/7/x86_64/stable/
enabled = 1
gpgcheck = 1
gpgkey = https://repos.influxdata.com/influxdb.key

Install InfluxDB

[vagrant@DevopsRoles ~]$ sudo yum -y install influxdb

Enable the InfluxDB service to start on system boot:

[vagrant@DevopsRoles ~]$ sudo systemctl enable influxdb

Start InfluxDB services on RHEL / Centos 7

[vagrant@DevopsRoles ~]$ sudo systemctl start influxdb

To check the status of InfluxDB is running

[vagrant@DevopsRoles ~]$ sudo systemctl status influxdb

Configure InfluxDB Firewall on RHEL / Centos 7

The default, InfluxDB uses TCP port 8086 for client-server communication over HTTP API, and TCP port 8088 is used for backup and restore.

Open the port on the Firewall using the command below

[vagrant@DevopsRoles ~]$ sudo firewall-cmd --add-port=8086/tcp --permanent
[vagrant@DevopsRoles ~]$ sudo firewall-cmd --reload

Configure InfluxDB HTTP Authentication on RHEL / Centos 7

Enable HTTP authentication

[vagrant@DevopsRoles ~]$ sudo vi /etc/influxdb/influxdb.conf

Add the content below:

[http]
 auth-enabled = true

Restart the InfluxDB service.

[vagrant@DevopsRoles ~]$ sudo systemctl restart influxdb

Create a user with an Authentication password

[vagrant@DevopsRoles ~]$ curl -XPOST "http://localhost:8086/query" --data-urlencode "q=CREATE USER \
username WITH PASSWORD 'password' WITH ALL PRIVILEGES"

You need to run any Influxdb commands on the terminal with a specific username and password.

[vagrant@DevopsRoles ~]$ influx -username 'username' -password 'password'

For example, the curl command uses the -u option to specify a username and password.

[vagrant@DevopsRoles ~]$ curl -G http://localhost:8086/query -u username:password --data-urlencode "q=SHOW DATABASES"

Check Influxdb service is listening

[vagrant@DevopsRoles ~]$ sudo netstat -nplt | grep 8086

You have successfully installed InfluxDB on RHEL/CentOS 7. Thank you for reading the DevopsRoles page!

Install Netdata on RHEL 7 / CENTOS 7

In this tutorial, How to install Netdata on RHEL 7 / CENTOS 7.

Netdata is performance and health monitoring for systems and applications. It is a monitoring agent you install on all your systems.

Why use Netdata

  • High-resolution metrics
  • Monitors everything
  • Install and get results immediately
  • Requires zero dedicated resources
  • Open-source, free and very easy
  • Auto-scaling of chart units
  • Time-series back-ends supported – it can archive its metrics on graphite, , Prometheus, JSON document DBs, in the same or lower detail

Install Netdata on RHEL 7 / CENTOS 7 from source

Install EPEL Repository

[vagrant@DevopsRoles ~]$ sudo yum install -y epel-release

Installing all dependencies for Netdata.

[vagrant@DevopsRoles ~]$ sudo yum install Judy-devel libuv cmake json-devel autoconf-archive autogen json-c-devel libmnl-devel libuv-devel lz4-devel nmap-ncat openssl-devel python3 git zlib-devel libuuid-devel libmnl gcc make git autoconf automake pkgconfig curl findutils

Clone Netdata from Github

[vagrant@DevopsRoles ~]$ git clone https://github.com/netdata/netdata.git --depth=100
[vagrant@DevopsRoles ~]$ cd netdata/

The build and installation Netdata on RHEL 7 / CENTOS 7

[vagrant@DevopsRoles ~]$ sudo ./netdata-installer.sh

The output terminal as the picture below

Netdata service will start auto after installation.

To stop netdata run

[vagrant@DevopsRoles ~]$ sudo systemctl stop netdata

To start netdata run

[vagrant@DevopsRoles ~]$ sudo systemctl start netdata

Accesing Netdata from Browser

The default listens on all IPs on port 19999. If you have firewalld, allow access to this port within LAN.

[vagrant@DevopsRoles ~]$ sudo firewall-cmd --permanent --add-rich-rule 'rule family="ipv4" \
source address="192.168.1.0/24" port protocol="tcp" port="19999" accept'

Reload Firewalld to apply changes

[vagrant@DevopsRoles ~]$ sudo firewall-cmd --reload

Access Netdata Web dashboard on server

Thank you for reading the DevopsRoles page!

create user and group in Linux

In this tutorial, I will quickly guide create user and group in Linux. How to add a user to a group in Linux. How to create users has permission or user no has permission.

Using command to create the and command to create the in Linux system.

How to create user and group in Linux

create group new in Linux

use groupadd command as below

$ sudo groupadd -g 2000 common # group common no has sudo permission
$ sudo groupadd -g 2001 dev # group dev has sudo permission
$ sudo groupadd -g 1100 IT

Create user new in Linux

For example, user user01 no has permission and user has permission

# useradd -m -d /home/user01 -s  /bin/bash   -g common -u 5000  user01; echo -e "user01\nuser01\n"  |  passwd  user01
# useradd -m -d /home/huupv  -s  /bin/bash   -g IT  -G dev    -u 5001  huupv; echo -e "huupv\nhuupv\n"  |  passwd  huupv

Add group to sudoers file

use visudo to open and edit the /etc/sudoers file and add group dev as follow below

%dev ALL=(root) ALL

Option

Create a user with sudo without password Linux.

# useradd -d /home/devops -u 8888 -s /bin/bash						
# echo -e "devops\ndevops\n" |  passwd devops						
# echo "devops ALL = (root) NOPASSWD:ALL" | tee /etc/sudoers.d/devops						
# chmod 0440 /etc/sudoers.d/devops						

Conclusion

Through the article, You can create user and group in Linux as above. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Change timezone in Linux

In this tutorial, I will change timezone in Linux by command line. How to change the to your current time zone.

  • The location of the local time file in Linux is /etc/localtime.
  • Timezone files are located in /usr/share/zoninfo/

To change the timezone in the Linux command line, you can use the methods below, which are available on most modern Linux distributions. Here’s how you can do it:

How to Change Timezone in Linux with Two Methods.

Method 1: I will copy from /usr/share/zoneinfo/Asia/Ho_Chi_Minh to /etc/localtime

$ sudo cp /usr/share/zoneinfo/Asia/Ho_Chi_Minh /etc/localtime

Method 2: I will delete and make a symbolic Linux from //share//Asia/Ho_Chi_Minh to /etc/ as following below

$ sudo rm -f /etc/localtime
$ sudo ln -s /usr/share/zoneinfo/Asia/Ho_Chi_Minh /etc/localtime

Verify the new timezone:

Conclusion

After changing the timezone, you may need to restart services or applications that rely on the system time to ensure they reflect the new timezone.

You changed your current timezone You can type date command to verify and you’re done. I hope this is helpful you.

How to configure a static IP address on Linux

In this tutorial, How to configure a static IP address on Linux. Step by step to make a static IP address on Linux.

Note: To change the network setting a good idea to make a copy of any configured file before your changes.

Configure a static IP address on Linux

For RHEL 8

How to configure a static IP address on an RHEL system. using command shown list network connections and devices on the system.

$ nmcli dev status

Now, To change the network interface from dynamic to static, you need to edit the file in folder “/etc//network-scripts”. In this example, I will create new file -Comtrend7FB9

Configuring a static IP address as below

HWADDR=7C:67:2A:CC:DF:8F
ESSID=Comtrend7FB9
MODE=Managed
KEY_MGMT=WPA-PSK
SECURITYMODE=open
MAC_ADDRESS_RANDOMIZATION=default
TYPE=Wireless
IPADDR=192.168.3.4  # Ip address static for Linux server
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static      
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=Comtrend7FB9
UUID=3f5a6317-27c7-249f-bfaa-1d2fa5283482
ONBOOT=yes

Restarting NetworkManager.

$ sudo systemctl restart NetworkManager

For Ubuntu 18.10

Using (network manager command-line interface) command to list the network interface on Ubuntu server.

$ nmcli d

For example, configure a static IP address on the Ubuntu system.

# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
auto enp0s25
iface enp0s25 inet static
    address 192.168.3.4
    netmask 255.255.255.0
    network 192.168.3.1
    broadcast 192.168.3.255

Restart the networking service.

$ sudo  systemctl restart NetworkManager.service

Configure Static IP On CentOS 6

You can update/edit as follow static IP configure. For example, I will update for eth0 interface network.

HWADDR=00:08:A2:0B:BA:B7
TYPE=Ethernet
BOOTPROTO=none
# IP static for Server #
IPADDR=192.168.3.4
# Subnet #
PREFIX=24
# Set default gateway IP for server #
GATEWAY=192.168.3.1
# Set dns servers #
DNS1=192.168.3.1
DNS2=8.8.8.8
DNS3=8.8.4.4
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
# Disable ipv6 #
IPV6INIT=no
NAME=eth0
# This is system specific and can be created using 'uuidgen eth0' command #
UUID=31171a6f-bcg1-44de-8h6e-cf8e782f8bd6
DEVICE=eth0
ONBOOT=yes

Save and close the file. you need to restart the service network to apply the configure for the eth0 interface network.

$ sudo systemctl restart network

Conclusion

You have configure a static IP address on Linux. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Get permission of chmod as numerical value on Linux

chmod command is used to change the permissions of files or directories. In this tutorial, I will get of as value on Linux.

For example, Check Linux file and folder permissions with the ls command as below

[vagrant@app1 ~]$ ls -l /home/vagrant/*
-rw-rw-r--. 1 vagrant vagrant   64 Feb 26 15:30 /home/vagrant/a
-rwxrwxr-x. 1 vagrant vagrant  241 Dec 10 15:31 /home/vagrant/bashscript.sh
-rw-rw-r--. 1 vagrant vagrant 3327 Nov 13 12:07 /home/vagrant/id_rsa
-rw-rw-r--. 1 vagrant vagrant  439 Feb 26 15:30 /home/vagrant/lastmodifyofifle.sh

Using stat command as below

[vagrant@app1 ~]$ stat --format='%a %U:%G %n' /home/vagrant/*

The result as below

664 vagrant:vagrant /home/vagrant/a
775 vagrant:vagrant /home/vagrant/bashscript.sh
664 vagrant:vagrant /home/vagrant/id_rsa
664 vagrant:vagrant /home/vagrant/lastmodifyofifle.sh

You make it 🙂

Conclusion

You have to get permission of chmod as numerical value on Linux. I hope will this your helpful. Thank you for reading the DevopsRoles page!