Search

My notebook

How to find files in Linux using ‘find’

find / -name file.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 ;

 

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

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

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

Решение проблемы Zabbix icmp pinger processes more than 75% busy

Сообщение«Zabbix icmp pinger processes more than 75% busy» означает что процесс или процессы выполняющие пинг хостов перегружены.
Для решения этой проблемы необходимо открыть конфигурационный файл zabbix сервера, например через редактор nano:

sudo nano /etc/zabbix/zabbix_server.conf

Далее найти в нем параметр StartPingers, если он равен 1 и закомментирован, то можно увеличить его например на 5 и раскомментировать (убрать перед ним символ #).
Этим мы увеличиваем количество процессов выполняющих ICMP Ping, соответственно нагрузка будет распределена и уменьшена.
Для сохранения изменений в редакторе nano используется комбинация клавиш Ctrl+O, потом Enter. Для выхода Ctrl+X.

После манипуляций необходимо выполнить перезагрузку Zabbix сервера командой:

service zabbix-server restart
или
systemctl start zabbix-server

Также нагрузку можно снизить увеличив «Интервал обновления» в параметрах шаблона. Для этого необходимо зайти в Web интерфейс Zabbix под администратором и нажать Настройка — Шаблоны, на необходимом шаблоне выбрать «Элементы данных», открыть элемент данных выполняющий пинг и найти «Интервал обновления (в сек)«. Значения 180 (это три минуты) или большего думаю вполне достаточно.

 

Спасибо IT Blog

Zabbix agent – CentOS 6

  • delete old install or :

rpm -qa | grep -i zabbi
rpm -e
yum remove -y zabbix-release

  • install

yum install http://repo.zabbix.com/zabbix/2.4/rhel/6/x86_64/zabbix-release-2.4-1.el6.noarch.rpm
yum clean all
yum install -y zabbix-agent

  • start agent

service zabbix-agent start
chkconfig zabbix-agent on

  • config iptables and selinux

iptables -L -n |grep “10050”
cp /etc/sysconfig/iptables /etc/sysconfig/iptables.orig

iptables -I INPUT -s ZABBIX_IP -p tcp -m tcp –dport 10050 -j ACCEPT
iptables -I INPUT -s ZABBIX_IP -p udp -m udp –dport 10050 -j ACCEPT
iptables -I INPUT -s ZABBIX_IP -p udp -m udp –dport 10050 -j ACCEPT

service iptables save
service iptables restart
iptables -L -n |grep “10050”

setenforce 0
vi /etc/selinux/config = Change SELINUX=disabled

Backup script for SQL express server

Create sql_backup.bat file in folder c:\scripts\sql_backup

(Scripts in folder c:\script\sql_backup\ backups in folder d:\sqlbackup\)

File text:

sqlcmd -i c:\scripts\sql_backup\sql_backup.sql >  D:\SQLBACKUPS\reports\backuplog.txt

Create sql_backup.sql files in folder c:\scripts\sql_backup

File text:

DECLARE @basePath varchar(300); 
SET @basePath = N'D:\SQLBACKUPS\'; 

DECLARE @db sysname;
DECLARE user_db_cursor CURSOR FOR 
 SELECT name FROM sys.databases WHERE name NOT IN 
('master', 'model', 'msdb', 'tempdb') 
OPEN user_db_cursor 
FETCH NEXT FROM user_db_cursor 
INTO @db 

WHILE @@FETCH_STATUS = 0 
BEGIN 
 DECLARE @backupPath varchar(1000); 
 SET @backupPath = @basePath + @db + '\'; 

 DECLARE @backupName varchar(1000); 
 DECLARE @time datetime2; 
 SET @time = SYSDATETIME(); 
 SET @backupName = @db + '_backup_' + 
REPLACE(REPLACE(REPLACE(CONVERT(varchar, @time, 20),'-','_'),':',''),' ','_') 
 + '_' + CAST(DATEPART(NANOSECOND, @time)/100 as varchar) 

 --Create sub-directory 
 EXECUTE master.dbo.xp_create_subdir @backupPath 
 
 DECLARE @backupFileName varchar(1000); 
 SET @backupFileName = @backupPath + @backupName + '.bak'; 
 
 --Backup database 
 BACKUP DATABASE @db TO DISK=@backupFileName 
 WITH NOFORMAT, NOINIT, NAME=@backupName , 
 SKIP, REWIND, NOUNLOAD, STATS=10 
 FETCH NEXT FROM user_db_cursor 
INTO @db 
END
CLOSE user_db_cursor 
DEALLOCATE user_db_cursor

Delete old backups:

Create

sqlcmd -i D:\SQLBACKUPS\Script\deleteold.sql > D:\SQLBACKUPS\reports\delete.txt
DECLARE @basePath varchar(300); 
SET @basePath = N'D:\SQLBACKUPS\'; 

DECLARE @time datetime; 
SET @time = DATEADD(DAY,-3, GETDATE() ); 

EXECUTE master.dbo.xp_delete_file 0,@basePath,N'bak',@time,1 

Export your IIS websites list to a xls (Excel)

run cmd as admin’

> %windir%\system32\inetsrv\appcmd list site > c:\sites.xls

Увеличение размера диска на 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
Installed:
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

vgdisplay

--- 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:

lvdisplay

--- 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

 

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

CentOS 7.x VMware Tools

yum -y install open-vm-tools

 

systemctl start vmtoolsd.service

 

systemctl enable vmtoolsd.service

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):

http://server_domain_name_or_IP/

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

 

Blog at WordPress.com.

Up ↑