Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Tuesday, August 4, 2020

Linux / ubuntu Server monitoring script and commands

Check server  Memory, CPU load, Storage with date time.

#! /bin/bash
printf "Memory\t\tOS_Disk\t\tHome_Disk\tCPU\t\tTime\n"
end=$((SECONDS+3600))
while [ $SECONDS -lt $end ]; do
MEMORY=$(free -m | awk 'NR==2{printf "%.2f%%\t\t", $3*100/$2 }')
DISK=$(df -h | awk '$NF=="/"{printf "%s\t\t", $5}')
DISKHOME=$(df -h | awk '$NF=="/home"{printf "%s\t\t", $5}')
CPU=$(top -bn1 | grep load | awk '{printf "%.2f%%\t\t\n", $(NF-2)}')
DATELOG=$(date "+%Y-%m-%d %T")
echo "$MEMORY$DISK$DISKHOME$CPU$DATELOG"
sleep 20
done

save this file as stats.sh

run file 

#./stats.sh

Tools
Basic listed below 
strace – discover system calls and signals to a process.
tcpdump – raw network traffic monitoring.
netstat – network connections monitoring.
htop – real time process monitoring.
iftop – real time network bandwidth monitoring.
lsof – view which files are opened by which process.

Sysdig - A Powerful System Monitoring and Troubleshooting Tool for Linux

Command for sysdig

$sudo sysdig
$csysdig
$sysdig -cl
$Sysdig -r trace.scap
$sysdig -c ps
$sysdig -c ps
$sysdig -c list_login_shells
$sysdig -c spy_users

For more detail click here

Basic Command for  Server monitoring

$last
$last reboot | shutdown
$htop
$top
$jobs
$who -b
$ps -aux| grep apache|wc -l  (check apache threads)


Thursday, October 10, 2019

Setup Filesystem Quotas on Linux / Ubuntu Server

Installing the Quota Tools

sudo apt update
sudo apt install quota

Check Quota Version :

quota --version

Installing the Quota Kernel Module
First need  to check, we will use find to search for the quota_v1 and quota_v2 modules in the /lib/modules/... directory:

find /lib/modules/`uname -r` -type f -name '*quota_v*.ko*'

Output : 
/lib/modules/4.15.0-45-generic/kernel/fs/quota/quota_v1.ko
/lib/modules/4.15.0-45-generic/kernel/fs/quota/quota_v2.ko

If you get no output from the above command, install

sudo apt install linux-image-extra-virtual
OR 
Resolve this install kernel dependencies, like this:

apt-get -y install linux-image-generic
apt-get -y install linux-headers-generic
apt-get -y install linux-image-extra-`uname -r`

After that we need to add the quota modules to start with boot:

echo quota_v1 >> /etc/modules
echo quota_v2 >> /etc/modules

Updating Filesystem Mount Options

sudo nano /etc/fstab
LABEL=/home    /home   ext2   defaults,usrquota,grpquota  0 0
Remount the filesystem to make the new options take effect:

sudo mount -o remount /home

Enabling Quotas
sudo quotacheck -ugm /home

Now we’re ready to turn on the quota system:

sudo quotaon -v /home

Configuring Quotas for a User

Using edquota to Set a User Quota

sudo edquota -u  jagdeep

# edquota ramesh

Disk quotas for user jagdeep (uid 50001):
  Filesystem           blocks       soft       hard     inodes     soft     hard
  /dev/sda3           1419352          0          0       1686        0        0
Let’s update our sammy user to have a block quota with a 100MB soft limit, and a 110MB hard limit:

# edquota ramesh

Disk quotas for user jagdeep (uid 50001):
  Filesystem         blocks       soft       hard     inodes     soft     hard
  /dev/sda3        1419352       100M          110M   1686    0        0
Save and close the file

sudo quota -vs jagdeep

Using setquota to Set a User Quota
sudo setquota -u sammy 200M 220M 0 0 /home

Generating Quota Reports

sudo repquota -s /home

# repquota /home
*** Report for user quotas on device /dev/sda3
Block grace time: 7days; Inode grace time: 7days
                        Block limits                File limits
User            used    soft    hard  grace    used  soft  hard  grace
----------------------------------------------------------------------
root      --  566488       0       0           5401     0     0
nobody    --    1448       0       0             30     0     0
jagdeep    -- 1419352       0       0           1686     0     0
john      --   26604       0       0            172     0     0

Configuring a Grace Period for Overages

sudo setquota -t 864000 864000 /home


Output
Block grace time: 10days; Inode grace time: 10days
. . .

Disable quota for a Linux user or group on the shell
Example for disabling the quota for the user "testuser":
setquota -u testuser 0 0 0 0 -a /home
Example for disabling quota for the group "testgroup":
setquota -g testgroup 0 0 0 0 -a /home

