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.

How to use bash create file in Linux

Introduction

This tutorial is all about using bash create file in Linux in the terminal. Guess what? It’s super easy! Bash has this neat and efficient command called “touch” that makes creating files a breeze. So, let’s dive in and discover how to use the touch command to create new files in Bash.

Alright, so what’s the deal with this “touch” command? Well, it’s like a magic wand for your terminal. With just a simple touch command, you can conjure up new files effortlessly. No need to go through complicated steps – Bash keeps it straightforward. In this tutorial, we’re going to break down the touch command and explore how it turns your terminal into a file-creating wizard.

Creating files in Bash doesn’t have to be a puzzle. With the trusty touch command, you’ll be crafting files like a pro in no time. This tutorial is your guide to mastering the art of file creation in Bash, so get ready to unleash the power of the touch command and make your terminal work wonders!

How to use Bash to create a file

Bash create file: A Guide to Using the Touch Command

The touch command to create an empty text file with foo.txt

The touch command in Bash is primarily used to update the access and modification timestamps of files. However, it can also be used to create a new file if it doesn’t already exist.

To create a new file using the touch command, follow this syntax:

$ touch foo.bar
$ > foo.bar
bash create file command

To make a text file using the cat command line on Linux. press ctrl+c to quit and save the file.

$ cat > foo.txt

shell command

$ echo 'This is my blog: devopsroles.com' > foo.txt

Append text to an existing file

$ echo 'yet another line: huuphan.com' >> foo.txt

To create a text file, you can use the vi or vim commands in your terminal. These tools are powerful editors for crafting text documents. Simply type vi or vim followed by the desired filename and press Enter. This will open an editor where you can write and edit your text. To begin typing, press i to enter insert mode. When you’re finished, press the Esc key to exit insert mode.

To save your work, type :w and press Enter. To close the editor, type :q, or you can save and exit at the same time by typing :wq. With these simple steps, you’ve successfully created your text file!

Conclusion

You have to use the Bash create file command terminal. Creating a new file in Bash is a straightforward process with the help of the touch command. Its simplicity and efficiency make it a popular choice for generating empty files. By using the touch command and providing the desired filename, you can quickly create new files in your Bash scripts or command-line operations. I hope will this your helpful. Thank you for reading the DevopsRoles page!

How to Password Protect Files on Linux : A Complete Guide

Introduction

In this tutorial, you’ll learn how to password protect files on Linux to ensure they remain secure from unauthorized access. Various methods are available for this purpose, each providing different levels of security. Here are a few techniques to help you safeguard your files and folders with strong passwords.

Using tools like zip and gpg, you can encrypt your files effectively. zip allows you to compress and password protect files, while gpg offers robust encryption options. Both methods are straightforward and enhance the security of your sensitive data on Linux systems.

How to Password Protect Files on Linux

Encrypt a File with GnuPG

I use gpg command to encrypt a file. GnuPG is a free Linux program that supports multiple encryptions for file encryption.

1. Open the terminal

2. Run the following command line to encrypt your file.

gpg -c your_file

GnuPG will create an encrypted file with .gpg extension in your current working folder.

The result is the picture below:

To access it, you’ll need to decrypt it. For this, run the following command

gpg your_file.gpg

The result is the picture below:

other encryption algorithms, first, check the supported ones by running:

For example, you specify the desired algorithm as a command below

gpg -c --cipher-algo algorithm_name your_file

using the zip command to Encrypt a File

the zip command is another CLI utility that password-protect files on Linux. it is pre-installed on all Linux distros.

zip --password your_password archive_file.zip file1 file2

you replace your_passowrd with the password you want to use to encrypt the archive.

Unzip the archive and enter your password. you can run the command below:

unzip archive_file.zip

Encrypt a File Using mcrypt

list out all the supported encryption algorithms

mcrypt --list

encrypt filename

mcrypt -a algorithm_name filename

If you wish to open this file, you’ll need to decrypt it as the command below:

mcrypt -d filename.nc

Conclusion

By following this tutorial, you now know how to password protect files on Linux, enhancing your data security. Always choose a strong, unique password when prompted and consider using a password manager to keep your passwords safe and easily accessible. Implementing these methods helps prevent unauthorized access and ensures your sensitive information remains protected. Thank you for reading the DevopsRoles page and I hope you found this information helpful. Stay secure!

Fixing the “Ubuntu Repository No Longer Has a Release” Issue

Introduction

In this tutorial, How to fix the Ubuntu repository no longer has a Release.

Ubuntu, a widely used Linux distribution, relies on repositories to provide software packages and updates. Occasionally, you might encounter the error message “Ubuntu repository no longer has a release,” indicating that the repository you’re trying to access is unavailable or unsupported. This article delves into the reasons behind this issue and offers potential solutions to address it effectively.

Today, I am installing Nginx, But suddenly one day you use this command and get the following error:

vagrant@controller:~$ sudo apt install nginx -y
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libnginx-mod-http-geoip2 libnginx-mod-http-image-filter libnginx-mod-http-xslt-filter libnginx-mod-mail
  libnginx-mod-stream libnginx-mod-stream-geoip2 nginx-common nginx-core
