Apache – TecAdmin https://tecadmin.net How to guide for System Administrator's and Developers Thu, 15 Dec 2022 05:57:03 +0000 en-US hourly 1 https://wordpress.org/?v=6.1.1 How To Install Apache Solr 9.0 on Fedora 36/35 https://tecadmin.net/how-to-install-apache-solr-on-fedora/ https://tecadmin.net/how-to-install-apache-solr-on-fedora/#comments Mon, 23 May 2022 09:27:16 +0000 https://tecadmin.net/?p=13982 Apache Solr is an open-source search platform written on Java. Solr provides full-text search, spell suggestions, custom document ordering and ranking, Snippet generation, and highlighting. This tutorial will help you to install Apache Solr 9.0 on Fedora 36/35/34/33/32 Linux systems. Step 1 – Prerequsities Apache Solr 9.0 required the Java Runtime Environment (JRE) version 11 [...]

The post How To Install Apache Solr 9.0 on Fedora 36/35 appeared first on TecAdmin.

]]>
Apache Solr is an open-source search platform written on Java. Solr provides full-text search, spell suggestions, custom document ordering and ranking, Snippet generation, and highlighting.

This tutorial will help you to install Apache Solr 9.0 on Fedora 36/35/34/33/32 Linux systems.

Step 1 – Prerequsities

Apache Solr 9.0 required the Java Runtime Environment (JRE) version 11 or higher. If the system doesn’t have JRE installed, use the following command to install OpenJDK 17 on the Fedora system.

sudo dnf install java-17-openjdk 

You can check the installed Java version at the command line using:

java -version

openjdk 17.0.3 2022-04-19
OpenJDK Runtime Environment 21.9 (build 17.0.3+7)
OpenJDK 64-Bit Server VM 21.9 (build 17.0.3+7, mixed mode, sharing)

Step 2 – Install Apache Solr on Fedora

Now download the required Solr version from its official site or mirrors. You may also use the below command to download Apache Solr 9.0 from its official website. After that extract the installer script.

wget https://dlcdn.apache.org/solr/solr/9.0.0/solr-9.0.0.tgz 
tar xzf solr-9.0.0.tgz solr-9.0.0/bin/install_solr_service.sh --strip-components=2 

Then execute the installer script with bash shell followed with downloaded Archive file. The command will be like below:

sudo bash ./install_solr_service.sh solr-9.0.0.tgz 

This will create a user with the name solr in your system and finish the installation process. After that start the service default Solr port 8983.

Step 3 – Managing Apache Solr Service

Use the following commands to Start, Stop and check the status of the Solr service.

  • Start Solr service:
    sudo service solr start 
    
  • Stop Solr service:
    sudo service solr stop  
    
  • Restart Solr service:
    sudo service solr restart  
    
  • Check the Solr service status:
    sudo service solr status  
    
    Output
    Found 1 Solr nodes: Solr process 30891 running on port 8983 { "solr_home":"/var/solr/data", "version":"9.0.0 a4eb7aa123dc53f8dac74d80b66a490f2d6b4a26 - janhoy - 2022-05-05 01:00:08", "startTime":"2022-05-26T07:52:42.644Z", "uptime":"0 days, 0 hours, 0 minutes, 14 seconds", "memory":"61.4 MB (%12) of 512 MB"}

Step 4 – Create a New Solr Collection

Apache Solr stores values under a collection. A collection is a single logical index that uses a separate solrconfig.xml configuration file with a single index schema.

You can create a new collection using the Apache Solr command-line utility or using Solr APIs. The below command will create a new collection in Solr named mycol1.

sudo su - solr -c "/opt/solr/bin/solr create -c mycol1 -n data_driven_schema_configs" 
Output:
Created new core 'mycol1'

Step 5 – Allow Solr Access on Public Network

The default Apache Solr runs on localhost only. To allow the Solr server publically accessible over networks, edit the /etc/default/solr.in.sh configuration file.

sudo vim /etc/default/solr.in.sh 

Search for the SOLR_JETTY_HOST variable. Uncomment it by removing the starting hash (#) symbol. Set the value to “0.0.0.0”.

Installing Solr on Fedora Linux
Enable Apache Solr to Listen on Public Network

Save the configuration file and restart Solr service:

sudo service solr restart  

You also need to open the port in the system firewall. The below-mentioned command will open port 8983 in firewalld.

sudo firewall-cmd --permanent  --add-port=8983/tcp 
sudo firewall-cmd --reload 

Step 6 – Access Solr Web Admin Panel

The default Apache Solr runs on port 8983. You can access the Solr port in your web browser and you will get the Solr dashboard.

I already have mapped the domain solr.tecadmin.net with the Fedora server IP address.

  http://solr.tecadmin.net:8983/
Installing Apache Solr on Fedora
Apache Solr Dashboard

Here you can view statics of created collection in previous steps named “mycol1”. Click on “Core Selector” on the left sidebar and select created collection.

Installing Apache Solr on Fedora
Apache Solr Collection Details

Conclusion

This tutorial helped you to install Apache Solr on the Fedora Linux system.

The post How To Install Apache Solr 9.0 on Fedora 36/35 appeared first on TecAdmin.

]]>
https://tecadmin.net/how-to-install-apache-solr-on-fedora/feed/ 11
How to Install Apache ActiveMQ on Ubuntu 22.04 https://tecadmin.net/how-to-install-apache-activemq-on-ubuntu-22-04/ https://tecadmin.net/how-to-install-apache-activemq-on-ubuntu-22-04/#respond Thu, 28 Apr 2022 02:51:59 +0000 https://tecadmin.net/?p=29115 Apache ActiveMQ is an opensource message-oriented middleware (MOM) broker service written in Java programming language. It is a protocol developed by the Apache foundation that helps to send messages between different applications with additional features. This tutorial helps you to install Apache ActiveMQ on Ubuntu 22.04 LTS Linux system. Prepare Your System The ActiveMQ can [...]

The post How to Install Apache ActiveMQ on Ubuntu 22.04 appeared first on TecAdmin.

]]>
Apache ActiveMQ is an opensource message-oriented middleware (MOM) broker service written in Java programming language. It is a protocol developed by the Apache foundation that helps to send messages between different applications with additional features.

This tutorial helps you to install Apache ActiveMQ on Ubuntu 22.04 LTS Linux system.

Prepare Your System

The ActiveMQ can be configured on any system that has Java installed. So make sure that your Ubuntu 22.04 Linux system has Java installed.

You can install Java on your with the following commands.

sudo apt update 
sudo apt install default-jdk 

It’s a good practice and recommended for running applications as non-root users. To create a user on your system, type:

sudo adduser activemq

Set the password to complete the user creation.

Now, the Ubuntu 22.04 is ready for Apache ActiveMQ installation. Go through the below steps:

Install Apache ActiveMQ on Ubuntu 22.04

First of all, download the latest version of Apache ActiveMQ source code from its official download page.

