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.

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!

Configure SSH connection with key authentication

In this tutorial, I will configure the SSH connection with key authentication.

How it works

  • (Client) Generate a set of secret key and public key
  • (Connection destination server) Register public key
  • (Connection destination server) Accepts a connection from a client, encrypts the random number using the public key
  • (Connection destination server) Hashed random number
  • (Client) hashes the received random number and forwards the hash value to the server
  • (Connection destination server) Compare the hash value sent by the client and the hash value generated on the server side

Set up SSH connection with key authentication.

1: Generation of a key set

ssh-keygen -t rsa -f client01

2: Public Key Registration

# Work on the server, target users to connect
cat client01.pub >> .ssh/authorized_keys

3: Enabling Key Authentication

  # vim /etc/ssh/sshd_config
  RSAAuthentication yes
  PubkeyAuthentication yes
  AuthorizedKeyFile .ssh/authorized_keys
  # Disable password authentication if you want to strengthen it
   PasswordAuthentication no

Try to connect

ssh -i .ssh/client01 -p12345 huupv@devopsroles

Conclusion

Thought the article, How to configure SSH connection with key authentication in Linux. Thank you for reading the DevopsRoles page!

systemd service unit notes

In this tutorial, The describe service unit notes.

  • is a system and service manager for Linux.
  • init is no longer an old Linux.
  • Only the command can be used for starting and stopping.

systemd service unit file

  • It is arranged under “/etc/systemd/system” with “unitname.service
  • Others include directories like “/usr/lib/systemd” and “/lib/systemd“, but rather for systems.

Service section

Describe the operation parameters of the unit.

Type

The relationship between the execution command and the main process is represented by Type.

  • simple: ExecStart command remains as it is process
  • forking: Child process of ExecStart is process
  • : Even if ExecStart ends, the main process will remain.

Restart

Restart conditions can be specified with parameters equivalent to respawn in the old inittab.

  • always: always rerun
  • on-abort: re-execute when terminating with a signal that can not be caught
  • on-watchdog: Rerun with monitor timeout
  • on-abnormal: Re-execution when terminating with a signal other than SIGHUP, SIGINT, SIGTERM or SIGPIPE
  • on-failure: re-execution when the main process ends with a code other than the normal termination code
  • on-success: Rerun when the main process ends with a normal exit code

Install section

Specify which target (old ) should be executed when th is activated ( enable).

For example, when enabling in multi-user mode (old run level 3), a symbolic link to a unit file is established under “/etc//system/multi-user.target“.

[Unit]
Description=Description
After=Execute after starting the specified unit list
Before=Execute before the specified unit list
Requires=Execute after the specified unit list has been successfully started
Wants=Even if the specified unit list fails to start up

[Service]
Environment=environment variable list
EnvironmentFile=environment variable file
Type=simple|forking|oneshot
ExecStart=start command
ExecStop=stop command
ExecReload=reload command
Restart=On-abort|on-watchdog|on-abnormal|on-failure|on-success|no
RemainAfterExit=yes|no
PIDFile=PID file path of main process
User=ExecXX execution user
SuccessExitStatus=(other than 0) EXIT code list to be regarded as a normal completion of the main process

[Install]
Alias=service alias list
WantedBy=target list
Also=unit list installed together

used commands

Unit file installation (loading)

$ sudo systemctl daemon-reload

Enable/disable

$ systemctl enable|disable unitname

Dependency display

$ systemctl list-dependencies unitname

For example, List Dependency of chronyd package.

Confirm startup sequence

Summary of time spent on startup (kernel, initrd, user)

$ systemd-analyze time

Time is taken to activate unit (currently active unit)

$ systemd-analyze blame

SVG output startup sequence

$ systemd-analyze plot > systemd.sequence.svg 

Confirm log

$ journalctl -xe 
$ journalctl -xe -S "2019-01-22 23:00:00"  
$ journalctl -xe -S "2019-01-22 23:00:00" -U "2019-01-22 23:10:00" 
$ journalctl -xe -u unitname
$ journalctl -f -u servicename 
$ journalctl --disk-usage

$ lsof -p $(pidof systemd-journald)

Reference information

  • man .service
  • man -analyze

unit file example

Apache system (fork daemon)

myhttpd.service unit file

[Unit]
Description=HTTP Server
After=web.service

[Service]
Type=forking
ExecStart=/opt/bin/apachectl start
ExecStop=/opt/bin/apachectl graceful-stop
PIDFile=/opt/logs/httpd.pid
Restart=on-failure

[Install]
WantedBy=multi-user.target

web.service unit file

[Unit]
Description=WebSphere Application Server apserver
After=network.target network.service

[Service]
Type=forking
ExecStart=/opt/AppServer/profiles/AppSrv01/bin/startServer.sh apserver
ExecStop=/opt/AppServer/profiles/AppSrv01/bin/stopServer.sh apserver
PIDFile=/opt/AppServer/profiles/AppSrv01/logs/apserver/apserver.pid
Restart=on-failure
User=webuser
SuccessExitStatus=143 0
TimeoutStopSec=0
TimeoutStartSec=0

[Install]
WantedBy=multi-user.target

systemd service unit notes. Thank you for reading the DevopsRoles page!