Suggested packages:
  fcgiwrap nginx-doc ssl-cert
The following NEW packages will be installed:
  libnginx-mod-http-geoip2 libnginx-mod-http-image-filter libnginx-mod-http-xslt-filter libnginx-mod-mail
  libnginx-mod-stream libnginx-mod-stream-geoip2 nginx nginx-common nginx-core
0 upgraded, 9 newly installed, 0 to remove and 0 not upgraded.
Need to get 700 kB of archives.
After this operation, 2386 kB of additional disk space will be used.
Ign:1 http://archive.ubuntu.com/ubuntu impish-updates/main amd64 nginx-common all 1.18.0-6ubuntu11.1
Ign:2 http://archive.ubuntu.com/ubuntu impish-updates/main amd64 libnginx-mod-http-geoip2 amd64 1.18.0-6ubuntu11.1
Ign:3 http://archive.ubuntu.com/ubuntu impish-updates/main amd64 libnginx-mod-http-image-filter amd64 1.18.0-6ubuntu11.1Ign:4 http://archive.ubuntu.com/ubuntu impish-updates/main amd64 libnginx-mod-http-xslt-filter amd64 1.18.0-6ubuntu11.1
Ign:5 http://archive.ubuntu.com/ubuntu impish-updates/main amd64 libnginx-mod-mail amd64 1.18.0-6ubuntu11.1
Ign:6 http://archive.ubuntu.com/ubuntu impish-updates/main amd64 libnginx-mod-stream amd64 1.18.0-6ubuntu11.1
Ign:7 http://archive.ubuntu.com/ubuntu impish-updates/main amd64 libnginx-mod-stream-geoip2 amd64 1.18.0-6ubuntu11.1
Ign:8 http://archive.ubuntu.com/ubuntu impish-updates/main amd64 nginx-core amd64 1.18.0-6ubuntu11.1
Ign:9 http://archive.ubuntu.com/ubuntu impish-updates/main amd64 nginx amd64 1.18.0-6ubuntu11.1
Err:1 http://security.ubuntu.com/ubuntu impish-updates/main amd64 nginx-common all 1.18.0-6ubuntu11.1
  404  Not Found [IP: 91.189.91.39 80]
Err:2 http://security.ubuntu.com/ubuntu impish-updates/main amd64 libnginx-mod-http-geoip2 amd64 1.18.0-6ubuntu11.1
  404  Not Found [IP: 91.189.91.39 80]
Err:3 http://security.ubuntu.com/ubuntu impish-updates/main amd64 libnginx-mod-http-image-filter amd64 1.18.0-6ubuntu11.1
  404  Not Found [IP: 91.189.91.39 80]
Err:4 http://security.ubuntu.com/ubuntu impish-updates/main amd64 libnginx-mod-http-xslt-filter amd64 1.18.0-6ubuntu11.1  404  Not Found [IP: 91.189.91.39 80]
Err:5 http://security.ubuntu.com/ubuntu impish-updates/main amd64 libnginx-mod-mail amd64 1.18.0-6ubuntu11.1
  404  Not Found [IP: 91.189.91.39 80]
Err:6 http://security.ubuntu.com/ubuntu impish-updates/main amd64 libnginx-mod-stream amd64 1.18.0-6ubuntu11.1
  404  Not Found [IP: 91.189.91.39 80]
  404  Not Found [IP: 91.189.91.39 80]
Err:9 http://security.ubuntu.com/ubuntu impish-updates/main amd64 nginx amd64 1.18.0-6ubuntu11.1
  404  Not Found [IP: 91.189.91.39 80]