As of today, ActiveMQ 5.17.0 is the latest available version, that can be downloaded with the following commands.

wget https://dlcdn.apache.org//activemq/5.17.0/apache-activemq-5.17.0-bin.tar.gz
tar xzf apache-activemq-5.17.0-bin.zip -C /opt 

Second command will extract the file at /opt/apache-activemq-5.17.0 directory.

The default ActiveMQ allows on localhost only. To enable ActiveMQ access for a local or public network, edit conf/jetty.xml configuration file.

sudo nano /opt/apache-activemq-5.17.0/conf/jetty.xml

Search for the below configuration section.

<bean id="jettyPort" class="org.apache.activemq.web.WebConsolePort" init-method="start">
             <!-- the default port number for the web console -->
        <property name="host" value="localhost"/>
        <property name="port" value="8161"/>
    </bean>

Change host value from localhost to system IP address or set 0.0.0.0 to listen on all interfaces.

Save the file and close it.

Running ActiveMQ As Systemd Service

Systemd is the default system and service manager for the latest Linux operating systems. To make the service startup easier, create a configuration file for ActiveMQ as below:

sudo nano /etc/systemd/system/activemq.service

Add the following content:

/etc/systemd/system/activemq.service
[Unit] Description=Apache ActiveMQ Message Broker After=network-online.target [Service] Type=forking User=activemq Group=activemq WorkingDirectory=/opt/apache-activemq-5.17.0/bin ExecStart=/opt/apache-activemq-5.17.0/bin/activemq start ExecStop=/opt/apache-activemq-5.17.0/bin/activemq stop Restart=on-abort [Install] WantedBy=multi-user.target

In case of a different version or location of ActiveMQ, update the configuration as per your system.

Save the file and close it.

Now reload the systemctl daemon to read the new configuration file.

sudo systemctl daemon-reload

After that, enable the ActiveMQ systemd service to auto-start on system boot. Also, start the service.

sudo systemctl enable activemq.service
sudo systemctl start activemq.service

Once the service is started, make sure that ActiveMQ service is up and running:

sudo systemctl status activemq.service
How to Install ActiveMQ on Ubuntu 22.04
Apache ActiveMQ Borker Running Service

That’s it. The Apache ActiveMQ service is up and running on Ubuntu 22.04 LTS system.

Test Installation

As the ActiveMQ installation is completed on the Ubuntu system. Let’s test if the installation is succeeded successfully.

If the UFQ firewall is active and you are accessing the Apache ActiveMQ from a remote host, make sure to open the 8161 port. You can open the UFW port with the following command.

sudo ufw allow 8161/tcp

