Daily Archives: 11 February, 2021

Ubuntu 17.10 Install google’s mod pagespeed for apache

About this article
One of the more recently popular modules for Apache is mod_pagespeed. It is an output filter for Apache 2.2+ that can be configured through a variety of options through configuration files or a .htaccess file. An “output filter” is a something that transforms the data before it’s sent to the client. In other words, it’s a layer between your website and what the user’s browser receives when they visit your URL. Speed Up the Web The goal of mod_pagespeed is to speed up your website. It does this by applying filters to a variety of files in order to reduce the number of trips the browser has to make to grab what it needs, to reduce the size of those files and to optimize the length those files are cached.

Installation is very simple. It’ll vary depending on the operating system you use. Ubuntu and Debian have packages you can download and install (or any Linux distribution that uses .DEB packages). Other Linux distributions can download the source and build from that.

Download Software

wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_amd64.deb wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_i386.deb
Code language: JavaScript (javascript)

Install

sudo dpkg -i mod-pagespeed-*.deb apt-get -f install rm mod-pagespeed-*.deb
Code language: Bash (bash)

The module enables itself automatically when installed. However, you must restart Apache for it to start working.

service apache2 restart or /etc/init.d/apache2 restart
Code language: Bash (bash)

You should now have a working version of mod_pagespeed up and running on your VPS. You can check this by looking at your page’s response headers. There should be a value for “X-Mod-Pagespeed” with the version number you installed. Setup The installation package handles a lot of configuration out-of-the-box. In fact, there are conservative defaults that are automatically enabled on Apache. Depending on the Apache version you’re running, you’ll get a different version of the module installed and enabled. If you’re running Apache 2.2, mod_pagespeed.so will be installed; Apache 2.4 users will use mod_pagespeed_ap24.so. Note: mod_pagespeed only works with Apache 2.2 and greater. There is also a bug with Apache 2.4.1 that prevents it from working with that version. Apache 2.4.2 or greater should be used. Additionally, configuration files have been added to your Apache installation. The primary configuration file is pagespeed.conf. This file is located at: /etc/apache2/mods-available/

How to configure mod_pagespeed? You can use whatever text editor you want to edit the configuration file. For this tutorial, we’ll be using nano. To start editing the main configuration file, use the following command:

pico /etc/apache2/mods-available/pagespeed.conf

How to check network speed with speedtest.net and terminal

To install the tool, speedtest-cli:

1.) First install python-pip, a tool for installing and managing Python packages. To do so, run below command:

sudo apt-get install python-pip
Code language: Bash (bash)

2.) Install speedtest-cli via python-pip:

sudo pip install speedtest-cli
Code language: Bash (bash)

Once installed, you can use one command to test your internet bandwidth. The command is: speedtest

You’ll see the similar output, which display you internet bandwidth as well as ISP & IP address.

Retrieving speedtest.net configuration… Retrieving speedtest.net server list… Testing from M-net Telekommunikations GmbH (88.217.180.40)… Selecting best server based on ping… Hosted by InterNetX GmbH (Munich) [2.23 km]: 18.756ms Testing download speed…………………………………. Download: 7.81 Mbit/s Testing upload speed………………………………………….. Upload: 3.46 Mbit/s
Code language: Bash (bash)

How to increase SSH Connection timeout

/etc/ssh_config is the client side configuration file not the server side config file.

To prevent all your clients from timing out you need to edit /etc/sshd_config which is the server side configuration file add these two options: We edit the file sshd_config, we find this two commented lines and edit them as follows.

ClientAliveInterval 120
ClientAliveCountMax 720

The first one configures the server to send null packets to clients each 120 seconds and the second one configures the server to close the connection if the client has been inactive for 720 intervals that is 720*120 = 86400 seconds = 24 hours

How to use tail Command to See Logs In Real Time

About tail command
tail outputs the last part, or “tail”, of files. It can also monitor new information written to the file in real time, displaying the newest entries in a system log, for example.


Syntax
tail [{-c |–bytes=}num] [-f] [–follow[={name|descriptor}]]
[-F] [{-n |–lines=}num] [–max-unchanged-stats[=num]]
[–pid=pid] [{-p|–quiet|–silent}] [–retry]
[{-s |–sleep-interval=}num] [{-v|–verbose}] [file …]


Monitoring ssh log via tail
tail -f /var/log/auth.log


Output:
root@webleit:~# ./tail-auth-log
Feb 23 13:16:36 webleit sshd[5526]: Received disconnect from 172.92.151.71 port 55252:11: Bye Bye [preauth]
Feb 23 13:16:36 webleit sshd[5526]: Disconnected from invalid user 172.92.151.71 port 55252 [preauth]
Feb 23 13:17:01 webleit CRON[5528]: pam_unix(cron:session): session opened for user root by (uid=0)
Feb 23 13:17:01 webleit CRON[5528]: pam_unix(cron:session): session closed for user root
Feb 23 13:25:12 webleit sudo: root : TTY=pts/0 ; PWD=/root ; USER=root ; COMMAND=/bin/su
Feb 23 13:25:12 webleit sudo: pam_unix(sudo:session): session opened for user root by sonik(uid=0)
Feb 23 13:25:12 webleit su[5551]: Successful su for root by root
Feb 23 13:25:12 webleit su[5551]: + /dev/pts/0 root:root
Feb 23 13:25:12 webleit su[5551]: pam_unix(su:session): session opened for user root by sonik(uid=0)
Feb 23 13:25:12 webleit su[5551]: pam_systemd(su:session): Cannot create session: Already running in a session