Friday, August 18, 2017

Install Laravel Framework on Ubuntu

Step 1 – Install LAMP

You will need to make sure your LAMP meets the following requirements:
  • PHP >= 5.6.4
  • OpenSSL PHP Extension
  • PDO PHP Extension
  • Mbstring PHP Extension
  • Tokenizer PHP Extension
  • XML PHP Extension
$ sudo apt-get install python-software-properties
$ sudo add-apt-repository ppa:ondrej/php
$ sudo apt-get update
$ sudo apt-get install -y php5.6 php5.6-mcrypt php5.6-gd
$ sudo apt-get install apache2 libapache2-mod-php5
$ sudo apt-get install mysql-server php5.6-mysql

Step 2 – Install Composer

Install Composer which is a tool for dependency management in PHP.

$ curl -sS https://getcomposer.org/installer | php
$ sudo mv composer.phar /usr/local/bin/composer
$ sudo chmod +x /usr/local/bin/composer

Step 3 – Install Laravel

Now create a directory where Laravel will be downloaded.
$ mkdir /var/www/html/your_website

Now enter the newly created directory and download the latest Laravel version.
$ cd /var/www/html/your_website
$ git clone https://github.com/laravel/laravel.git

Start the Laravel installation using Composer:
$ composer install

Dependencies installation will take some time. After than set proper permissions on files.
$ chown -R www-data.www-data /var/www/laravel
$ chmod -R 777 /var/www/laravel/storage

Step 4 – Set Encryption Key

# php artisan key:generate
You will notice the below error when running the command.

[ErrorException]
  file_get_contents(/var/www/html/your_website/.env): failed to open stream: No such file or directory

To solve this you should rename the .env.example file into .env:
$ mv .env.example  .env

Generate the encryption key again:
# php artisan key:generate

You should get the following output:
Application key [base64:ULQsledeS17HxCAsssA/06qN+aQGbXBPPpXVeZvdRWE=] set successfully.

Now edit the app.php file and configure the encryption key. Open the file with your favorite text editor. 

# vim config/app.php

