Wednesday, October 23, 2019

Network Load Monitor Commad in EC2 Instance



Object :

To monitor the Instance In Out Network traffic in the EC2 instances.



Step:1
 
           First you need to install the "nload" RPM in your terminal using the below command.

sudo yum install nload

It will start the installation When you accept Yes.

Loaded plugins: priorities, update-motd, upgrade-helper
amzn-main                                                | 2.1 kB     00:00
amzn-updates                                             | 2.5 kB     00:00
epel/x86_64/metalink                                     | 7.8 kB     00:00
1065 packages excluded due to repository priority protections
Resolving Dependencies
--> Running transaction check
---> Package nload.x86_64 0:0.7.4-1.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package         Arch             Version                  Repository      Size
================================================================================
Installing:
 nload           x86_64           0.7.4-1.el6              epel            63 k

Transaction Summary
================================================================================
Install  1 Package

Total download size: 63 k
Installed size: 155 k
Is this ok [y/d/N]: y
Downloading packages:
nload-0.7.4-1.el6.x86_64.rpm                               |  63 kB   00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : nload-0.7.4-1.el6.x86_64                                     1/1
  Verifying  : nload-0.7.4-1.el6.x86_64                                     1/1

Installed:
  nload.x86_64 0:0.7.4-1.el6

Complete!


Command To Monitor the Network Load.

nload -U m (This command will show you in MB)
nload -U k (This command will show you in KB)
nload -U G (This command will show you in GB)

As per your Use case you might select the command.Thanks !!!

Tuesday, July 16, 2019

Build Your Apache logs by Unified Log rotate cycle In EC2 Instances.



Build Your Apache logs by Unified Log rotate cycle In EC2 Instances.

Log rotate by default configured in one of the EC2 instances for apache web server's access_log & error_log

Step:1

The below configuration was Actual entry (/etc/httpd/conf.d/example.com.conf)


<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/vhosts/example.com/httpdocs/public_html/public

    #CustomLog /var/www/vhosts/example.com/statistics/logs/access_log combined
    #CustomLog "|/usr/sbin/rotatelogs /var/www/vhosts/example.com/statistics/logs/access_log.%Y.%m.%d 86400" combined
    CustomLog "|/usr/sbin/rotatelogs /var/www/vhosts/example.com/statistics/logs/access_%d.%m.%Y.log 86400" combined
    ErrorLog  /var/www/vhosts/example.com/statistics/logs/error_log

    <Directory /var/www/vhosts/example.com/httpdocs/public_html/public>
        Options -Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

<VirtualHost *:443>
        ServerName example.com
        ServerAlias www.example.com
        DocumentRoot /var/www/vhosts/example.com/httpdocs/public_html/public
        CustomLog "|/usr/sbin/rotatelogs /var/www/vhosts/example.com/statistics/logs/access_ssl_%d.%m.%Y.log 86400" combined
        ErrorLog  /var/www/vhosts/example.com/statistics/logs/error_ssl_log

        SSLEngine ON
        SSLCACertificateFile /etc/pki/tls/certs/example.com-ca.crt
        SSLCertificateKeyFile /etc/pki/tls/private/example.com.key
        SSLCertificateFile /etc/pki/tls/certs/example.com.crt


    <Directory /var/www/vhosts/example.com/httpdocs/public_html/public>
        Options -Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

Step:2
The entry you might rotate every 7 days based on your requirement you will have to change accordingly.

This entry has to be done in the file path

File: /etc/logrotate.d/vhostlogs