E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/n/nginx/nginx-common_1.18.0-6ubuntu11.1_all.deb  404  Not Found [IP: 91.189.91.39 80]
E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/n/nginx/libnginx-mod-http-geoip2_1.18.0-6ubuntu11.1_amd64.deb  404  Not Found [IP: 91.189.91.39 80]
E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/n/nginx/libnginx-mod-http-image-filter_1.18.0-6ubuntu11.1_amd64.deb  404  Not Found [IP: 91.189.91.39 80]
E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/n/nginx/libnginx-mod-http-xslt-filter_1.18.0-6ubuntu11.1_amd64.deb  404  Not Found [IP: 91.189.91.39 80]
E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/n/nginx/libnginx-mod-mail_1.18.0-6ubuntu11.1_amd64.deb  404  Not Found [IP: 91.189.91.39 80]
E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/n/nginx/libnginx-mod-stream_1.18.0-6ubuntu11.1_amd64.deb  404  Not Found [IP: 91.189.91.39 80]
E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/n/nginx/libnginx-mod-stream-geoip2_1.18.0-6ubuntu11.1_amd64.deb  404  Not Found [IP: 91.189.91.39 80]
E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/n/nginx/nginx-core_1.18.0-6ubuntu11.1_amd64.deb  404  Not Found [IP: 91.189.91.39 80]
E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/n/nginx/nginx_1.18.0-6ubuntu11.1_amd64.deb  404  Not Found [IP: 91.189.91.39 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

Cause: older releases of Ubuntu moved to a new host.

If you encounter an issue where the Ubuntu repository no longer has a “Release” file, it could be due to a temporary problem with the repository or a misconfiguration on your system. Here are a few steps you can take to troubleshoot and potentially resolve the issue:

Ubuntu repository no longer has a Release fixed

Step 1. Backup file sources.list

cp /etc/apt/sources.list /etc/apt/sources.list.bak

Step 2. Replace the links with the new repository address.

sudo sed -i -re 's/([a-z]{2}.)?archive.ubuntu.com|security.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list

Step 3. Update OS after steps 1 and step 2.

sudo apt-get update && sudo apt-get dist-upgrade

At this point, when you see that command 3 has run successfully, you can completely select Y to continue the update process for your Ubuntu server. Or select N to cancel the update process.

As a result, the fixed repository no longer has a Release file on Ubuntu Server. For example, I select Y.

root@controller:~# sudo apt-get update && sudo apt-get dist-upgrade
Get:1 http://old-releases.ubuntu.com/ubuntu impish InRelease [270 kB]
Hit:2 https://apache.jfrog.io/artifactory/couchdb-deb focal InRelease
Get:3 http://old-releases.ubuntu.com/ubuntu impish-updates InRelease [115 kB]
Get:4 http://old-releases.ubuntu.com/ubuntu impish-backports InRelease [101 kB]
Get:5 http://old-releases.ubuntu.com/ubuntu impish-security InRelease [110 kB]
Get:6 http://old-releases.ubuntu.com/ubuntu impish/main amd64 Packages [1396 kB]
Get:7 http://old-releases.ubuntu.com/ubuntu impish/main Translation-en [511 kB]
Get:8 http://old-releases.ubuntu.com/ubuntu impish/main amd64 c-n-f Metadata [29.8 kB]
Get:9 http://old-releases.ubuntu.com/ubuntu impish/restricted amd64 Packages [82.2 kB]
Get:44 http://old-releases.ubuntu.com/ubuntu impish-security/universe amd64 c-n-f Metadata [5396 B]
Get:45 http://old-releases.ubuntu.com/ubuntu impish-security/multiverse amd64 Packages [4776 B]
Get:46 http://old-releases.ubuntu.com/ubuntu impish-security/multiverse Translation-en [988 B]
Get:47 http://old-releases.ubuntu.com/ubuntu impish-security/multiverse amd64 c-n-f Metadata [228 B]
Fetched 23.4 MB in 1min 34s (248 kB/s)
Reading package lists... Done
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
The following packages will be upgraded:
  git git-man libpython3.9 libpython3.9-minimal libpython3.9-stdlib python3-distupgrade python3.9 python3.9-minimal
  ubuntu-release-upgrader-core
9 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
7 standard security updates
Need to get 11.1 MB of archives.
After this operation, 24.6 kB disk space will be freed.
Do you want to continue? [Y/n] y
Get:1 http://old-releases.ubuntu.com/ubuntu impish-updates/main amd64 python3.9 amd64 3.9.7-2ubuntu0.1 [433 kB]
Get:2 http://old-releases.ubuntu.com/ubuntu impish-updates/main amd64 libpython3.9 amd64 3.9.7-2ubuntu0.1 [1897 kB]
Get:3 http://old-releases.ubuntu.com/ubuntu impish-updates/main amd64 libpython3.9-stdlib amd64 3.9.7-2ubuntu0.1 [1807 kB]
Get:4 http://old-releases.ubuntu.com/ubuntu impish-updates/main amd64 python3.9-minimal amd64 3.9.7-2ubuntu0.1 [2058 kB]
Get:5 http://old-releases.ubuntu.com/ubuntu impish-updates/main amd64 libpython3.9-minimal amd64 3.9.7-2ubuntu0.1 [783 kB]
Get:6 http://old-releases.ubuntu.com/ubuntu impish-updates/main amd64 ubuntu-release-upgrader-core all 1:21.10.10 [25.5 kB]
Get:7 http://old-releases.ubuntu.com/ubuntu impish-updates/main amd64 python3-distupgrade all 1:21.10.10 [104 kB]
Get:8 http://old-releases.ubuntu.com/ubuntu impish-updates/main amd64 git-man all 1:2.32.0-1ubuntu1.3 [943 kB]
Get:9 http://old-releases.ubuntu.com/ubuntu impish-updates/main amd64 git amd64 1:2.32.0-1ubuntu1.3 [3038 kB]
Fetched 11.1 MB in 50s (221 kB/s)
(Reading database ... 99174 files and directories currently installed.)
Preparing to unpack .../0-python3.9_3.9.7-2ubuntu0.1_amd64.deb ...
Unpacking python3.9 (3.9.7-2ubuntu0.1) over (3.9.7-2build1) ...
Preparing to unpack .../1-libpython3.9_3.9.7-2ubuntu0.1_amd64.deb ...
Unpacking libpython3.9:amd64 (3.9.7-2ubuntu0.1) over (3.9.7-2build1) ...
Preparing to unpack .../2-libpython3.9-stdlib_3.9.7-2ubuntu0.1_amd64.deb ...
Unpacking libpython3.9-stdlib:amd64 (3.9.7-2ubuntu0.1) over (3.9.7-2build1) ...
Preparing to unpack .../3-python3.9-minimal_3.9.7-2ubuntu0.1_amd64.deb ...
Unpacking python3.9-minimal (3.9.7-2ubuntu0.1) over (3.9.7-2build1) ...
Preparing to unpack .../4-libpython3.9-minimal_3.9.7-2ubuntu0.1_amd64.deb ...
Unpacking libpython3.9-minimal:amd64 (3.9.7-2ubuntu0.1) over (3.9.7-2build1) ...
Preparing to unpack .../5-ubuntu-release-upgrader-core_1%3a21.10.10_all.deb ...
Unpacking ubuntu-release-upgrader-core (1:21.10.10) over (1:21.10.9) ...
Preparing to unpack .../6-python3-distupgrade_1%3a21.10.10_all.deb ...
Unpacking python3-distupgrade (1:21.10.10) over (1:21.10.9) ...
Preparing to unpack .../7-git-man_1%3a2.32.0-1ubuntu1.3_all.deb ...
Unpacking git-man (1:2.32.0-1ubuntu1.3) over (1:2.32.0-1ubuntu1.2) ...
Preparing to unpack .../8-git_1%3a2.32.0-1ubuntu1.3_amd64.deb ...
Unpacking git (1:2.32.0-1ubuntu1.3) over (1:2.32.0-1ubuntu1.2) ...
Setting up libpython3.9-minimal:amd64 (3.9.7-2ubuntu0.1) ...
Setting up python3-distupgrade (1:21.10.10) ...
Setting up ubuntu-release-upgrader-core (1:21.10.10) ...
Setting up git-man (1:2.32.0-1ubuntu1.3) ...
Setting up python3.9-minimal (3.9.7-2ubuntu0.1) ...
Setting up libpython3.9-stdlib:amd64 (3.9.7-2ubuntu0.1) ...
Setting up libpython3.9:amd64 (3.9.7-2ubuntu0.1) ...
Setting up git (1:2.32.0-1ubuntu1.3) ...
Setting up python3.9 (3.9.7-2ubuntu0.1) ...
Processing triggers for man-db (2.9.4-2) ...
Processing triggers for libc-bin (2.34-0ubuntu3.2) ...
Scanning processes...
Scanning candidates...
Scanning linux images...

Running kernel seems to be up-to-date.

Restarting services...
Service restarts being deferred:
 systemctl restart networkd-dispatcher.service
 systemctl restart unattended-upgrades.service

No containers need to be restarted.

No user sessions are running outdated binaries.

Via Youtube

Conclusion

By understanding the potential causes and implementing the solutions provided in this article, you can address the issue and restore the functionality of your package manager.

Whether it’s removing unsupported repositories, updating URLs, ensuring network connectivity, or waiting for temporary issues to be resolved, these steps will help you navigate and resolve the error efficiently.

You have a fixed repository no longer has a Release file on Ubuntu. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Linux Systemd Cheat Sheet Useful

Introduction

In this tutorial, I write about the Systemd cheat sheet useful in Linux. Systemd provides a system and service that runs at PID 1. It tracks logged-in users and runs containers virtual machines and more.

The Linux Systemd Cheat Sheet is a handy guide that provides quick and easy-to-understand information about Systemd. Systemd is a system and service manager for Linux operating systems, and this cheat sheet is designed to help users navigate and utilize its features efficiently.

Whether you’re a beginner or an experienced Linux user, this cheat sheet covers essential commands and functions related to Systemd. From starting and stopping services to managing system processes, the cheat sheet is a valuable resource for anyone looking to streamline their Linux system management tasks.

With the Linux Systemd Cheat Sheet, you can quickly reference key Systemd commands, making it easier to troubleshoot issues, configure services, and optimize system performance. This user-friendly guide aims to empower Linux users with the knowledge they need to navigate Systemd effectively, ensuring a smoother and more efficient system administration experience.

Systemd Cheat Sheet in Linux

Logs with systemd

The contentCommand Line
View all system logsjournalctl
List boot numbersjournalctl –list-boots
View logs for unit sshjournalctl –unit ssh
View system logs from the most recentjournalctl -xe

For example the picture below

Introspection with systemd

The contentCommand Line
show unit file settingssystemctl show sshd
Show contents of the unit filesystemctl cat sshd
Show whether the unit is activesystemctl is-active sshd
Show whether the unit has failedsystemctl is-failed sshd
Edit unit file configurationsudo systemctl edit sshd
Restart daemonsudo systemctl daemon-reload

Services

The contentCommand Line
Start service nginxsystemctl start nginx
Stop service nginxsystemctl stop nginx
Show status of service nginxsystemctl status nginx
Start nginx now and at system startupsystemctl enable –now nginx
At system startup, start (enable) nginxsystemctl enable nginx
At system startup, do not start nginxsystemctl disable nginx
Show whether service nginx is enabledsystemctl is-enabled nginx
Prevent service from starting (mask)systemctl mask nginx
Unmask service, allowing it to be startedsystemctl unmask nginx
List all available servicessystemctl list-unit-files –-type service

For example as below

Targets (runlevels)

Targets, also known as runlevels in Linux, play a crucial role in managing the system’s state and functionality. Think of targets as different modes or scenarios your computer can operate in, each with a specific set of services and processes.

In simpler terms, runlevels help define what your computer is supposed to do at different stages – be it during startup, regular operation, or shutdown. For instance, runlevel 3 might focus on a multi-user environment with networking capabilities, while runlevel 5 could include a graphical user interface for a more user-friendly experience.

These runlevels or targets allow users to customize and control the behavior of their Linux system based on their needs. Whether you’re setting up a server that doesn’t require a graphical interface or a desktop environment for everyday use, understanding and configuring runlevels is essential for tailoring your Linux experience.

The contentCommand line
List all available targetssystemctl list-unit-files –-type target
Show dependencies of a targetsystemctl list-dependencies nginx
Show default boot targetsystemctl get-default
Boot to a text consolesystemctl set-default multi-user
Boot to a graphical desktopsystemctl set-default graphical

FAQ Section

1. What is the difference between systemctl and journalctl?

systemctl manages services, units, and targets, while journalctl is used to view logs maintained by Systemd.

2. Can Systemd work alongside other init systems?

Yes, but it’s not recommended as conflicts can arise. Most modern Linux distributions have fully transitioned to Systemd.

3. How do I troubleshoot failed services?

Use:

systemctl status <service-name>

Then, check logs with:

journalctl -u <service-name>

External Resources

Conclusion

You should utilize the helpful Systemd Cheat Sheet in Linux. The cheat sheet includes fundamental systemd commands, and there are even more advanced features and options to explore. For detailed information about specific commands or options, you can check the systemd documentation or man pages (man systemctl). I hope you find this information useful. Thank you for visiting the DevopsRoles page!”

How to install CouchDB on Rocky Linux 8: A Comprehensive Guide

Introduction

In this tutorial, How to Install CouchDB on Rocky Linux Server. We’ll cover each step, from updating your system and installing necessary dependencies to configuring CouchDB for optimal performance. By the end of this guide, you will have a fully functional CouchDB instance running on your Rocky Linux server, ready to handle your database needs with reliability and efficiency.

  • CouchDB is a NoSQL database.
  • CouchDB stores and presents data in JavaScript Object Notation.

Install CouchDB on Rocky Linux 8

Update the System

$ sudo yum update

Install “epel-release” repository.

$ sudo yum install epel-release

Enable the Apache CouchDB package repository.

$ sudo vi /etc/yum.repos.d/apache-couchdb.repo

The content is as below:

[bintray--apache-couchdb-rpm]
name=bintray--apache-couchdb-rpm
baseurl=http://apache.bintray.com/couchdb-rpm/el$releasever/$basearch/
gpgcheck=0
repo_gpgcheck=0
enabled=1

You want to install Standalone or Cluster Mode. I will use standalone mode.

Install CouchDB

How to fix the error code below:

[vagrant@localhost ~]$ sudo yum install couchdb
bintray--apache-couchdb-rpm                                                                                                                                                      170  B/s | 166  B     00:00
Errors during downloading metadata for repository 'bintray--apache-couchdb-rpm':
  - Status code: 502 for http://apache.bintray.com/couchdb-rpm/el8/x86_64/repodata/repomd.xml (IP: 34.215.50.170)
Error: Failed to download metadata for repo 'bintray--apache-couchdb-rpm': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried

You need to delete the repo and add the repo for “couchdb.repo” as below:

$ sudo rm /etc/yum.repos.d/apache-couchdb.repo
$ sudo yum-config-manager --add-repo https://couchdb.apache.org/repo/couchdb.repo

YouTube: Step-by-Step Guide: Installing CouchDB on Rocky Linux 8

Now, You install the Couchdb server.

$ sudo yum install couchdb

The output terminal is the picture below:

Verify the installation.

Start services

# systemctl start couchdb
# systemctl enable couchdb
# systemctl status couchdb

Firewalld setting allows port 5984

$ sudo firewall-cmd --zone=public --permanent --add-port=5984/tcp
$ sudo systemctl start firewalld

The CouchDB server will run on localhost:5984

Configuration of CouchDB on Rocky Linux 8

CouchDB’s configuration files are located in the /opt/couchdb/etc/ directory.

Open the file

$ sudo vi /opt/couchdb/etc/local.ini

uncommenting the line just below

[admins]
admin = mypassword

Uncomment the port and bind-address values.

[chttpd]
port = 5984
bind_address = 0.0.0.0

Save the changes and exit the configuration file.

Creating a Database

Access CouchDB Web Interface at http://127.0.0.1:5984/_utils/ with your user credentials and create a new database with CouchDB.

By default, CouchDB listens on port 5984.

Conclusion

You have to Install CouchDB on Rocky Linux 8. CouchDB should now be installed and running on your Rocky Linux 8 system. Remember to secure your CouchDB installation and configure any necessary authentication and access controls based on your requirements. I hope this will be helpful for you. Thank you for reading the DevopsRoles page!

How to run a single command on multiple Linux machines at once

Introduction

In this tutorial, How to run a single command on multiple Linux machines at once. I will create a script on the Linux servers to send commands to multiple servers.

Prerequisites

  • 2 Virtual Machine
  • ssh Connectivity Between 2 Servers

Configure SSH on Server 1

For example, The Server calls the name controller. This server is using the operating system Ubuntu.

create the SSH config file with the command:

cat ~/.ssh/config

For example, the content as output below

Create the script to run a single command on multiple Linux machines at once

We will create 1 script to run a command for a remote Linux server.

sudo vi /usr/local/bin/script_node1

In that file, paste the following:

#!/bin/bash

# Get the user's input as command
[[ -z ${@} ]] && exit || CMD_EXEC="${@}"

# Get the hosts from ~/.ssh/config
HOSTS=$(grep -Po 'Host\s\Knode1' "$HOME/.ssh/config")

# Test weather the input command uses sudo
if [[ $CMD_EXEC =~ ^sudo ]]
then
    # Ask for password
    read -sp '[sudo] password for remote_admin: ' password; echo

    # Rewrite the command
    CMD_EXEC=$(sed "s/^sudo/echo '$password' | sudo -S/" <<< "$CMD_EXEC")
fi

# loop over the hosts and execute the SSH command, remove `-a` to override the>
while IFS= read -r host
do
   echo -e '\n\033[1;33m'"HOST: ${host}"'\033[0m'
   ssh -n "$host" "$CMD_EXEC 2>&1" | tee -a "/tmp/$(basename "${0}").${host}"
done <<< "$HOSTS"

Save and close the file.

Now, We will update the package for server calls name node1 as command below:

script_node1 sudo apt-get update

Via youtube

Conclusion

You have to run a single command on multiple Linux machines at once. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Install pyenv and manage multiple python versions

Introduction

In this post, How to Install pyenv and manage multiple python versions.

  • Pyenv is a fantastic tool for installing and managing multiple Python versions. It also offers the ability to quickly switch from one version of Python to another.
  • Pyenv integrates with the Virtualenv plugin to support creating virtual environments (virtual environments), and library projects will be installed in isolation in this virtual environment without affecting the system.

Install Dependencies

On Rocky Linux / Centos

sudo yum install zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel xz xz-devel libffi-devel

On Ubuntu

sudo apt-get install make build-essential libssl-dev zlib1g-dev libbz2-dev \
  libreadline-dev libsqlite3-dev wget curl libncurses5-dev libncursesw5-dev \
  xz-utils tk-dev libffi-dev liblzma-dev

Install pyenv

You can view the installation instructions from Pyenv’s homepage on Github or use the command below

$ curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash

The output terminal install pyenv as below

vagrant@devopsroles:~$ curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   148  100   148    0     0    778      0 --:--:-- --:--:-- --:--:--   778
100  1687  100  1687    0     0   5477      0 --:--:-- --:--:-- --:--:-- 17214
Cloning into '/home/vagrant/.pyenv'...
remote: Enumerating objects: 882, done.
remote: Counting objects: 100% (882/882), done.
remote: Compressing objects: 100% (438/438), done.
remote: Total 882 (delta 493), reused 565 (delta 338), pack-reused 0
Receiving objects: 100% (882/882), 460.45 KiB | 1.92 MiB/s, done.
Resolving deltas: 100% (493/493), done.
Cloning into '/home/vagrant/.pyenv/plugins/pyenv-doctor'...
remote: Enumerating objects: 11, done.
remote: Counting objects: 100% (11/11), done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 11 (delta 1), reused 3 (delta 0), pack-reused 0
Receiving objects: 100% (11/11), 38.71 KiB | 1.49 MiB/s, done.
Resolving deltas: 100% (1/1), done.
Cloning into '/home/vagrant/.pyenv/plugins/pyenv-installer'...
remote: Enumerating objects: 16, done.
remote: Counting objects: 100% (16/16), done.
remote: Compressing objects: 100% (13/13), done.
remote: Total 16 (delta 1), reused 10 (delta 0), pack-reused 0
Receiving objects: 100% (16/16), 5.78 KiB | 5.78 MiB/s, done.
Resolving deltas: 100% (1/1), done.
Cloning into '/home/vagrant/.pyenv/plugins/pyenv-update'...
remote: Enumerating objects: 10, done.
remote: Counting objects: 100% (10/10), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 10 (delta 1), reused 5 (delta 0), pack-reused 0
Receiving objects: 100% (10/10), done.
Resolving deltas: 100% (1/1), done.
Cloning into '/home/vagrant/.pyenv/plugins/pyenv-virtualenv'...
remote: Enumerating objects: 61, done.
remote: Counting objects: 100% (61/61), done.
remote: Compressing objects: 100% (55/55), done.
remote: Total 61 (delta 11), reused 22 (delta 0), pack-reused 0
Receiving objects: 100% (61/61), 37.94 KiB | 2.11 MiB/s, done.
Resolving deltas: 100% (11/11), done.
Cloning into '/home/vagrant/.pyenv/plugins/pyenv-which-ext'...
remote: Enumerating objects: 10, done.
remote: Counting objects: 100% (10/10), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 10 (delta 1), reused 6 (delta 0), pack-reused 0
Receiving objects: 100% (10/10), done.
Resolving deltas: 100% (1/1), done.

WARNING: seems you still have not added 'pyenv' to the load path.


# See the README for instructions on how to set up
# your shell environment for Pyenv.

# Load pyenv-virtualenv automatically by adding
# the following to ~/.bashrc:

eval "$(pyenv virtualenv-init -)"

Then insert the following 3 lines into the shell’s config file ~/.bashrc

export PATH="/home/vagrant/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

The output terminal config file ~/.bashrc as below

[vagrant@devopsroles ~]$ cat .bashrc
# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

# User specific environment
if ! [[ "$PATH" =~ "$HOME/.local/bin:$HOME/bin:" ]]
then
    PATH="$HOME/.local/bin:$HOME/bin:$PATH"
fi
export PATH

# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=

# User specific aliases and functions
export PATH="/home/vagrant/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
[vagrant@devopsroles ~]$ source .bashrc
[vagrant@devopsroles ~]$ pyenv --version
pyenv 2.2.4
[vagrant@devopsroles ~]$

use pyenv

For example, I will introduce how to use pyenv to set up a virtual environment using python 3.6.6 for the project demo. Path ~/projects/demo

$ pyenv install 3.6.6

The output terminal as below

[vagrant@devopsroles ~]$ pyenv install 3.6.6

Installing Python-3.6.6...
Installed Python-3.6.6 to /home/vagrant/.pyenv/versions/3.6.6
[vagrant@devopsroles ~]$

If the installation fails, maybe your system lacks the necessary libraries for compiling, install the missing libraries here

Create a virtual environment with virtualenv, which uses Python 3.6.6.

pyenv virtualenv 3.6.6 app

Enable environment settings

pyenv activate app

To deactivate environment settings

pyenv deactivate app

Useful Commands

Conclusion

You have to Install pyenv and manage multiple python versions. I hope will this your helpful. Thank you for reading the DevopsRoles page! Install pyenv, Install pyenv.

Exploring the fd Command in Linux: A Powerful Find Alternative for Efficient File Searches

Introduction

In this tutorial, how to use the fd command in Linux. fd command-line tool to find files in the file system. this tool is very simple.

The “fd” command is not a standard command in Linux. It seems that you might be referring to a specific command that is not part of the core Linux utilities.

What is the ‘fd’ Command?

The ‘fd’ command is a powerful and user-friendly tool that facilitates file searches within the Linux file system.

Although not a native Linux command, it is often considered a better and more intuitive alternative to the ‘find’ command. ‘fd’ is built on Rust, which contributes to its speed and efficiency.

Install fd command

Before you can start using ‘fd’, you need to install it on your Linux system. In this section, we’ll cover how to install ‘fd’ using popular package managers like ‘apt’ and ‘yum’, as well as from source.

Using apt to install fd on Ubuntu Server.

sudo apt-get install fd-find

(Optional) Create an alias for fd that refers to fdfind.

alias fd=fdfind

(Optional) To make the alias permanent.

vi ~/.bashrc
#Add this entry to the bashrc file
alias fd=fdfind

Use the fd command in Linux

Before using the fd command in Linux, we need to read the help of the command.

# fd --help

The output terminal as below

Find all files and directories starting with “abc” followed by any number of digits, you can use the following command:

fd -e "^abc\d+"

find all files that were changed before a specified number of days

$ fd index /home/vagrant --changed-before 365d

Finding Files Inside a Specific Directory

$ fd password /etc

Finding Files Based on Extension

$ fd -e html

Finding Hidden Files

$ fd -H bash

More details information about fd command.

man fd

Conclusion

fd command is a simple command in Linux. It uses the number of lines of files. These are just a few examples of how you can use the “fd” command.

For more advanced usage and options, you can refer to the documentation or help of the specific “fd” implementation you have installed on your system, as there are multiple versions available. Thank you for reading the DevopsRoles page!

Install LAMP Stack on Rocky Linux

Introduction

In this tutorial, How to Install LAMP Stack on Rocky Linux. A LAMP stack, which stands for Linux, Apache, MySQL (or MariaDB), and PHP, is a popular software bundle that provides the necessary components for hosting dynamic websites and web applications. In this tutorial, we’ll walk you through the steps to set up a LAMP stack on a Rocky Linux server.

Prerequisites

Before we begin, ensure that you have:

  • A running Rocky Linux instance
  • Root or sudo privileges
  • A stable internet connection

How to install LAMP Stack on Rocky Linux

Install Apache on Rocky Linux

Apache HTTP Server is one of the most widely used web servers in the world. To install it, run the following command:

dnf install -y httpd httpd-devel httpd-tools

Enable Apache start at boot time

systemctl enable httpd

start the Apache HTTPd daemon

systemctl start httpd

To check Apache running on Rocky Linux

systemctl status httpd

The output terminal is below

Opens a browser that can access your Server’s IP address

http://Your-IP-address
OR
http://domain.com

Install MariaDB on Rocky Linux

Next, you’ll need a database server. You can choose between MariaDB and MySQL. In this example, we’ll use MariaDB. Install it with the following command:

dnf install mariadb-server mariadb

The output terminal as below

Enable MariaDB to start at boot time

systemctl enable --now mariadb

Start the MariaDB daemon

systemctl start mariadb

To check MariaDB running on Rocky Linux

systemctl status mariadb

Additional steps to harden the database server. Run the MariaDB security script to secure your installation:

mysql_secure_installation
Set root password? [Y/n] y
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y

Follow the on-screen prompts to set a root password and improve the security of your database server.

Install PHP on Rocky Linux

The default PHP stream is PHP 7.2. PHP is a server-side scripting language commonly used in web development. Install PHP and the PHP MySQL extension with the following command:

To install the latest module Stream. We will reset the PHP streams.

dnf module reset php

Install PHP 7.4

dnf module install php:7.4

The output terminal is below

Install additional PHP extensions

dnf install php-cli php-gd php-curl php-zip php-mbstring php-opcache php-intl php-mysqlnd

Confirm the version of PHP installed

php -v

The output terminal is below

Test Your Install LAMP Stack

To verify that your LAMP stack is installed and running correctly, create a test PHP file in the Apache web root directory. We’ll use info.php as an example:

We create a test PHP file in the /var/www/html path.

vi /var/www/html/info.php

The content info.php is below

<?php
phpinfo();
?>

Save the changes and restart the webserver.

systemctl restart httpd

Open back browser

http://server-ip/info.php

The output is below

Remove file test PHP

rm -f /var/www/html/info.php

Conclusion

Congratulations! You’ve successfully install LAMP stack on your Rocky Linux server. You now have a powerful platform for hosting websites and web applications. Remember to secure your server, keep your software up to date, and regularly back up your data to ensure a stable and reliable web hosting environment. I hope will this your helpful. Thank you for reading the DevopsRoles page!

This comprehensive guide should equip you with the knowledge to manage and expand your LAMP stack setup. For any further customization or troubleshooting, refer to the official documentation and community forums. Happy coding!

Refer to:

Backup and restore a Postgres database

Introduction

In this tutorial, How to backup and restore a Postgres database. You have installed the PostgreSQL database system.

Why Backup Your PostgreSQL Database?

Before we dive into the how, let’s briefly discuss the importance of regular database backups:

  • Data Loss Prevention: Backups protect your data against accidental deletion, corruption, or hardware failures.
  • Disaster Recovery: In the event of a catastrophic failure or data breach, having a backup allows you to quickly recover and restore your database.
  • Testing and Development: Backups can be used to create copies of your database for testing, development, or staging purposes.

Now, let’s get started with the backup and restore process.

Backup and restore a Postgres database

Backup a PostgreSQL Database

The pg_dump command is the PostgreSQL utility for creating database backups. Here’s the basic syntax:

pg_dump -U your_postgres_user -d your_database_name -f backup_file.sql

For example: import and export my-db database as below

The output format is a plain-text SQL script file ( The default)

root@5cc6d8f56baf:/# pg_dump -h localhost -U devopsroles my-db > my-db.sql

You can compress this data by using the “custom” dump format:

# format tar
root@5cc6d8f56baf:/# pg_dump -h localhost -U devopsroles -F t my-db > my-db.tar

Backup use pg_dump via a compression tool such as gzip

root@5cc6d8f56baf:/# pg_dump -h localhost -U devopsroles my-db | gzip > my-db.gz

Backup Remote PostgreSQL Databases

pg_dump -U devopsroles -h 192.168.1.122 -p 5432 my-db > my-db.sql

To explain:

  • -U: to specify the database role name
  • -h: remote host
  • -p: port a PostgreSQL database

To back up all PostgreSQL databases

root@5cc6d8f56baf:/# pg_dumpall -h localhost -U devopsroles > all_pg_dbs.sql

Restore the dump using the psql command

pgsql -f all_pg_dbs.sql postgres

Restoring a PostgreSQL Database

You can use psql or pg_restore utilities for retore postgres databases.

For example:

root@5cc6d8f56baf:/# psql -h localhost -U devopsroles my-db < my-db.sql
root@5cc6d8f56baf:/# pg_restore -h localhost -U devopsroles -d my-db my-db.tar

Conclusion

egularly backing up and, if necessary, restoring your PostgreSQL database is essential for data protection and disaster recovery. Remember to schedule automated backups, keep your backup files in a secure location, and test your backup and restore procedures periodically to ensure they work as expected.

By following these steps, you can safeguard your data and have peace of mind knowing that your PostgreSQL database is protected against data loss and system failures.

You have Backup and restore a Postgres database. I hope will this your helpful. Thank you for reading the DevopsRoles page!