Locate the ‘key’ => env(‘APP_KEY’ line and add the key next to it. After you are done the directive should look like this:


'key' => env('APP_KEY', 'base64:7fGASOGOSASA%^AYUFSA9TxZu8M2NwBWVEQsjPGRiasbdasYITIUG$%^$CSSA='),

    'cipher' => 'AES-256-CBC',

Save and close the file.

Now open your favorite web browser and navigate to  http://localhost/your_website  where you will be welcomed by a page as shown in the image below:
Laravel First Page

Wednesday, June 14, 2017

How can I downgrade / Upgrade from PHP 7.0 to PHP 5.6 / PHP 5.6 to PHP 7.0 / PHP 8 on Ubuntu

Ubuntu 16.04 comes with php7.0, and some php web applications might fail to run  with php7.0. So, you test your web app with both php7.0 and php5.0  version. 

You can do following changes with Ubuntu sudo update-alternatives --config php
 
sudo apt install software-properties-common sudo add-apt-repository ppa:ondrej/php sudo apt update

root@pc1# apt-get install php7.0 php5.6 php5.6-mysql php-gettext php5.6-mbstring php-xdebug libapache2-mod-php5.6 libapache2-mod-php7.0 php5.6-curl php5.6-gd php5.6-mcrypt php5.6-xml php5.6-xmlrpc

sudo apt-get install php8.1 php8.1-fpm
sudo apt-get install php8.1-mysql php8.1-mbstring php8.1-xml php8.1-gd php8.1-curl
sudo apt-get install php7.4 php7.4-fpm
sudo apt-get install php7.4-mysql php7.4-mbstring php7.4-xml php7.4-gd php7.4-curl


Installing both php5.6 & php7.0 & php8.0 was clean in my case: no complain of issues, etc.

To switch from php7.0 to php5.6 or other:

# For php in web apps
sudo a2dismod php7.0 && sudo a2enmod php5.6 && sudo service apache2 restart
OR sudo update-alternatives --config php
# For php-cli in the command line
sudo ln -sfn /usr/bin/php5.6 /etc/alternatives/php
or from  php5.6 to php7:
# For php in web apps
sudo a2dismod php5.6 && sudo a2enmod php7.0 && sudo service apache2 restart
# For php-cli in the command line
sudo ln -sfn /usr/bin/php7.0 /etc/alternatives/php
Now Check php version : root@pc1# php --version or php -v
Remove : sudo apt-get remove php5.6-* 

Sunday, June 11, 2017

Problems faced during migration php/mysql code Windows to Linux

1.  Slashes in file names when migrating PHP project to Windows server from Linux server.
Solution : Need to remove back slash & forward slash with underscore (" _ ")

2. Case Sensitive : Mostly in windows both "A" and "a" treat same. But in Linux thinks are different. So need to take care of this. This problems faces both in PHP and MySql files and table respectively. 

You can configuring MySQL Tables to be Case Insensitive by editing the MySQL configuration file, which is generally found at /etc/mysql/my.cnf/etc/my.cnf or ~/my.cnf

Add the following line to the my.cnf configuration file:
lower_case_table_names=1
Then restart MySQL (or reboot):
/etc/init.d/mysql restart (Debian/Ubuntu/SuSE)
/etc/init.d/mysqld restart (Red Hat/CentOS/Fedora)

Today me facing problem the CodeIgniter Web Framework  code. In case of windows folder name was in cap mean in Upper case and in php coding same folder in lower case. It working fine with window server (XAMPP). But when I migrate same into Linux server (ubuntu LAMP) case sensitivity matters and creating problem to load files. You need to take care this otherwise php code does not work. 

Wednesday, June 7, 2017

Apache SSL Certificate Installation on Linux (Ubuntu) OS

For SSL Certificate Installation in Apache (Ubuntu OS)  follow the instructions below :

1. First Copy the Certificate files to your server on apache directory : In case of Ubuntu or Linux OS find path /etc/apache2/

2. Find the Apache config file to edit  Apache's main configuration file is typically named httpd.conf or /etc/apache2/conf.d/ or /etc/apache/sites-available/. 

3. Create  a files under apache configuration directory mention above like website-ssl.conf  for SSL.
If you need your site to be accessible through both secure (https) and non-secure (http) connections, you will need a virtual host for each type of connection. Make a copy of the existing non-secure virtual host.

4. Configure it for SSL as described below :

 <VirtualHost *:443>
DocumentRoot /var/www/html/
ServerName www.yourdomainname.com
SSLEngine on
SSLCertificateFile /path/to/your_domain_name.crt
SSLCertificateKeyFile /path/to/your_private.key
SSLCertificateChainFile /path/to/DigiCertCA.crt

</VirtualHost>

rename the file names to match your certificate files as mention above.

5. Test your Apache config before restarting your apache serviceRun the following command in case of ubuntu OS.

sudo service apache2 restart

Troubleshooting: If your web site is publicly accessible tool  like (SSL Tool 1 , SSL Tool 2SSL (Grading)) can help you find problems.

Tuesday, May 29, 2012

rsync Command

rsync is used to perform the backup operation in UNIX / Linux. rsync utility is used to synchronize the files and directories from one location to another in an effective way.  

Example Synchronize Files From Local to Remote using shell(ssh with port)
rsync -avzi -e "ssh -p 2445" /var/lib/ldap/ username@192.168.32.101:/var/lib/ldap/

Example : Synchronize Files From Remote to Local

rsync -avz username@192.168.200.10:/var/lib/rpm /root/temp

Read More : Click here 

Wednesday, August 31, 2011

Install and Configure Mail Server on Linux System

Mail Transfer Agent
A Mail Transfer Agent (MTA) is the program which receives and sends out the email from your server, and is therefore the key part. The default MTA in Ubuntu is Postfix, but exim4 is also fully supported and in the main repository.
Postfix - this guide explains how to set up Postfix.

In order to install Postfix with SMTP-AUTH and TLS, first install the postfix package from the Main repository using your favorite package manager. For example:
sudo aptitude install postfix


Configuration
From a terminal prompt:
sudo dpkg-reconfigure postfix
Insert the following details when asked (replacing server1.example.com with your domain name if you have one):
General type of mail configuration: Internet Site
NONE doesn't appear to be requested in current config
System mail name: server1.example.com
Root and postmaster mail recipient: <admin_user_name>
Other destinations for mail: server1.example.com, example.com, localhost.example.com, localhost
Force synchronous updates on mail queue?: No
Local networks: 127.0.0.0/8
Yes doesn't appear to be requested in current config
Mailbox size limit (bytes): 0 
Local address extension character: + 
Internet protocols to use: all

Tuesday, December 14, 2010

Comparison of Oracle, MySQL and Postgres DBMS


Comparison are given below with include all the basic concept :-
Category Problem Assessment
MySQL Oracle8 Postgres
Elementary features Basic data types B C A
SQL C B B
Declarative constraints C A A
Programming abstractions D A C
Generation of ids C A A
National chars B A B
Transactions Transactions D A A
Locks D A A
Multiuser access C A C
Programming in DB

Saturday, August 2, 2008

How to install linux (ubuntu) under Windows?

First install  windows than goto control panel than goto administrative tools than go computer management and than go disk management click on the disk management option and the screen will be open our computer drives will be open and format one drive or delete logical drive than the screen colour will be green than C.D. of will be put in the driver than reboot the system than we will click next next --------------- many times

The disk of linux is three types -
1.Live c.d.
2. alternate c.d.
3. net install c.d.