##########################################################################################
/var/www/vhosts/example.com/statistics/logs/*.log {
    daily
    rotate 2
    missingok
    notifempty
    nocreate
    compress
    postrotate
           find /var/www/vhosts/example.com/statistics/logs/ -name "*.gz" -mtime +7 -delete
    endscript
}
###########################################################################################

That's it you have done the Log rotate entry for Apache access logs!!!

Wednesday, December 5, 2018

How to configure Mod_jk installation in AWS ec2 instance



The Apache Tomcat Connectors (Installation of Mod_jk Tomcat COnnectors)

Installation of Mod_jk First you need to install the Prerequest!!

Pre-request

yum install -y httpd24-devel gcc gcc-c++ make libtool

yum install libtool httpd24-devel autoconf.noarch

OR

go to your terminal and use the below command

wget  http://mirrors.estointernet.in/apache//httpd/httpd-2.4.38.tar.gz
tar -xzf httpd-2.4.38.tar.gz


Download the latest Apache from the Official Apache Website (https://httpd.apache.org/download.cgi)


Step:1



cd httpd-2.4.38

./configure --prefix=/usr/local/apache --enable-rewrite=shared --enable-proxy=shared
make
make install

Step:2

Install the JK connector (mod_jk) for tomcat Connectors

Now you can download tomcat connector (Mod_jk)


wget http://www.eu.apache.org/dist/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.46-src.tar.gz

Select the Latest which you Required.


Copy to this directory of /opt/

/opt/tomcat-connectors-1.2.46-src

Extract the Package which you donwload

tar -xvf tomcat-connectors-1.2.46-src.tar.gz

cd tomcat-connectors-1.2.46-src/

configure-make-make install the connector

./configure –with-apxs=/usr/bin/apxs

For UBUNTU ONLY THIS LINE(./configure --with-apxs=/usr/local/apache/bin/apxs)

make
libtool --finish /usr/lib64/httpd/modules
make install
service httpd restart

Step:3

Configuring the JK Connector Module


Create workers.properties file
Load and configure the JK connector module in apache httpd.conf file

GO to the Working directory path of /opt/tomcat-connectors-1.2.46-src/conf/
And open the worker.properties file (file path "/opt/tomcat-connectors-1.2.46-src/conf/workers.properties")

Put New entry in last paragh of

workers.tomcat_home=/opt/tomcat-connectors-1.2.46-src
workers.java_home=/usr/lib/jvm/jdk6
ps=/
worker.list=myworker
worker.myworker.port=8009
worker.myworker.host=localhost
worker.myworker.type=ajp13
worker.myworker.lbfactor=1



Step :4

Create the file of mod_jk.conf in the directory of "/etc/httpd/conf.d/mod_jk.conf" and put the entry .


LoadModule jk_module modules/mod_jk.so
JkWorkersFile /opt/tomcat-connectors-1.2.46-src/conf/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel error
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat "%w %V %T"



Test the configuration are configured successfully  .

httpd -t


Step:5

Apply the Virtual Host Concept

Open the path of /etc/httpd/conf.d/domain.example.com.conf

<VirtualHost *:80>
    ServerName domain.example.com
    DocumentRoot /var/www/vhosts/domain.example.com/public_html

    CustomLog /var/www/vhosts/domain.example.com/statistics/logs/access_log combined
    ErrorLog  /var/www/vhosts/domain.eample.com/statistics/logs/error_log

   <Directory /var/www/vhosts/domain.example.com/public_html>
    Options -Includes +FollowSymLinks +MultiViews
   AllowOverride All
   Order allow,deny
   Allow from al
  </Directory>
   JkMount /* myworker
 </VirtualHost>

          Restart the Tomcat and apache Httpd service


                  Thats it you done the Mod_jk Installation !!!.











Friday, July 6, 2018

Configure EC2 Instance Apache Web Server on Amazon Linux 2 to Use SSL/TLS

step: 1

[ec2-user~] sudo yum update -y

Now that Your Instance is current , add SSL/TLS suppport by installing the Apache Module mod_ssl


Pre-Request

Configure your security group to allow your instance to accept connections on the following TCP ports:

SSH (port 22)
HTTP (port 80)
HTTPS (port 443


CentOS-7.X 

[ec2-user ~]$ sudo systemctl is-enabled httpd
sudo systemctl start httpd && sudo systemctl enable httpd

CentOS-6.X

Step 2

sudo yum install mod24_ssl

It have been installed mod_ssl TO configure an Modssl

The configuration file for mod_ssl. It contains "directives" telling Apache where to find encryption keys and certificates


Copy your existing SSL certificate to below mentioned path .

/etc/pki/tls/certs/example_domainname_com-ca.crt
/etc/pki/tls/private/example_domainname_com.key
/etc/pki/tls/certs/example_domainname_com.crt

/etc/httpd/conf.d/example.domainname.com.conf
________________________________________________________________________________
### trial.example.com - GENERATED AUTOMATICALLY ###
<VirtualHost *:80>
    ServerName trial.example.com
    ServerAlias www.trial.example.com
    DocumentRoot /var/www/vhosts/trial.example.com/webapp/public_html
    #Redirect permanent / https://trial.example.com/
    #RedirectMatch ^((?!\/(\/jsp\/viewReportData.jsp)).*)$ https://%{HTTP_HOST}$1

RewriteEngine On

# Go to https if not on /your-page-url/

RewriteCond %{SERVER_PORT} =80
RewriteCond %{THE_REQUEST} !/jsp/viewReportData.jsp [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]


    CustomLog /var/www/vhosts/trial.example.com/statistics/logs/access_log combined
    ErrorLog  /var/www/vhosts/trial.example.com/statistics/logs/error_log

    <Directory /var/www/vhosts/trial.example.com/webapp/public_html>
        Options -Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
       JkMount /* myworker
</VirtualHost>

<VirtualHost *:443>
    ServerName trial.example.com
    ServerAlias www.trial.example.com
    DocumentRoot /var/www/vhosts/trial.example.com/webapp/public_html

RewriteEngine On

# Go to http if on /your-page-url/

RewriteCond %{SERVER_PORT} !=80
RewriteCond %{THE_REQUEST} /jsp/viewReportData.jsp [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    SSLEngine ON
    SSLCACertificateFile /etc/pki/tls/certs/trial.example.com-ca.crt
    SSLCertificateKeyFile /etc/pki/tls/private/trial.example.com.key
    SSLCertificateFile /etc/pki/tls/certs/trial.example.com.crt

    CustomLog /var/www/vhosts/trial.example.com/statistics/logs/access_ssl_log combined
    ErrorLog  /var/www/vhosts/trial.example.com/statistics/logs/error_ssl_log

    <Directory /var/www/vhosts/trial.example.com/webapp/public_html>
        Options -Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
     JkMount /* myworker
</VirtualHost>

___________________________________________________________________________________
Once the configuration file completed

Step:3

execute the below command to reflect

httpd -t

/etc/init.d/httpd restart

That it enjoy the SSL installation experience !!!

Thursday, May 19, 2016

MySQL commands for Database Administration in Linux



1. How to set MySQL Root password?

If you have fresh installation of MySQL server, then it doesn’t required any password to connect it as root user. To set MySQL password for root user, use the following command.

# mysqladmin -u root password YOURNEWPASSWORD


2. How to Change MySQL Root password?

If you would like to change or update MySQL root password, then you need to type the following command. For example, say your old password is 123456 and you want to change it with new password say xyz123.

mysqladmin -u root -p123456 password 'xyz123'


3. How to check MySQL Server is running?

To find out whether MySQL server is up and running, use the following command.

# mysqladmin -u root -p ping

Enter password:
mysqld is alive


4. How to Check which MySQL version I am running?

The following command shows MySQL version along with the current running status .

# mysqladmin -u root -p version

Enter password:
mysqladmin  Ver 8.42 Distrib 5.5.28, for Linux on i686
Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Server version          5.5.28
Protocol version        10
Connection              Localhost via UNIX socket
UNIX socket             /var/lib/mysql/mysql.sock
Uptime:                 7 days 14 min 45 sec

Threads: 2  Questions: 36002  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 0.059


5. How to Find out current Status of MySQL server?

To find out current status of MySQL server, use the following command. The mysqladmin command shows the status of uptime with running threads and queries.

# mysqladmin -u root -ptmppassword status

Enter password:
Uptime: 606704  Threads: 2  Questions: 36003  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 0.059


6. How to check status of all MySQL Server Variable’s and value’s?

To check all the running status of MySQL server variables and values, type the following command. The output would be similar to below.

# mysqladmin -u root -p extended-status

Enter password:
+------------------------------------------+-------------+
| Variable_name                            | Value       |
+------------------------------------------+-------------+
| Aborted_clients                          | 3           |
| Aborted_connects                         | 3           |
| Binlog_cache_disk_use                    | 0           |
| Binlog_cache_use                         | 0           |
| Binlog_stmt_cache_disk_use               | 0           |
| Binlog_stmt_cache_use                    | 0           |
| Bytes_received                           | 6400357     |
| Bytes_sent                               | 2610105     |
| Com_admin_commands                       | 3           |
| Com_assign_to_keycache                   | 0           |
| Com_alter_db                             | 0           |
| Com_alter_db_upgrade                     | 0           |
| Com_alter_event                          | 0           |
| Com_alter_function                       | 0           |
| Com_alter_procedure                      | 0           |
| Com_alter_server                         | 0           |
| Com_alter_table                          | 0           |
| Com_alter_tablespace                     | 0           |
+------------------------------------------+-------------+


7. How to see all MySQL server Variables and Values?

To see all the running variables and values of MySQL server, use the command as follows.

# mysqladmin  -u root -p variables

Enter password:
+---------------------------------------------------+----------------------------------------------+
| Variable_name                                     | Value                                        |
+---------------------------------------------------+----------------------------------------------+
| auto_increment_increment                          | 1                                            |
| auto_increment_offset                             | 1                                            |
| autocommit                                        | ON                                           |
| automatic_sp_privileges                           | ON                                           |
| back_log                                          | 50                                           |
| basedir                                           | /usr                                         |
| big_tables                                        | OFF                                          |
| binlog_cache_size                                 | 32768                                        |
| binlog_direct_non_transactional_updates           | OFF                                          |
| binlog_format                                     | STATEMENT                                    |
| binlog_stmt_cache_size                            | 32768                                        |
| bulk_insert_buffer_size                           | 8388608                                      |
| character_set_client                              | latin1                                       |
| character_set_connection                          | latin1                                       |
| character_set_database                            | latin1                                       |
| character_set_filesystem                          | binary                                       |
| character_set_results                             | latin1                                       |
| character_set_server                              | latin1                                       |
| character_set_system                              | utf8                                         |
| character_sets_dir                                | /usr/share/mysql/charsets/                   |
| collation_connection                              | latin1_swedish_ci                            |
+---------------------------------------------------+----------------------------------------------+



8. How to check all the running Process of MySQL server?

The following command will display all the running process of MySQL database queries.

# mysqladmin -u root -p processlist

Enter password:
+-------+---------+-----------------+---------+---------+------+-------+------------------+
| Id    | User    | Host            | db      | Command | Time | State | Info             |
+-------+---------+-----------------+---------+---------+------+-------+------------------+
| 18001 | rsyslog | localhost:38307 | rsyslog | Sleep   | 5590 |       |                  |
| 18020 | root    | localhost       |         | Query   | 0    |       | show processlist |
+-------+---------+-----------------+---------+---------+------+-------+------------------+



9. How to create a Database in MySQL server?

To create a new database in MySQL server, use the command as shown below.

# mysqladmin -u root -p create databasename

Enter password:

# mysql -u root -p

Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 18027
Server version: 5.5.28 MySQL Community Server (GPL) by Remi

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| databasename       |
| mysql              |
| test               |
+--------------------+
8 rows in set (0.01 sec)

mysql>



10. How to drop a Database in MySQL server?

To drop a Database in MySQL server, use the following command. You will be asked to confirm press ‘y‘.

# mysqladmin -u root -p drop databasename

Enter password:
Dropping the database is potentially a very bad thing to do.
Any data stored in the database will be destroyed.

Do you really want to drop the 'databasename' database [y/N] y
Database "databasename" dropped



11. How to reload/refresh MySQL Privileges?

The reload command tells the server to reload the grant tables. The refresh command flushes all tables and reopens the log files.

# mysqladmin -u root -p reload;
# mysqladmin -u root -p refresh



12. How to shutdown MySQL server Safely?

To shutdown MySQL server safely, type the following command.

mysqladmin -u root -p shutdown

Enter password:

You can also use the following commands to start/stop MySQL server.

# /etc/init.d/mysqld stop
# /etc/init.d/mysqld start



13. Some useful MySQL Flush commands

Following are some useful flush commands with their description.

    flush-hosts: Flush all host information from host cache.
    flush-tables: Flush all tables.
    flush-threads: Flush all threads cache.
    flush-logs: Flush all information logs.
    flush-privileges: Reload the grant tables (same as reload).
    flush-status: Clear status variables.

# mysqladmin -u root -p flush-hosts
# mysqladmin -u root -p flush-tables
# mysqladmin -u root -p flush-threads
# mysqladmin -u root -p flush-logs
# mysqladmin -u root -p flush-privileges
# mysqladmin -u root -p flush-status



14. How to kill Sleeping MySQL Client Process?

Use the following command to identify sleeping MySQL client process.

# mysqladmin -u root -p processlist

Enter password:
+----+------+-----------+----+---------+------+-------+------------------+
| Id | User | Host      | db | Command | Time | State | Info             |
+----+------+-----------+----+---------+------+-------+------------------+
| 5  | root | localhost |    | Sleep   | 14   |       |                                                                      |
| 8  | root | localhost |    | Query   | 0    |       | show processlist |
+----+------+-----------+----+---------+------+-------+------------------+

Now, run the following command with kill and process ID as shown below.

# mysqladmin -u root -p kill 5

Enter password:
+----+------+-----------+----+---------+------+-------+------------------+
| Id | User | Host      | db | Command | Time | State | Info             |
+----+------+-----------+----+---------+------+-------+------------------+
| 12 | root | localhost |    | Query   | 0    |       | show processlist |
+----+------+-----------+----+---------+------+-------+------------------+

If you like to kill multiple process, then pass the process ID‘s with comma separated as shown below.

# mysqladmin -u root -p kill 5,10



15. How to run multiple mysqladmin commands together?

If you would like to execute multiple ‘mysqladmin‘ commands together, then the command would be like this.

# mysqladmin  -u root -p processlist status version

Enter password:
+----+------+-----------+----+---------+------+-------+------------------+
| Id | User | Host      | db | Command | Time | State | Info             |
+----+------+-----------+----+---------+------+-------+------------------+
| 8  | root | localhost |    | Query   | 0    |       | show processlist |
+----+------+-----------+----+---------+------+-------+------------------+
Uptime: 3801  Threads: 1  Questions: 15  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 0.003
mysqladmin  Ver 8.42 Distrib 5.5.28, for Linux on i686
Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Server version          5.5.28
Protocol version        10
Connection              Localhost via UNIX socket
UNIX socket             /var/lib/mysql/mysql.sock
Uptime:                 1 hour 3 min 21 sec

Threads: 1  Questions: 15  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 0.003



16. How to Connect remote mysql server

To connect remote MySQL server, use the -h (host)  with IP Address of remote machine.

# mysqladmin  -h 172.16.25.126 -u root -p



17. How to execute command on remote MySQL server

Let’s say you would like to see the status of remote MySQL server, then the command would be.

# mysqladmin  -h 172.16.25.126 -u root -p status



18. How to start/stop MySQL replication on a slave server?

To start/stop MySQL replication on salve server, use the following commands.

# mysqladmin  -u root -p start-slave

# mysqladmin  -u root -p stop-slave



19. How to store MySQL server Debug Information to logs?

It tells the server to write debug information about locks in use, used memory and query usage to the MySQL log file including information about event scheduler.

# mysqladmin  -u root -p debug

Enter password:



20. How to view mysqladmin options and usage

To find out more options and usage of myslqadmin command use the help command as shown below. It will display a list of available options.

# mysqladmin --help