Now, open a browser and access

  • http://server-ip:8161/
  • How to Install Apache ActiveMQ on Ubuntu 22.04
    Apache ActiveMQ Homepage

    You can access the ActiveMQ admin section with the following URL:

    • http://server-ip:8161/admin
    • Username: admin
    • Password: admin
    How to Install ActiveMQ on Ubuntu 22.04
    Apache ActiveMQ Broker Admin Interface

    Conclusion

    In this tutorial, you have learned to install the Apache ActiveMQ on the Ubuntu system. In addition, provides you the configuration to access ActiveMQ on a private or public network.

    The post How to Install Apache ActiveMQ on Ubuntu 22.04 appeared first on TecAdmin.

    ]]>
    https://tecadmin.net/how-to-install-apache-activemq-on-ubuntu-22-04/feed/ 0
    How to Install Apache, MySQL, PHP (LAMP Stack) on Ubuntu 22.04 https://tecadmin.net/how-to-install-lamp-stack-on-ubuntu-22-04/ https://tecadmin.net/how-to-install-lamp-stack-on-ubuntu-22-04/#comments Tue, 05 Apr 2022 05:09:41 +0000 https://tecadmin.net/?p=9382 Have you ever wondered how websites like WordPress, Drupal, and other content management systems even exist? How can software developers build and maintain such websites without being technical experts in website hosting technologies? The answer is LAMP. LAMP is an acronym for Linux, Apache, MySQL, and PHP. This article describes in detail how to set [...]

    The post How to Install Apache, MySQL, PHP (LAMP Stack) on Ubuntu 22.04 appeared first on TecAdmin.

    ]]>
    Have you ever wondered how websites like WordPress, Drupal, and other content management systems even exist? How can software developers build and maintain such websites without being technical experts in website hosting technologies? The answer is LAMP. LAMP is an acronym for Linux, Apache, MySQL, and PHP. This article describes in detail how to set up LAMP on the Ubuntu server. If you are a website developer or intend to become one, then you’ll find this guide useful.

    You will learn how to install the LAMP stack on your Ubuntu VPS server and begin developing dynamic websites that can be hosted on a stable, fast, and secure server environment. Let’s get started…

    Pre-Requisities

    Assuming that you have a running Ubuntu 22.04 Linux system with sudo (or root) privileged access.

    Access your system and open a terminal. It will be good to update the package manager cache and upgrade currently installed packages. To do this execute:

    sudo apt update && sudo apt upgrade 
    

    Let’s begin the LAMP (Linux, Apache, MySQL, and PHP) stack installation on Ubuntu 22.04 Jammy Jellyfish Linux system.

    Step 1: Install PHP (Programming Languege)

    First, you need to decide on the PHP version to install on your system. You can also install multiple PHP versions on a single system. Currently the repository contains PHP 5.6, PHP 7.1, 7.2, 7.3, 7.4 and PHP 8.0, 8.1. The below instruction will install PHP 8.1. Please change the version as per your requirements.

    The ondrej/php PPA contains all PHP version’s for Ubuntu systems. So add this repository in your system with command below:

    sudo add-apt-repository ppa:ondrej/php 
    

    Now update the apt cache and install PHP 8.1.

    sudo apt update 
    sudo apt install php8.1 
    

    This will install PHP on your Ubuntu system along with some useful PHP extensions.

    Step 2: Install Apache (Web Server)

    Generally, the PHP installation also installs Apache and its module on your system. Still, you can run the following commands to confirm the installations.

    sudo apt install apache2 libapache2-mod-php8.1 -y 
    

    This will install Apache and start the service.

    Now, you need to allow web server ports in the firewall. To allow ports 80 and 443 in the UFW firewall, execute the following commands.

    sudo ufw allow 80/tcp 
    sudo ufw allow 443/tcp 
    

    Open a web browser on your system and type the server’s IP in the address bar. You will get the default Apache server page

    How to Install LAMP Stack on Ubuntu 22.04
    Apache default page

    Step 3: Install MySQL (Database Server)

    The default Ubuntu repositories contain MySQL 8.0. Which can be directly installed using the package manager. To install the available MySQL server version, execute the following command.

    sudo apt-get install mysql-server 
    

    Once the installation is finished, you can secure the MySQL server by executing the following command.

    sudo mysql_secure_installation 
    

    This will ask for a few questions to secure the MySQL server.

    1. Press ‘y’ to enable validate password plugin. This will allow you to set a strict password policy for user accounts.
      VALIDATE PASSWORD COMPONENT can be used to test passwords
      and improve security. It checks the strength of password
      and allows the users to set only those passwords which are
      secure enough. Would you like to setup VALIDATE PASSWORD component?
      
      Press y|Y for Yes, any other key for No: y
      
    2. Chose the password complexity level. Read the all 3 options and choose one:
      LOW    Length >= 8
      MEDIUM Length >= 8, numeric, mixed case, and special characters
      STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
      
      Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1
      
    3. Enter a new password and re-enter it. Make sure it matches the complexity level as described above.
      New password: *************
      Re-enter new password: *************
      
    4. Press ‘y’ to continue with provided password.
      Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
      
    5. Remove default anonymous users from MySQL server:
      Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
      
    6. Disable root login from remote systems
      Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
      
    7. Remove test database form MySQL created by default during installation.
      Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
      
    8. Reload all privileges to apply the above changes immediately.
      Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
      

    You have secured the MySQL server in the LAMP stack on Ubuntu 22.04 Linux system.

    Remember that the above password set for the root accounts is used for remote users only. To log in from the same system, just type mysql on terminal.

    sudo mysql 
    
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 14
    Server version: 8.0.28-0ubuntu4 (Ubuntu)
    
    Copyright (c) 2000, 2022, Oracle and/or its affiliates.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql>
    

    Step 4: Installing Other Required Packages

    You may also need to install modules like MySQL and other extensions for PHP based on the application requirements. Use the following command to find our available PHP extensions.

    sudo apt search php8.1-* 
    

    The above command will list all available PHP7 modules for installation, Let’s begin the installation of modules.

    sudo apt install php8.1-mysql php8.1-curl php8.1-xml 
    

    Step 5: Test LAMP Setup

    You have successfully completed the installation of Apache, MySQL, and PHP on the Ubuntu 22.04 Linux system. To verify the PHP integration with Apache, create a PHP script (example: info.php) on the website document root and write the below content.

    <?php
       phpinfo();
    ?>

    Now access this file in the web browser. It will so all the details about versions and installation.

    http://server-ip-address/info.php 
    How to Setup LAMP Stack on Ubuntu 22.04
    PHP details by phpinfo() function.

    Conclusion

    This tutorial helped you to set up the LAMP stack on Ubuntu 22.04 LTS system. Now, you can host PHP-based web applications on your server.

    The post How to Install Apache, MySQL, PHP (LAMP Stack) on Ubuntu 22.04 appeared first on TecAdmin.

    ]]>
    https://tecadmin.net/how-to-install-lamp-stack-on-ubuntu-22-04/feed/ 32
    How To Disable HTTP Methods in Apache https://tecadmin.net/how-to-disable-http-methods-in-apache/ https://tecadmin.net/how-to-disable-http-methods-in-apache/#comments Thu, 30 Dec 2021 06:09:30 +0000 https://tecadmin.net/?p=28430 The HTTP methods are used to perform create, read, update, and delete (or CRUD) operations. The most common methods are POST, GET, PUT, PATCH, and DELETE. Its good practice to disable methods, which are unused and insecure like PUT, PATCH, and DELETE. This tutorial explains, how to disable HTTP methods for an apache web server. [...]

    The post How To Disable HTTP Methods in Apache appeared first on TecAdmin.

    ]]>
    The HTTP methods are used to perform create, read, update, and delete (or CRUD) operations. The most common methods are POST, GET, PUT, PATCH, and DELETE. Its good practice to disable methods, which are unused and insecure like PUT, PATCH, and DELETE.

    This tutorial explains, how to disable HTTP methods for an apache web server.

    Disable HTTP Methods in Apache

    Create a “.htaccess” file under the document root directory and add the following code. Make sure that the Apache rewrite module and .htaccess are enabled.

    RewriteEngine On
    RewriteCond %{REQUEST_METHOD} ^(HEAD|PUT|DELETE|PATCH|TRACK|OPTIONS) 
    RewriteRule .* - [F]
    

    The above configuration will disable HEAD, PUT, DELETE, PATCH, TRACK, and OPTIONS methods.

    Next, restart the Apache webserver to apply changes.

    sudo systemctl restart apache2 
    

    Verify Setup

    You can verify changes using the curl command line utility. Let’s send a request from your system to verify that the server accepts specific header requests. For example, the below command will send an “OPTIONS” request to the server.

    curl -i -X OPTIONS https://tecadmin.net 
    
    Output
    HTTP/1.1 403 Forbidden Date: Thu, 30 Dec 2021 05:50:03 GMT Server: Apache/2.4.41 (Ubuntu) Content-Length: 281 Content-Type: text/html; charset=iso-8859-1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>403 Forbidden</title> </head><body> <h1>Forbidden</h1> <p>You don't have permission to access this resource.</p> <hr> <address>Apache Server at tecadmin.net Port 443</address> </body></html>

    You will see a forbidden message in the result. This means that the Apache server rejected the OPTIONS request.

    Conclusion

    Hopefully, this article will help you disable the HTTP methods for your Apache webserver.

    The post How To Disable HTTP Methods in Apache appeared first on TecAdmin.

    ]]>
    https://tecadmin.net/how-to-disable-http-methods-in-apache/feed/ 1
    How To Setup Apache, PHP & MongoDB in Ubuntu & Debian https://tecadmin.net/how-to-setup-apache-php-mongodb-in-ubuntu/ https://tecadmin.net/how-to-setup-apache-php-mongodb-in-ubuntu/#respond Fri, 08 Oct 2021 01:44:41 +0000 https://tecadmin.net/?p=28067 MongoDB is a free open-source, schema-free, NoSQL database which is getting more popular day by day among web developers. It is a document-oriented database and is known for its processing speed. In order to use MongoDB for our projects, we will first need to install it on our system along with its dependencies and some [...]

    The post How To Setup Apache, PHP & MongoDB in Ubuntu & Debian appeared first on TecAdmin.

    ]]>
    MongoDB is a free open-source, schema-free, NoSQL database which is getting more popular day by day among web developers. It is a document-oriented database and is known for its processing speed.

    In order to use MongoDB for our projects, we will first need to install it on our system along with its dependencies and some other tools. In this post, we will learn to install and set up Apache, PHP, and MongoDB on Ubuntu and Debian operating systems.

    Installing Apache

    First of all, we will install Apache on our system. Apache is a web server software and a popular HTTP client; it helps in creating virtual hosts. To install Apache on our system we will use the below-given command:

    sudo apt update 
    sudo apt install apache2 -y 
    

    Note: The commands given in this article will work on both Ubuntu and Debian as both of them use the same package manager.

    Installing PHP

    To install PHP along with its common modules on our system we just need to run a simple command:

    sudo apt install -y php7.4 libapache2-mod-php7.4 
    

    We have installed PHP 7.4 on our system. You can install the version and the modules that you require for your project.

    Installing MongoDB

    Unfortunately, MongoDB is not available in the default repositories of Ubuntu and Debian. So we will have to first import the public key which will be used by the package management system:

    wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add - 
    

    If the terminal gives an error while executing the above-given command then you will have to install GnuPG on your system before executing this command again.

    The next step is to create a list file for your version of the operating system. As I am running Ubuntu 20.04, I will run the following command:

    echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list 
    

    For Debian 10:

    echo "deb http://repo.mongodb.org/apt/debian buster/mongodb-org/5.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list 
    

    Next, we need to reload the local package database and then install the latest stable release of Mongodb:

    sudo apt update 
    sudo apt install -y mongodb-org 
    

    This will install the MongoDB server on your system.

    Installing MongoDB PHP Module

    For the last step, we need to install the MongoDB PHP module which is required for connecting PHP with MongoDB.

    sudo apt install php7.4-mongodb 
    

    Make sure to install the MongoDB module for the same version of PHP.

    Run the following command to check the MongoDB module is enabled for the PHP CLI environment.

    php -m | grep mongo 
    
    Output
    mongodb

    Next, restart the Apache server to apply changes.

    sudo systemctl restart apache2 
    

    You can also create a phpinfo() file at the Apache document root. When you access this file in web broser,

    Mongodb Module with PHP & Apache2
    Mongodb Module with PHP & Apache2

    Conclusion

    MongoDB is a well-known, high-performance, NoSQL database. It is highly scalable and is different from Relational Database Systems such as MySQL and PostgreSQL. In this post, we learned how to install it along with its dependencies and other related tools.

    The post How To Setup Apache, PHP & MongoDB in Ubuntu & Debian appeared first on TecAdmin.

    ]]>
    https://tecadmin.net/how-to-setup-apache-php-mongodb-in-ubuntu/feed/ 0
    Common Apache Commands on Ubuntu & Debian https://tecadmin.net/common-apache-commands-on-ubuntu-debian/ https://tecadmin.net/common-apache-commands-on-ubuntu-debian/#respond Fri, 24 Sep 2021 11:40:12 +0000 https://tecadmin.net/?p=26192 Apache is the most popular web server developed by the Apache Foundation in 1995. It comes under Apache License 2.0. It is a cross-platform application available for most of the older operating systems like Linux, Windows, and macOS systems. With a 45% of market share, Apache is serving almost every second website on the internet. [...]

    The post Common Apache Commands on Ubuntu & Debian appeared first on TecAdmin.

    ]]>
    Apache is the most popular web server developed by the Apache Foundation in 1995. It comes under Apache License 2.0. It is a cross-platform application available for most of the older operating systems like Linux, Windows, and macOS systems. With a 45% of market share, Apache is serving almost every second website on the internet. Which tells its popularity between users.

    In this tutorial, we will discuss some commonly used commands for managing Apache servers on Ubuntu and Debian-based systems. This includes how to enable/disable a virtual host, module, or configuration file in the Apache server.

    1. Check Apache Version

    Use -v command-line option to check the running Apache version on Ubuntu and other Debina-based systems.

    apache2 -v 
    
    Server version: Apache/2.4.41 (Ubuntu)
    Server built:   2021-06-17T18:27:53
    

    To view the detailed infomation use capital letter -V with apache2 command.

    apache2 -V 
    

    2. Test Apache Configuration

    After making any changes in Apache configuration files, You must run a check for the syntax. Use the following command to check the syntax for all the Apache2 configuration files.

    sudo apachectl -t 
    

    If all the configuration files are correct, You will see “Syntax Ok” in the results.

    Output
    Syntax OK

    3. Enable and Disable Virtual Hosts

    The website configuration files keep information about the Apache Virtual Hosts. In the case of Debian-based systems, the actual file is created under /etc/apache2/sites-available directory.

    Then, we enable the website using a2ensite, which simply creates a symlink of that file to /etc/apache2/sites-enabled. Apache loads all the files from this directory to the environment.

    For example, if you have created a file named example.com.conf. Then use the following command.

    sudo a2ensite example.com 
    

    Similariy use a2dissite command to disbale the sites, which is already disabled.

    sudo a2dissite example.com 
    

    4. Enable and Disable Configurations

    The original configuration files are stored under /etc/apache2/sites-available/ directory. Apache read the configuration files from /etc/apache2/sites-enabled/ directory, So you need to create symbolic link of files to site-enabeld directory.

    The a2enconf command creates a symbolic link for the configuration file and a2disconf removes the symbolic link. For example to create symbolic link for the configuration file phpmyadmin.conf run:

    sudo a2enconf phpmyadmin 
    

    To deactivate the configuration just disable it by a2disconf command like:

    sudo a2disconf phpmyadmin 
    

    5. Enable and Disable Modules

    All the Apache module files are stored under /etc/apache2/mods-available/ directory. All the active modules are symlinked to /etc/apache2/mods-enabled/ directory.

    Use a2enmod command to enable a module in Apache server and a2dismod to disable the module. For example to enable rewrite module, type:

    sudo a2enmod rewrite 
    

    To disable rewrite module, run:

    sudo a2dismod rewrite 
    

    6. Manage Apache2 Service

    The latest operating systems have opted the system for managing services. You can use the systemctl command-line utility for managing the Apache service on your system.

    The following commands will stop, start, and restart the apache2 service on your system.

    sudo systemctl stop apache2  
    sudo systemctl start apache2 
    sudo systemctl restart apache2 
    

    The changes in configuration files can be reloaded in the running environment with reload option. This will not restart the Apache service.

    sudo systemctl reload apache2 
    

    Use the following command to enable or disable the apcahe2 service.

    sudo systemctl enable apache2 
    sudo systemctl disable apache2 
    

    7. Show Apache Command Help

    For more help use the -h options on command line.

    sudo apache2 -h 
    
    Output
    Usage: apache2 [-D name] [-d directory] [-f file] [-C "directive"] [-c "directive"] [-k start|restart|graceful|graceful-stop|stop] [-v] [-V] [-h] [-l] [-L] [-t] [-T] [-S] [-X] Options: -D name : define a name for use in directives -d directory : specify an alternate initial ServerRoot -f file : specify an alternate ServerConfigFile -C "directive" : process directive before reading config files -c "directive" : process directive after reading config files -e level : show startup errors of level (see LogLevel) -E file : log startup errors to file -v : show version number -V : show compile settings -h : list available command line options (this page) -l : list compiled in modules -L : list available configuration directives -t -D DUMP_VHOSTS : show parsed vhost settings -t -D DUMP_RUN_CFG : show parsed run settings -S : a synonym for -t -D DUMP_VHOSTS -D DUMP_RUN_CFG -t -D DUMP_MODULES : show all loaded modules -M : a synonym for -t -D DUMP_MODULES -t -D DUMP_INCLUDES: show all included configuration files -t : run syntax check for config files -T : start without DocumentRoot(s) check -X : debug mode (only one worker, do not detach)

    Conclusion

    In this beginners guide, you have learned about basic commands to manage Apache server via command line.

    The post Common Apache Commands on Ubuntu & Debian appeared first on TecAdmin.

    ]]>
    https://tecadmin.net/common-apache-commands-on-ubuntu-debian/feed/ 0
    How to Install and Secure Apache on Debian11 https://tecadmin.net/how-to-install-apache-on-debian-11/ https://tecadmin.net/how-to-install-apache-on-debian-11/#comments Fri, 03 Sep 2021 04:46:16 +0000 https://tecadmin.net/?p=27622 Apache HTTP web server is one of the widely used web servers especially on Linux distributions which is a free, cross-platform used by a vast number of websites on the internet. Apache webserver uses HTTP to process the request and entertain web information. Apache has tons of useful features and its functionality can be enhanced [...]

    The post How to Install and Secure Apache on Debian11 appeared first on TecAdmin.

    ]]>
    Apache HTTP web server is one of the widely used web servers especially on Linux distributions which is a free, cross-platform used by a vast number of websites on the internet. Apache webserver uses HTTP to process the request and entertain web information. Apache has tons of useful features and its functionality can be enhanced with extra modules. It also allows programmers to publish their work on the internet.

    So, in this article, we will discuss the installation of the Apache web server and how to secure it after installation on Debian 11.

    Requirements

    Before installation, you must be logged into the Debian System with access to all sudo privileges. We also recommend completing the initial server setup on newly install Debian 11 systems.

    Step 1 – Installing Apache on Debian

    The latest version of Apache packages is available under the default Debian 11 repository. So we can directly install it using the packages manager.

    After login, open the terminal and update apt cache by below mentioned command:

    sudo apt update 
    

    After updating of apt cache, now install the Apache2 on your Debian 11 Bullseye by the command:

    sudo apt install apache2 
    

    Press “y” for any confirmation prompted by the installer.

    Once the installation process completed. Verify the installed Apache version by running the following command:

    apache2 -v 
    
    Output:
    Server version: Apache/2.4.48 (Debian) Server built: 2021-08-12T11:51:47

    Another way to verify the installation of Apache is by accessing the Apache2 default page using your Server’s IP Address or hostname. If you don’t know your hostname then run the below-mentioned command first:

    hostname -I 
    
    Check IP Address of Local system
    Check IP Address of Local System

    Enter your Server’s hostname or IP address in the URL bar of the browser and press Enter, Apache2 Debian Default page will open as shown below:

    Apache default page on Debian 11
    Apache default page on Debian 11

    Step 2 – Managing the Apache Service

    After successful installation, Apache service can be managed using “systemctl” commands, run the below-mentioned command to check the status of the server:

    sudo systemctl status apache2.service 
    
    Check Apache Service Status on Debian 11
    Check Apache Service Status on Debian 11

    Press “q” to quit. Few commands to manage Apache Service in Debian 11 are:

    To start the server use the command:

    sudo systemctl start apache2.service 
    

    Similarly, to stop service, replace start with a stop in the above command:

    sudo systemctl stop apache2.service 
    

    The service can be restarted using:

    sudo systemctl restart apache2.service 
    

    Step 3 – Configuring Firewall Settings

    If your system has a firewall, you’ll need to authorize access to certain web ports so that external users can utilize them. Run the below-mentioneds command to allow port 80 (HTTP) and 443 (HTTPS) in the Debian terminal:

    sudo ufw allow 80/tcp 
    sudo ufw allow 443/tcp 
    
    Allow HTTP and HTTPS port in UFW
    Allow HTTP and HTTPS port in UFW

    Now verify by checking the status:

    sudo ufw status 
    

    if it is not active, to enable its to use:

    sudo ufw enable 
    

    Step 4 – Creating Virtual Host in Apache

    In Apache, virtual hosts allow you to operate numerous websites on a single server. In the Apache web server, we’ll create a virtual host. To accomplish it, we’ll first create a website called sample.com with the server block that comes standard with Apache.

    Let’s start by setting up your Apache server’s first virtual host. We’ll use the sample domain as “sample.com”, but you can name it according to your preference:

    sudo mkdir -p /var/www/sample.com 
    

    Now change the permissions and owner by below-mentioned command:

    sudo chown -R www-data:www-data /var/www/sample.com 
    sudo chmod -R 755 /var/www/sample.com 
    

    Running below-mentioned command, to test our testdomain.info site, we’ll now construct an example index page. To accomplish so, we’ll use the nano editor to generate an HTML file that looks like this:

    sudo nano /var/www/sample.com/index.html 
    

    Insert the below mentioned content into index page and press Ctrl+O to save the file an Ctrl+X to exit the file and return to terminal:

    <html>
     <head>
       <title>Welcome to the page sample.com!</title>
     </head>
     <body>
       <h1>Congratulations! Your sample.com server succeeded!</h1>
     </body>
    </html>

    Running the below-mentioned command in a terminal, we’ll build a virtual host file, which will serve the content of server:

    sudo nano /etc/apache2/sites-available/sample.com.conf 
    

    A text file will be open, insert the following content:

    <VirtualHost *:80>
      ServerAdmin admin@sample.com
      ServerName sample.com
      ServerAlias www.sampe.com
      DocumentRoot /var/www/sample.com
      ErrorLog ${APACHE_LOG_DIR}/error.log
      CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>

    Press Ctrl+O to save the file and Ctrl+X to exit the file and return to the terminal.

    Step 5 – Enabling the Domain Configuration

    Run the following command to turn on the virtual host file:

    sudo a2ensite sample.com.conf 
    

    Disable the default Apache Configuration by running below mentioned command:

    sudo a2dissite 000-default.conf 
    

    New changes to Apache are made applicable by running below mentioned command:

    sudo systemctl restart apache2 
    

    Step 6 – Resolve Hostname Error

    Now, we have to check our configuration for any syntax error, for testing configuration run the below-mentioned command:

    sudo apache2ctl configtest 
    
    Could not resolve system hotname
    Could not resolve system hotname issue with Apache

    This will cause an error but don’t worry we will resolve this. Create a new configuration “servername.conf” and edit in a text editor:

    sudo nano /etc/apache2/conf-avaialable/servername.conf 
    

    Now insert the following content into the file:

    ServerName sample.com
    

    Press Ctrl+O to save the file and Ctrl+X to exit the file. Make sure to change “sample.com” with your actual domain name. Now to enable the conf server name run the below-mentioned command:

    sudo a2enconf servername 
    

    Now again run the above command to test configuration:

    sudo apache2ctl configtest 
    

    You will see that the hostname error is resolved now.

    Step 7 – How to secure Apache2 on Debian 11

    To secure the Apache server, edit the “security.conf” file, run the below-mentioned command to open the file:

    sudo nano /etc/apache2/conf-enabled/security.conf 
    

    Insert or update the below content into the file:

    ServerTokens Prod
    ServerSignature Off
    TraceEnable Off
    Header always append X-Frame-Options SAMEORIGIN
    Header always set X-XSS-Protection: "1; mode=block"
    Header always set X-Content-Type-Options: "nosniff"
    Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
    Header always edit Set-Cookie ^(.*)$ $1;HttpOnly;Secure

    Save the file and close it.

    Set the server-wide SSLCipherSuite and SSL protocol to use secure ciphers to serve the website by editing ssl.conf file:

    sudo nano /etc/apache2/mods-enabled/ssl.conf 
    

    Now insert the below-written content into the file and press Ctrl+O to save the file and Ctrl+X to exit the file:

    SSLProtocol -all +TLSv1.2
    SSLCipherSuite HIGH:!aNULL:!MD5

    Now run the reload command of Apache to save configuration:

    sudo systemctl restart apache2.service 
    

    That’s it. You have successfully installed and secured the Apache server.

    Conclusion

    Apache Web Server is an open-source server used by many websites on the internet and allows developers to publish their work on the internet. This server is available on all OS but in this article, we discuss its installation on the latest version of Debian (Linux OS) and also tell how to test and secure it after its successful installation. You will be able to successfully install Apache2 on Debian 11 Bullseye and configure the server after going through this guide.

    The post How to Install and Secure Apache on Debian11 appeared first on TecAdmin.

    ]]>
    https://tecadmin.net/how-to-install-apache-on-debian-11/feed/ 3
    How To Enable Brotli Compression in Apache https://tecadmin.net/how-to-enable-brotli-compression-in-apache/ https://tecadmin.net/how-to-enable-brotli-compression-in-apache/#comments Thu, 01 Jul 2021 09:44:53 +0000 https://tecadmin.net/?p=26417 Just like Gzip, Brotli is also a generic-purpose compression algorithm developed by Google. It compresses data using a combination of modern technologies and algorithms. It is similar in speed to deflate but provides higher compression. Brotli compression is supported by all the major browsers like Chrome, Firefox, Safari, Edge. The Brotli compression is opted by [...]

    The post How To Enable Brotli Compression in Apache appeared first on TecAdmin.

    ]]>
    Just like Gzip, Brotli is also a generic-purpose compression algorithm developed by Google. It compresses data using a combination of modern technologies and algorithms. It is similar in speed to deflate but provides higher compression. Brotli compression is supported by all the major browsers like Chrome, Firefox, Safari, Edge.

    The Brotli compression is opted by the top tech fortunes like Cloudflare etc. This is the reason, we recommend switching to brotli from the old deflate data compression algorithm.

    This tutorial helps you to enable brotli compression in the Apache webserver.

    Prerequisites

    Shell access to your server with sudo privileged account.

    We assume that you already have a running Apache server. Also created a virtual host for the web application.

    Step 1 – Installing Brotli

    First, install the brotli package on your system. For the Ubuntu and Debian systems, it’s available in the default repositories.

    Open a terminal and type:

    sudo apt install brotli -y 
    

    This will install the required package containing the algorithm files on your system.

    Step 2 – Configure Brotli with Apache

    The Apache server contains the Brotli module default. You can enable the brotli module in Apache with the following command.

    sudo a2enmod brotli 
    

    Next, you have to configure the Apache virtual host to enable compression with brotli. You need to add the below code in the virtual host configuration file.

    <IfModule mod_brotli.c>
        AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/xml text/css text/javascript application/javascript
    </IfModule>

    After enabling the brotli compression the Virtual host configuration file looks like below:

    <VirtualHost *:80>
          ServerAdmin webmaster@localhost
          ServerName example.com
          DocumentRoot /var/www/
    
          <IfModule mod_brotli.c>
                AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/xml text/css text/javascript application/javascript
          </IfModule>
    	
          ErrorLog ${APACHE_LOG_DIR}/error.log
          CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>

    Save the configuration file and close it. Then reload the Apache service to apply changes.

    sudo systemctl restart apache2 
    

    That’s it. You have successfully enabled brotli compression in the Apache server.

    Step 3 – Test Compression

    Access your web application in a browser and check headers value in the browser console. You need to search for the Content-Encoding value. It must contain br as value, which denotes that the web page is compressed with brotli compression.

    The command line heroes can also use curl command to access the header values as below:

    curl -I -H 'Accept-Encoding: br' http://example.com 
    

    You will see the result below.

    HTTP/1.1 200 OK
    Date: Thu, 01 Jul 2021 06:26:54 GMT
    Server: Apache/2.4.41 (Ubuntu)
    Upgrade: h2,h2c
    Connection: Upgrade
    Last-Modified: Fri, 05 Feb 2021 08:55:44 GMT
    ETag: "33-5ba92fc4cecdf-br"
    Accept-Ranges: bytes
    Vary: Accept-Encoding
    Content-Encoding: br
    Content-Length: 46
    Content-Type: text/html
    

    Check for the value of Content-Encoding option.

    Conclusion

    This tutorial helped you to configure Brotli compression in the Apache webserver.

    The post How To Enable Brotli Compression in Apache appeared first on TecAdmin.

    ]]>
    https://tecadmin.net/how-to-enable-brotli-compression-in-apache/feed/ 2
    How to Install Tomcat 10 on Ubuntu 20.04 https://tecadmin.net/how-to-install-tomcat-10-on-ubuntu-20-04/ https://tecadmin.net/how-to-install-tomcat-10-on-ubuntu-20-04/#comments Wed, 17 Mar 2021 15:15:16 +0000 https://tecadmin.net/?p=24944 Apache Tomcat is an open-source web server with a servlet container for publishing Java-based web applications. Tomcat is developed and maintained by an open community of developers under the auspices of the Apache Software Foundation. As of today, Tomcat 10 is the latest stable version available for installation on development and production environments. To know [...]

    The post How to Install Tomcat 10 on Ubuntu 20.04 appeared first on TecAdmin.

    ]]>
    Apache Tomcat is an open-source web server with a servlet container for publishing Java-based web applications. Tomcat is developed and maintained by an open community of developers under the auspices of the Apache Software Foundation. As of today, Tomcat 10 is the latest stable version available for installation on development and production environments. To know more about the Apache Tomcat visit apache official site http://tomcat.apache.org/.

    This tutorial will help you to how to install Apache Tomcat 10 on Ubuntu 20.04 LTS Linux systems.

    Prerequisites

    A running Ubuntu 20.04 system with shell access of root or sudo privileged account access.

    For the newly installed systems recommended to complete initial server setup instructions.

    Step 1 – Install Java

    You must have JRE (Java runtime environment) installed on your system. Tomcat 10 is required to have JRE 8 or higher version installed on your system. Use the following command to install OpenJDK to fulfil the requirements.

    sudo apt update 
    sudo apt install default-jdk -y 
    

    Check the current active Java version:

    java -version 
    
    openjdk 11.0.13 2021-10-19
    OpenJDK Runtime Environment (build 11.0.13+8-Ubuntu-0ubuntu1.20.04)
    OpenJDK 64-Bit Server VM (build 11.0.13+8-Ubuntu-0ubuntu1.20.04, mixed mode, sharing)
    

    Step 2 – Create Tomcat User

    We recommended running a Tomcat server with a dedicated user account. Create a new user, which is recommended for security purposes mainly for production deployments.

    To create a new account, type:

    sudo useradd -m -d /opt/tomcat -U -s /bin/false tomcat 
    

    The above command will create a user and group with the name “tomcat” in your system.

    Step 3 – Install Tomcat 10

    The Apache Tomcat development team releases the latest version of Tomcat from time to time. So it will be good check download latest Tomcat version from the official download server. Use the below command to download Tomcat 10.

    wget https://dlcdn.apache.org/tomcat/tomcat-10/v10.0.23/bin/apache-tomcat-10.0.23.tar.gz 
    

    Once the download is completed, extracted the downloaded archive and copy all content to the tomcat home directory.

    sudo tar xzvf apache-tomcat-10*tar.gz -C /opt/tomcat --strip-components=1 
    

    Next, set the proper file permissions.

    sudo chown -R tomcat:tomcat /opt/tomcat/ 
    sudo chmod -R u+x /opt/tomcat/bin 
    

    You have now the latest Tomcat application on your system.

    Step 4 – Create Tomcat User

    Now, configure your tomcat with user accounts to secure access of admin/manager pages. To do this, edit conf/tomcat-users.xml file in your editor and paste the following code inside <tomcat-users> </tomcat-users> tags. We recommend changing the password in the below configuration with high secured password.

    sudo nano /opt/tomcat/conf/tomcat-users.xml 
    

    Add the following values. Make sure to change the password for admin and manager access.

    <!-- user manager can access only manager section -->
    <role rolename="manager-gui" />
    <user username="manager" password="_SECRET_PASSWORD_" roles="manager-gui" />
    
    <!-- user admin can access manager and admin section both -->
    <role rolename="admin-gui" />
    <user username="admin" password="_SECRET_PASSWORD_" roles="manager-gui,admin-gui" />
    

    Save file and close.

    Step 5 – Enable Remote Tomcat Access

    The default Tomcat manager and host-manager applications are accessible for localhost only. To allow access to these pages from the remote system, you need to modify the following configuration files.

    You can either allow a specific remote system or allow all. Edit the context.xml file for manager and host manager application:

    sudo nano /opt/tomcat/webapps/manager/META-INF/context.xml
    

    Comment out the section added for IP address restriction to allow connections from anywhere.

    <Context antiResourceLocking="false" privileged="true" >
      <CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor"
                       sameSiteCookies="strict" />
      <!-- <Valve className="org.apache.catalina.valves.RemoteAddrValve"
             allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /> -->
      ...
    </Context>
    

    Similarly edit context.xml for host manager application in text editor:

    sudo nano /opt/tomcat/webapps/host-manager/META-INF/context.xml
    

    Comment out the same section to allow connections from anywhere.

    <Context antiResourceLocking="false" privileged="true" >
      <CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor"
                       sameSiteCookies="strict" />
      <!--<Valve className="org.apache.catalina.valves.RemoteAddrValve"
             allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /> -->
      ...
    </Context>
    

    Save all files and close it.

    Step 6 – Create a Tomcat Systemd Unit File

    Tomcat provides bash scripts to start, stop service. But, to make it simple, create a startup script to manage Tomcat as systemd service. Let’s create a tomcat.service file with the following content:

    sudo nano /etc/systemd/system/tomcat.service 
    
    [Unit]
    Description=Tomcat
    After=network.target
    
    [Service]
    Type=forking
    
    User=tomcat
    Group=tomcat
    
    Environment="JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64"
    Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom"
    Environment="CATALINA_BASE=/opt/tomcat"
    Environment="CATALINA_HOME=/opt/tomcat"
    Environment="CATALINA_PID=/opt/tomcat/temp/tomcat.pid"
    Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"
    
    ExecStart=/opt/tomcat/bin/startup.sh
    ExecStop=/opt/tomcat/bin/shutdown.sh
    
    [Install]
    WantedBy=multi-user.target
    

    Reload the systemd daemon service to load newly create files.

    sudo systemctl daemon-reload 
    

    Now, start the Tomcat application for the first time.

    sudo systemctl start tomcat.service 
    

    Next, enable the tomcat service to auto-start for subsequent system boots. This is more important for the production deployments.

    sudo systemctl enable tomcat.service 
    

    As of now, the tomcat application is running on your system. You can verify the service status by executing the command as below. Make sure the status is showing “active (running)“.

    sudo systemctl status tomcat.service 
    
    ● tomcat.service - Tomcat
         Loaded: loaded (/etc/systemd/system/tomcat.service; enabled; vendor preset: enabled)
         Active: active (running) since Wed 2021-03-17 10:56:39 IST; 3h 45min ago
        Process: 481049 ExecStart=/opt/tomcat/bin/startup.sh (code=exited, status=0/SUCCESS)
       Main PID: 481056 (java)
          Tasks: 29 (limit: 4539)
         Memory: 264.2M
         CGroup: /system.slice/tomcat.service
                 └─481056 /usr/lib/jvm/java-1.11.0-openjdk-amd64/bin/java -Djava.util.logging.config.file>
    
    Mar 17 10:56:39 tecadmin-ubuntu2004 systemd[1]: Starting Tomcat...
    Mar 17 10:56:39 tecadmin-ubuntu2004 startup.sh[481049]: Tomcat started.
    Mar 17 10:56:39 tecadmin-ubuntu2004 systemd[1]: Started Tomcat.
    

    Step 7 – Access the Tomcat Web Interface

    The default Tomcat server runs on port 8080. As you have configured Tomcat on your system, you can access web interface from your system. You can access tomcat interfaces by entering your server’s IP address or a domain name pointed to that server, followed by port 8080 in your browser:

    Change tecadmin.local with your server ip or domain or localhost.

    http://tecadmin.local:8080/
    

    You will see the page like below:

    Installing Tomcat 10

    Tomcat Manager App is a web application packaged with the Tomcat server application. The Manager interface provides us with the basic functionality we need to manage our deployed web applications.

    Click Manager App button home page or directly type /manager in browser url of main Tomcat server to access it.

    http://tecadmin.local:8080/manager/
    

    Tomcat 10 Manager Dashboard

    Tomcat Host Manager App is another web application packaged with Tomcat server application. Which is used to creates/removes Virtual Hosts within the Tomcat service. A Virtual Host allows you to define multiple hostnames on a single server.

    Click Host Manager button home page or directly type /host-manager url in main Tomcat server to access it.

    http://tecadmin.local:8080/host-manager/
    

    Tomcat 10 Host Manager Page

    Conclusion

    You have a running Tomcat server on Ubuntu system. You may need to create a Virtual host or configure a SSL certificate in Tomcat.

    The post How to Install Tomcat 10 on Ubuntu 20.04 appeared first on TecAdmin.

    ]]>
    https://tecadmin.net/how-to-install-tomcat-10-on-ubuntu-20-04/feed/ 5
    How to Install Apache Kafka on Ubuntu 20.04 https://tecadmin.net/how-to-install-apache-kafka-on-ubuntu-20-04/ https://tecadmin.net/how-to-install-apache-kafka-on-ubuntu-20-04/#comments Sun, 14 Feb 2021 16:40:56 +0000 https://tecadmin.net/?p=23427 Apache Kafka is an open-source, distributed event streaming platform developed by the Apache Software Foundation. This is written in Scala and Java programming languages. You can install Kafka on any platform supporting Java. This tutorial described you step-by-step tutorial to install Apache Kafka on Ubuntu 20.04 LTS Linux system. You will also learn to create [...]

    The post How to Install Apache Kafka on Ubuntu 20.04 appeared first on TecAdmin.

    ]]>
    Apache Kafka is an open-source, distributed event streaming platform developed by the Apache Software Foundation. This is written in Scala and Java programming languages. You can install Kafka on any platform supporting Java.

    This tutorial described you step-by-step tutorial to install Apache Kafka on Ubuntu 20.04 LTS Linux system. You will also learn to create topics in Kafka and run producer and consumer nodes.

    Prerequisites

    You must have sudo privileged account access to the Ubuntu 20.04 Linux system.

    Step 1 – Installing Java

    Apache Kafka can be run on all platforms supported by Java. In order to set up Kafka on the Ubuntu system, you need to install java first. As we know, Oracle java is now commercially available, So we are using its open-source version OpenJDK.

    Execute the below command to install OpenJDK on your system from the official PPA’s.

    sudo apt update 
    sudo apt install default-jdk
    

    Verify the current active Java version.

    java --version 
    
    openjdk version "11.0.9.1" 2020-11-04
    OpenJDK Runtime Environment (build 11.0.9.1+1-Ubuntu-0ubuntu1.20.04)
    OpenJDK 64-Bit Server VM (build 11.0.9.1+1-Ubuntu-0ubuntu1.20.04, mixed mode, sharing)
    

    Step 2 – Download Latest Apache Kafka

    Download the Apache Kafka binary files from its official download website. You can also select any nearby mirror to download.

    wget https://dlcdn.apache.org/kafka/3.2.0/kafka_2.13-3.2.0.tgz 
    

    Then extract the archive file

    tar xzf kafka_2.13-3.2.0.tgz 
    sudo mv kafka_2.13-3.2.0 /usr/local/kafka 
    

    Step 3 – Creating Systemd Unit Files

    Now, you need to create systemd unit files for the Zookeeper and Kafka services. Which will help you to start/stop the Kafka service in an easy way.

    First, create a systemd unit file for Zookeeper:

    vim /etc/systemd/system/zookeeper.service
    

    And add the following content:

    [Unit]
    Description=Apache Zookeeper server
    Documentation=http://zookeeper.apache.org
    Requires=network.target remote-fs.target
    After=network.target remote-fs.target
    
    [Service]
    Type=simple
    ExecStart=/usr/local/kafka/bin/zookeeper-server-start.sh /usr/local/kafka/config/zookeeper.properties
    ExecStop=/usr/local/kafka/bin/zookeeper-server-stop.sh
    Restart=on-abnormal
    
    [Install]
    WantedBy=multi-user.target
    

    Save the file and close it.

    Next, to create a systemd unit file for the Kafka service:

    vim /etc/systemd/system/kafka.service
    

    Add the below content. Make sure to set the correct JAVA_HOME path as per the Java installed on your system.

    [Unit]
    Description=Apache Kafka Server
    Documentation=http://kafka.apache.org/documentation.html
    Requires=zookeeper.service
    
    [Service]
    Type=simple
    Environment="JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64"
    ExecStart=/usr/local/kafka/bin/kafka-server-start.sh /usr/local/kafka/config/server.properties
    ExecStop=/usr/local/kafka/bin/kafka-server-stop.sh
    
    [Install]
    WantedBy=multi-user.target
    

    Save the file and close.

    Reload the systemd daemon to apply new changes.

    systemctl daemon-reload
    

    Step 4 – Start Kafka and Zookeeper Service

    First, you need to start the ZooKeeper service and then start Kafka. Use the systemctl command to start a single-node ZooKeeper instance.

    sudo systemctl start zookeeper
    

    Now start the Kafka server and view the running status:

    sudo systemctl start kafka
    sudo systemctl status kafka
    

    Kafka service on ubuntu

    All done. The Kafka installation has been successfully completed. The part of this tutorial will help you to work with the Kafka server.

    Step 5 – Create a Topic in Kafka

    Kafka provides multiple pre-built shell scripts to work on it. First, create a topic named “testTopic” with a single partition with a single replica:

    cd /usr/local/kafka
    bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic testTopic
    
    Created topic testTopic.
    

    The replication factor describes how many copies of data will be created. As we are running with a single instance keep this value 1.

    Set the partition options as the number of brokers you want your data to be split between. As we are running with a single broker keep this value 1.

    You can create multiple topics by running the same command as above. After that, you can see the created topics on Kafka by the running below command:

    bin/kafka-topics.sh --list --bootstrap-server localhost:9092
    
    [output]
    testTopic
    

    Alternatively, instead of manually creating topics you can also configure your brokers to auto-create topics when a non-existent topic is published to.

    Step 6 – Send and Receive Messages in Kafka

    The “producer” is the process responsible for put data into our Kafka. The Kafka comes with a command-line client that will take input from a file or from standard input and send it out as messages to the Kafka cluster. The default Kafka sends each line as a separate message.

    Let’s run the producer and then type a few messages into the console to send to the server.

    bin/kafka-console-producer.sh --broker-list localhost:9092 --topic testTopic
    
    >Welcome to kafka
    >This is my first topic
    >
    

    You can exit this command or keep this terminal running for further testing. Now open a new terminal to the Kafka consumer process on the next step.

    Step 7 – Using Kafka Consumer

    Kafka also has a command-line consumer to read data from the Kafka cluster and display messages to standard output.

    bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic testTopic --from-beginning
    
    Welcome to kafka
    This is my first topic
    

    Now, If you have still running Kafka producer (Step #6) in another terminal. Just type some text on that producer terminal. it will immediately be visible on the consumer terminal. See the below screenshot of the Kafka producer and consumer in working:

    Conclusion

    This tutorial helped you to install and configure the Apache Kafka service on an Ubuntu system. Additionally, you learned to create a new topic in the Kafka server and run a sample production and consumer process with Apache Kafka.

    The post How to Install Apache Kafka on Ubuntu 20.04 appeared first on TecAdmin.

    ]]>
    https://tecadmin.net/how-to-install-apache-kafka-on-ubuntu-20-04/feed/ 6