Hddtemp crontab every hour in to file

hddtemp is a small utility (with daemon) that gives the hard-drive temperature via S.M.A.R.T. (for drives supporting this feature).
In this article we are going to create a txt file and in it we are going to store the hdd temperature for every hour.


Install:
apt-get install hddtemp


Configuration:
crontab -e
* * * * echo `date`,`/usr/sbin/hddtemp /dev/sda` >> /root/hddtemp.txt
pico /root/hddtemp.txt


Test
tail -f /root/hddtmep.txt

Install GoAccess Apache Log Analyzer Tool on Ubuntu 17.10

What is it?
GoAccess is an open source real-time web log analyzer and interactive viewer that runs in a terminal in *nix systems or through your browser. It provides fast and valuable HTTP statistics for system administrators that require a visual server report on the fly.
GoAccess was designed to be a fast, terminal-based log analyzer. Its core idea is to quickly analyze and view web server statistics in real time without needing to use your browser (great if you want to do a quick analysis of your access log via SSH, or if you simply love working in the terminal).
While the terminal output is the default output, it has the capability to generate a complete, self-contained real-time HTML report (great for analytics, monitoring and data visualization), as well as a JSON, and CSV report.
Install Required Dependencies
sudo apt-get -y install libncursesw5-dev gcc make libgeoip-dev libtokyocabinet-dev build-essential -y


Install GoAccess
wget http://tar.goaccess.io/goaccess-1.2.tar.gz
tar -xzvf goaccess-1.2.tar.gz
cd goaccess-1.2
sudo ./configure –enable-utf8 –enable-geoip=legacy
sudo make
sudo make install


Use GoAccess
sudo goaccess /var/log/apache2/access.log –log-format=COMBINED
sudo goaccess /var/log/apache2/access.log –log-format=COMBINED -a -o /var/www/html/report.html

Apache CouchDB NOSQL database solution

CouchDB is a free and an open source NOSQL database solution implemented in the concurrency-oriented language Erlang. It has a document-oriented NoSQL database architecture. It uses JSON to store data, JavaScript as its query language using MapReduce, and HTTP for an API. CouchDB implements a form of multi-version concurrency control, so it does not lock the database file during writes. You can use CouchDB in mobile devices for replication and synchronization.


A No SQL (originally referring to “non SQL” or “non relational”) database provides a mechanism for storage and retrieval of data that is modeled in means other than the tabular relations used in relational databases. Such databases have existed since the late 1960s, but did not obtain the “No SQL” moniker until a surge of popularity in the early twenty-first century, triggered by the needs of Web 2.0 companies such as Facebook, Google, and Amazon. No SQL databases are increasingly used in big data and real-time web applications. No SQL systems are also sometimes called “Not only SQL” to emphasize that they may support SQL-like query languages

Make Browsers Cache Static Files With mod_expires On Apache2 Ubuntu 18.04

If you have tested your website for speed with googles website test tool then you have seen the error: Leverage browser caching not enabled. To fix this you need to enable and configure mod_expires on Apache2. This will make your website faster and better and meet the requirements of google website page speed.


This module controls the setting of the Expires HTTP header and the max-age directive of the Cache-Control HTTP header in server responses. The expiration date can set to be relative to either the time the source file was last modified, or to the time of the client access.


These HTTP headers are an instruction to the client about the document’s validity and persistence. If cached, the document may be fetched from the cache rather than from the source until this time has passed. After that, the cache copy is considered “expired” and invalid, and a new copy must be obtained from the source.


First we need to enable the mod in the terminal:


a2enmod expires

Then we restart apache2


service apache2 force-reload


If we don’t have any errors we continue.


pico /etc/apache2/sites-available/000-default.conf
and add between <VirtualHost *:80> and </VirtualHost>


<IfModule mod_expires.c>
ExpiresActive on
ExpiresByType image/jpg “access plus 60 days”
ExpiresByType image/png “access plus 60 days”
ExpiresByType image/gif “access plus 60 days”
ExpiresByType image/jpeg “access plus 60 days”
ExpiresByType text/css “access plus 1 days”
ExpiresByType image/x-icon “access plus 1 month”
ExpiresByType application/pdf “access plus 1 month”
ExpiresByType audio/x-wav “access plus 1 month”
ExpiresByType audio/mpeg “access plus 1 month”
ExpiresByType video/mpeg “access plus 1 month”
ExpiresByType video/mp4 “access plus 1 month”
ExpiresByType video/quicktime “access plus 1 month”
ExpiresByType video/x-ms-wmv “access plus 1 month”
ExpiresByType application/x-shockwave-flash “access 1 month”
ExpiresByType text/javascript “access plus 1 week”
ExpiresByType application/x-javascript “access plus 1 week”
ExpiresByType application/javascript “access plus 1 week”
</IfModule>

How to show the last queries executed on MySQL?

You can enable a general query log for that sort of diagnostic. Generally you don’t log all SELECT queries on a production server though, it’s a performance killer.
Edit your MySQL config, e.g. /etc/mysql/my.cnf – look for, or add, a line like this:

[mysqld] log = /var/log/mysql/mysql.log
Code language: JavaScript (javascript)

Restart mysql to pick up that change, now you can:

tail -f /var/log/mysql/mysql.log
Code language: JavaScript (javascript)


Hey presto, you can watch the queries as they come in.