My notebook



How to find files in Linux using ‘find’

find / -name


Find highest CPU, Memory & MySQL Usage for cPanel accounts

OUT=$(/usr/local/cpanel/bin/dcpumonview | grep -v Top | sed -e ‘s#<[^>]*># #g’ | while read i ; do NF=`echo $i | awk {‘print NF’}` ; if [[ “$NF” == “5” ]] ; then USER=`echo $i | awk {‘print $1’}`; OWNER=`grep -e “^OWNER=” /var/cpanel/users/$USER | cut -d= -f2` ; echo “$OWNER $i”; fi ; done) ; (echo “USER CPU” ; echo “$OUT” | sort -nrk4 | awk ‘{printf “%s %s%\n”,$2,$4}’ | head -5) | column -t ;echo;(echo -e “USER MEMORY” ; echo “$OUT” | sort -nrk5 | awk ‘{printf “%s %s%\n”,$2,$5}’ | head -5) | column -t ;echo;(echo -e “USER MYSQL” ; echo “$OUT” | sort -nrk6 | awk ‘{printf “%s %s%\n”,$2,$6}’ | head -5) | column -t ;


user1 2.51%
user2 1.48%
user3 1.04%
user4 0.77%
user5 0.61%

user1 5.67%
user2 0.38%
user3 0.38%
user4 0.13%
user5 0.12%

user1 0.3%
user2 0.0%
user3 0.0%
user4 0.0%
user5 0.0%

Увеличение размера диска на CentOS 7 (VMware)

На сайте VMware размещена инструкция по увеличению размера логического тома в виртуальной машине под управлением Red Hat и Cent OS, но написана она для более ранних версий. В результате выполнений действий по инструкции получим ошибку:


resize2fs /dev/mapper/centos_ns-root
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/mapper/cent os_ns-root
Couldn't find valid filesystem superblock.

Предварительно диск должен быть расширен средствами гипервизора.

В CentOS / RHEL 7 нужно использовать System Storage Manager.

Устанавливаем его:

yum install system-storage-manager
system-storage-manager.noarch 0:0.4-5.el7

После установки находим наш расширеный диск, в моем случае это /dev/sda расширеный до 50 ГБ:

ssm list

Device Free Used Total Pool Mount point
/dev/fd0 4.00 KB
/dev/sda 50.00 GB PARTITIONED
/dev/sda1 500.00 MB /boot
/dev/sda2 0.00 KB 3.51 GB 3.51 GB centos_ns
Pool Type Devices Free Used Total
centos_ns lvm 1 0.00 KB 3.51 GB 3.51 GB
Volume Pool Volume size FS FS size Free Type Mount point
/dev/centos_ns/root centos_ns 3.11 GB xfs 3.10 GB 2.15 GB linear /
/dev/centos_ns/swap centos_ns 412.00 MB linear
/dev/sda1 500.00 MB xfs 496.67 MB 386.61 MB part /boot

Создаем главный (primary) раздел на расширенном диске:

fdisk /dev/sda

Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p
Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000c30dc
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 8388607 3681280 8e Linux LVM
Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
Partition number (3,4, default 3): 3
First sector (8388608-104857599, default 8388608):
Using default value 8388608
Last sector, +sectors or +size{K,M,G} (8388608-104857599, default 104857599):
Using default value 104857599
Partition 3 of type Linux and of size 46 GiB is set
Command (m for help): t
Partition number (1-3, default 3): 3
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.


shutdown -r now

После загрузки смотрим диски (fdisk -l) должен появится раздел /dev/sda3 с типом 8e

fdisk -l
Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000c30dc
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 8388607 3681280 8e Linux LVM
/dev/sda3 8388608 104857599 48234496 8e Linux LVM
Disk /dev/mapper/centos_ns-root: 3334 MB, 3334471680 bytes, 6512640 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/centos_ns-swap: 432 MB, 432013312 bytes, 843776 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Преобразовываем новый раздел в физический том

pvcreate /dev/sda3

Physical volume "/dev/sda3" successfully created

Смотрим имя Volume group


--- Volume group ---
VG Name centos_ns
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 6
VG Access read/write
VG Status resizable

Расширяем Volume group

vgextend centos_ns /dev/sda3

Volume group "centos_ns" successfully extended

Смотрим свободное пространство Volume group:

vgdisplay centos_ns | grep "Free"

Free PE / Size 11775 / 46.00 GiB

Определяем имя нужного Logical Volume:


--- Logical volume ---
LV Path /dev/centos_ns/root
LV Name root
VG Name centos_ns

Расширяем определенный Logical Volume на свободный размер:

ssm resize -s+46G /dev/centos_ns/root

SSM Error (2005): There is not enough space in the pool 'centos_ns' to grow volume '/dev/centos_ns/root'

Если возникла такая ошибка указываем немного меньше размер

ssm resize -s+45.9G /dev/centos_ns/root

Extending logical volume root to 49.00 GiB
Logical volume root successfully resized
meta-data=/dev/mapper/centos_ns-root isize=256 agcount=60, agsize=203520 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=12058624, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 12058624 to 12845056

Диск увеличен!

ssm list

Device Free Used Total Pool Mount point
/dev/fd0 4.00 KB
/dev/sda 50.00 GB PARTITIONED
/dev/sda1 500.00 MB /boot
/dev/sda2 0.00 KB 3.51 GB 3.51 GB centos_ns
/dev/sda3 104.00 MB 45.89 GB 46.00 GB centos_ns
Pool Type Devices Free Used Total
centos_ns lvm 2 104.00 MB 49.40 GB 49.50 GB
Volume Pool Volume size FS FS size Free Type Mount point
/dev/centos_ns/root centos_ns 49.00 GB xfs 45.99 GB 2.04 GB linear /
/dev/centos_ns/swap centos_ns 412.00 MB linear
/dev/sda1 500.00 MB xfs 496.67 MB 363.48 MB part /boot
[root@ns ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos_ns-root 49G 1.1G 48G 3% /
devtmpfs 237M 0 237M 0% /dev
tmpfs 246M 0 246M 0% /dev/shm
tmpfs 246M 4.4M 241M 2% /run
tmpfs 246M 0 246M 0% /sys/fs/cgroup
/dev/sda1 497M 175M 323M 36% /boot


Оригинальная статья

Install Nginx on CentOS 7

Step One—Add Nginx Repository

To add the CentOS 7 EPEL repository, open terminal and use the following command:

sudo yum install epel-release

Step Two—Install Nginx

Now that the Nginx repository is installed on your server, install Nginx using the following yum command:

sudo yum install nginx

After you answer yes to the prompt, Nginx will finish installing on your virtual private server (VPS).

Step Three—Start Nginx

Nginx does not start on its own. To get Nginx running, type:

sudo systemctl start nginx

If you are running a firewall, run the following commands to allow HTTP and HTTPS traffic:

sudo firewall-cmd --permanent --zone=public --add-service=http 
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload

You can do a spot check right away to verify that everything went as planned by visiting your server’s public IP address in your web browser (see the note under the next heading to find out what your public IP address is if you do not have this information already):


You will see the default CentOS 7 Nginx web page, which is there for informational and testing purposes. It should look something like this:

CentOS 7 Nginx Default

If you see this page, then your web server is now correctly installed.

Before continuing, you will probably want to enable Nginx to start when your system boots. To do so, enter the following command:

sudo systemctl enable nginx

Congratulations! Nginx is now installed and running!

How To Find Your Server’s Public IP Address

To find your server’s public IP address, find the network interfaces on your machine by typing:

ip addr
1. lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN

. . .
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000

. . .

You may see a number of interfaces here depending on the hardware available on your server. The lointerface is the local loopback interface, which is not the one we want. In our example above, the eth0interface is what we want.

Once you have the interface name, you can run the following command to reveal your server’s public IP address. Substitute the interface name you found above:

ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'

Server Root and Configuration

If you want to start serving your own pages or application through Nginx, you will want to know the locations of the Nginx configuration files and default server root directory.

Default Server Root

The default server root directory is /usr/share/nginx/html. Files that are placed in there will be served on your web server. This location is specified in the default server block configuration file that ships with Nginx, which is located at /etc/nginx/conf.d/default.conf.

Server Block Configuration

Any additional server blocks, known as Virtual Hosts in Apache, can be added by creating new configuration files in /etc/nginx/conf.d. Files that end with .conf in that directory will be loaded when Nginx is started.

Nginx Global Configuration

The main Nginx configuration file is located at /etc/nginx/nginx.conf. This is where you can change settings like the user that runs the Nginx daemon processes, and the number of worker processes that get spawned when Nginx is running, among other things.

See More

Once you have Nginx installed on your cloud server, you can go on to install a LEMP Stack.


Full post  DigitalOcean





sys-unconfig – shell-скрипт для перенастройки системы во время следующей загрузки




sys-unconfig обеспечивает простой способ перенастройки системы под новую конфигурацию. При выполнении sys-unconfig остановит вашу систему и во время загрузки запустит следующие конфигурационные программы: passwd (для смены пароля root’а), netconfig, timeconfig, authconfig и ntsysv.


Наличие этого файла заставит /etc/rc.d/rc.sysinit запустить программы, указанные выше.

How to upgrade PHP version 5.3.3 to 5.3.X


rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm


yum upgrade --enablerepo=remi php


Original post.

Mysql backup

Create folder

mkdir /etc/scripts

edit backup files

databases=`mysql --user=$USER --password=$PASSWORD -e "SHOW DATABASES;" | tr -d "| " | grep -v Database`
for db in $databases; do
 if [[ "$db" != "information_schema" ]] && [[ "$db" != _* ]] ; then
 echo "Dumping database: $db"
 mysqldump --force --opt --user=$USER --password=$PASSWORD --databases $db > $OUTPUT/`date +%Y%m%d`.$db.sql
 gzip $OUTPUT/`date +%Y%m%d`.$db.sql

Delete old backups:

find /opt/backup_mysql/* -mtime +6 -exec rm {} \;

Change permission:

chmod 700
Add task
crontab -e
#delete old backups
0 2 * * * SHELL=/bin/sh PATH=/bin:/sbin:/usr/bin:/usr/sbin /etc/scripts/ > /dev/null 2>&1
#new backup
0 3 * * * SHELL=/bin/sh PATH=/bin:/sbin:/usr/bin:/usr/sbin /etc/scripts/ > /dev/null 2>&1

Setup IT Operational Portal Using iTop On CentOS/Debian


Using iTop you can:

– Document your entire IT infrastructure assets such as servers, applications, network devices, virtual machines, contacts.. etc.

– Manage incidents, user requests, planned outages.

– Document IT services and contracts with external providers including service level agreements.

– Export all the information in a manual or scripted manner.

– Import or synchronize/federate any data from external systems.


– Fully configurable CMDB.
– HelpDesk and Incident Management.
– Service and Contract Management.
– Change Management.
– Configuration Management.
– Automatic SLA management.
– Automatic impact analysis.
– CSV import tool for all data.
– Consistency audit to check data quality.
– Data synchronization (data federation).

In this tutorial let us see how to setup the iTop on CentOS 6.5 and Debian 7, although it should work on RHEL, Scientific Linux 6.x and Ubuntu 13.10 as well.


As it relies on apache, mysql and php, we need a server that has a working LAMP stack. To install LAMP server, refer the following articles that matches your platform.

Install LAMP server on CentOS/RHEL/Scientific Linux 6

Install LAMP server on Debian 7

Install LAMP server on Ubuntu 13.10

Then install the following php extensions.

On CentOS/RHEL/Scientific Linux:

# yum install php-mysql php-mcrypt php-xml php-cli php-soap php-ldap graphviz

On Debian/Ubuntu:

apt-get install php5-mysql php5-ldap php5-mcrypt
apt-get install php5-cli php5-soap php5-json graphviz

We need to adjust the following php settings for best performance. Edit file /etc/php.ini,

# vi /etc/php.ini

Set post_max_size as 32M.

post_max_size = 32M

Download iTap

You can download the latest version from here.

 # wget

Extract the zip file with command:

# unzip

The above command extracts the zip file as a folder called ‘web’ in your current directory. Copy the ‘web’ folder contents to apache root folder.

# cp -fr web/ /var/www/html/itop

If you’re on a Debian/Ubuntu system, then the command would be:

# cp -fr web/ /var/www/itop

Create the following folders and make them to be writable.

# mkdir /var/www/html/itop/conf
# mkdir /var/www/html/itop/data
# mkdir /var/www/html/itop/env-production
# mkdir /var/www/html/itop/log
# chmod 777 /var/www/html/itop/conf/
# chmod 777 /var/www/html/itop/data
# chmod 777 /var/www/html/itop/env-production/
# chmod 777 /var/www/html/itop/log

Begin Installation

Let us start the installation by navigating to the URL http://ip-address/itop orhttp://domain-name/itop.

If everything Ok, you will see the following screen. Click Continue.

Welcome to iTop version 2.0.2 - Mozilla Firefox_001Select Install a New iTop and click Next.

Install or Upgrade choice - Mozilla Firefox_002Accept the License agreement.

License Agreement - Mozilla Firefox_003Create a new database for iTop.

Database Configuration - Mozilla Firefox_005Enter the password for admin account.

Administrator Account - Mozilla Firefox_006We’ve reached the end of installation. You’ll be asked to populate some sample data’s into your data. If you directly use it in production environment, then select the second option and Click Next. I want to populate my database with some demo data’s, so checked the first option.

Miscellaneous Parameters - Mozilla Firefox_008Click Next.

Configuration Management options - Mozilla Firefox_010Select the best choice of your IT environment and click Next.

Service Management options - Mozilla Firefox_012Select the type of your Ticket management. If you don’t like to have Ticket management system, you can skip it also.

Tickets Management options - Mozilla Firefox_013Select the type of tickets you want to use in order to manage changes to the IT infrastructure.

Change Management options - Mozilla Firefox_015Select the following options if you want to implement any additional ITIL processes.

Additional ITIL tickets - Mozilla Firefox_016Once you done with configuration, click Install.

Ready to install - Mozilla Firefox_018Congratulations! We’ve successfully installed iTop. Click on the Link Enter iTop to log in.

Done - Mozilla Firefox_019This is how my Dashboard looks with demo data.

Welcome to iTop - Mozilla Firefox_020That’s all now. Start learning iTop with demo data and manage your IT infrastructure like a boss.

Reference Links:

iTop Homepage


Original post – Link

Install LAMP Server (Apache, MySQL, PHP) On RHEL, CentOS, Scientific Linux 6.5/6.4

LAMP is a combination of operating system and open-source software stack. The acronym LAMP is derived from first letters of Linux, Apache HTTP Server, MySQL database, and PHP/Perl/Python.

In this tutorial let us see how to setup LAMP server on RHEL/CentOS/Scientific Linux 6.x. Here x stands for version such as 6.1, 6.2, 6.3, 6.4, 6.5 etc.

My testbox hostname and IP address are server.unixmen.local and, respectively.

Install Apache

Apache is an open-source multi-platform web server. It provides a full range of web server features including CGI, SSL and virtual domains.

To install Apache, enter the following command from your terminal:

# yum install httpd -y

Start the Apache service and let it to start automatically on every reboot:

# service httpd start
# chkconfig httpd on

Allow Apache server default port 80 through your firewall/router if you want to connect from remote systems. To do that, edit file /etc/sysconfig/iptables,

# vi /etc/sysconfig/iptables

Add the following lines.

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEP

Restart iptables:

# service iptables restart

Test Apache:

Open your web browser and navigate to http://localhost/ or http://server-ip-address/.

Apache HTTP Server Test Page powered by CentOS - Mozilla Firefox_001

Install MySQL

MySQL is an enterprise class, open source, world’s second most used database. MySQL is a popular choice of database for use in web applications, and is a central component of the widely used LAMP open source web application software stack.

To install MySQL, enter the following command:

# yum install mysql mysql-server -y

Start the MySQL service and make to start automatically on every reboot.

# service mysqld start
# chkconfig mysqld on

Setup MySQL root password

By default, mysql root user doesn’t has password. To secure mysql, we have to setup mysql root user password.

# mysql_secure_installation
In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):     ## Press Enter ## 
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n]     ## Press Enter ##
New password:                ## Enter new password ##
Re-enter new password:       ## Re-enter new password ##
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n]     ## Press Enter ##
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n]     ## Press Enter ## 
... Success!
By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n]     ## Press Enter ##
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n]     ## Press Enter ##
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

Install PHP

PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely used open-source general purpose scripting language that is especially suited for web development and can be embedded into HTML.

Install PHP with following command:

# yum install php -y

Test PHP

Create a sample “testphp.php” file in Apache document root folder and append the lines as shown below:

# vi /var/www/html/testphp.php

Add the following lines.

Restart httpd service:

# service httpd restart

Navigate to http://server-ip-address/testphp.php. It will display all the details about php such as version, build date and commands etc.

If you wanna to get MySQL support in your PHP, you should install “php-mysql” package. If you want to install all php modules just you use the command “yum install php*”

[root@server ~]# yum install php-mysql -y

Now open the phptest.php file in your browser using http://ip-address/testphp.php or http://domain-name/testphp.php. Scroll down and you will see the mysql module will be presented there.

phpinfo() - Mozilla Firefox_002Install phpMyAdmin

phpMyAdmin is a free open source web interface tool, used to manage your MySQL databases. By default phpMyAdmin is not found in CentOS official repositories. So let us install it using EPEL repository.

To install EPEL repository, follow the below link:

Install EPEL Repository On RHEL/CentOS/Scientific Linux 6

Now install phpMyAdmin

# yum install phpmyadmin -y

Configure phpMyAdmin

Edit the phpmyadmin.conf file.

# vi /etc/httpd/conf.d/phpMyAdmin.conf

Find and comment the whole /<Directory> section as shown below:

Alias /phpMyAdmin /usr/share/phpMyAdmin
Alias /phpmyadmin /usr/share/phpMyAdmin

#<Directory /usr/share/phpMyAdmin/>
#   <IfModule mod_authz_core.c>
#     # Apache 2.4
#     Require local
#   </IfModule>
#   <IfModule !mod_authz_core.c>
#     # Apache 2.2
#     Order Deny,Allow
#     Deny from All
#     Allow from
#     Allow from ::1
#   </IfModule>

Open “” file and change from “cookie” to “http” to change the authentication in phpMyAdmin:

# cp /usr/share/phpMyAdmin/ /usr/share/phpMyAdmin/ 
# vi /usr/share/phpMyAdmin/

Change cookie to http.

/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'http';

Restart the Apache service:

# service httpd restart

Now you can access the phpmyadmin console by navigating to http://server-ip-address/phpmyadmin/ from your browser.

Enter your MySQL username and password which you have given in previous steps. In my case its “root” and “centos”.

phpMyAdmin - Mozilla Firefox_003Now you will be redirected to the phpmyadmin as shown below. - localhost | phpMyAdmin 4.1.2 - Mozilla Firefox_004

Now you will able to manage your MariaDB databases from phpMyAdmin web interface.

That’s it. Your LAMP server is up and ready to use.

Original post – link

Blog at

Up ↑