How to Administrate CloudLinux OS from Command Line

CloudLinux OS (Operating System) improves server stability, density and security by isolating each tenant and providing them with limited server resources.

It comes with many components that control system resources in many aspects.

It creates a virtual environment for each user using the Lightweight Virtualized Environment (LVE) feature, which allows you to control server resources such as memory, CPU, IO, IOPS, number of processes and other limits for each tenant.

CloudLinux components can be easily managed through Graphical user interface (GUI) without any issues if you have installed it with supported control panels like cPanel, Plesk, ISPmanager, DirectAdmin, InterWorx.

Otherwise, you need to use the following utilities to manage them via the command line.

This method is also easy and you can complete the activity here faster compared to the GUI method.

1) lvectl Command Usage

lvectl is the primary tool for LVE management. It allows you to set/reset all LVEs settings based on configuration in /etc/container/ve.cfg. It requires administrator privilege.

Syntax: lvectl command [lveid] [options]

To list loaded LVE’s with LVE id, use the following command.

# lvectl list | more
      ID   SPEED    NCPU    PMEM    VMEM      EP   NPROC      IO    IOPS
 default      25       1    1.0G    1.0G      20     100    1024    1024
     512      25       1    1.0G    1.0G      20     100    1024    1024
     514      25       1    1.0G    1.0G      20     100    1024    1024
     515      25       1    1.0G    1.0G      20     100    1024    1024
     516      25       1    1.0G    1.0G      20     100    1024    1024
     517      25       1    1.0G    1.0G      20     100    1024    1024
     518      25       1    1.0G    1.0G      20     100    1024    1024
     513      25       1    1.0G    1.0G      20     100    1024    1024
.
.

List the loaded LVE’s with the username instead of the LVE ID.

# lvectl list-user | more
      ID   SPEED    NCPU    PMEM    VMEM      EP   NPROC      IO    IOPS
 default      25       1    1.0G    1.0G      20     100    1024    1024
datapoin      25       1    1.0G    1.0G      20     100    1024    1024
  devpro      25       1    1.0G    1.0G      20     100    1024    1024
dhanjale      25       1    1.0G    1.0G      20     100    1024    1024
dowellte      25       1    1.0G    1.0G      20     100    1024    1024
earthrec      25       1    1.0G    1.0G      20     100    1024    1024
electron      25       1    1.0G    1.0G      20     100    1024    1024
deepamfl      25       1    1.0G    1.0G      20     100    1024    1024
evergree      25       1    1.0G    1.0G      20     100    1024    1024
gitiwapt      25       1    1.0G    1.0G      20     100    1024    1024
.
.

Use the following commands to remove limits for a specific user, such as cpu, ncpu, io, nproc, pmem, vmem and entry processes.

Check current or default limits for a particular user. In this case, we will be checking the “daygeek” user limits.

# lvectl list-user | grep daygeekc
daygeekc      25       1    1.0G    1.0G      20     100    1024    1024

To remove limits.

# lvectl set-user daygeekc --unlimited

To change a specific field limits. For instance, to set speed limit to 50%.

# lvectl set-user daygeekc --speed=50%
daygeekc      50       1    1.0G    1.0G      20     100    1024    1024

Remove customized limits for the user and return to default.

# lvectl delete-user daygeekc

2) lveps Command Usage

lveps tool shows information about running LVEs, processes and threads belonging to them, CPU/memory/IO usage consumed by LVEs and their individual processes/threads. LVE is only reported if it is considered active.

Syntax: lveps [options]

The following command will display processes running inside ‘active’ LVEs.

# lveps -p -n
      ID     EP    PNO        COM    TNO    TID       CPU      MEM         DT         DO
     621      3      6        ---      6    ---      1163      115          0          0
            ---    ---        php    --- 137743         0       26        N/A        N/A
            ---    ---        php    --- 137742         0       26        N/A        N/A
            ---    ---        php    --- 137741         0       26        N/A        N/A
            ---    ---      httpd    --- 132958         0        5        N/A        N/A
            ---    ---      httpd    --- 132443         0        5        N/A        N/A
            ---    ---      httpd    --- 131632         0        5        N/A        N/A

3) lvetop Command Usage

lvetop utility allows you to monitor LVE usage. It shows the following fields such as username, number of entry processes, number of processes, number of threads, CPU usage, Memory usage, I/O usage and IOPS.

# lvetop
      ID     EP    PNO    TNO     SPEED      MEM         IO       IOPS
daygeekc      0      0      0       11%        0          0          0

4) cldetect Command Usage

cldetect is used to detect installed software, and adjust CloudLinux options accordingly.

Syntax: /usr/bin/cldetect [--options]

To check installed cPanel version.

# /usr/bin/cldetect --detect-cp
cPanel,11.50.0

5) LVE-stats 2 Command Usage

The LVE-stats 2 collects LVE usage statistics, and allows to query the data. It contains many tools that used to collect different information about LVE usage.

5a) lveinfo Command Usage

lveinfo is an utility to display historical information about LVE usage.

Query historical information about LVE usage by LVE ID.

# /usr/sbin/lveinfo
+---+----+----+----+---+---+----+---+---+---+-----+------+-----+-----+------+-----+------+------+------+---+-----+-----+------+-----+-----+-----+
| ID|aCPU|mCPU|lCPU|aIO|mIO|lIO |aEP|mEP|lEP|aVMem|mVMem |lVMem|aPMem|mPMem |lPMem|aNproc|mNproc|lNproc|EPf|VMemF|PMemF|NprocF|aIOPS|mIOPS|lIOPS|
+---+----+----+----+---+---+----+---+---+---+-----+------+-----+-----+------+-----+------+------+------+---+-----+-----+------+-----+-----+-----+
|641| 4  | 25 | 25 | 0 | 29|1024| 0 | 6 | 20|14.5M|107.6M| 1.0G| 9.4M|317.3M| 1.0G|  0   |  6   | 100  | 0 |  0  |  0  |  0   |  1  | 234 | 1024|
|621| 1  | 21 |100 | 0 | 0 | 0  | 0 | 2 | 0 | 1.4M|76.9M |  0  | 9.7M|95.6M |  0  |  0   |  2   |  0   | 0 |  0  |  0  |  0   |  0  |  0  |  0  |
|515| 0  | 0  | 25 | 0 | 0 |1024| 0 | 0 | 20|  0  |  0   | 1.0G| 395K| 520K | 1.0G|  0   |  0   | 100  | 0 |  0  |  0  |  0   |  0  |  0  | 1024|
|518| 0  | 0  | 25 | 0 | 0 |1024| 0 | 0 | 20|  0  |  0   | 1.0G| 120K| 120K | 1.0G|  0   |  0   | 100  | 0 |  0  |  0  |  0   |  0  |  0  | 1024|
|534| 0  | 1  | 25 | 0 | 64|1024| 0 | 1 | 20| 41K | 5.6M | 1.0G| 3.9M|10.3M | 1.0G|  0   |  1   | 100  | 0 |  0  |  0  |  0   |  0  |  15 | 1024|
|563| 0  | 0  | 25 | 0 | 0 |1024| 0 | 0 | 20|  0  |  0   | 1.0G| 2.7M| 2.7M | 1.0G|  0   |  0   | 100  | 0 |  0  |  0  |  0   |  0  |  0  | 1024|
|582| 0  | 0  | 25 | 0 | 0 |1024| 0 | 0 | 20|  0  |  0   | 1.0G| 84K | 84K  | 1.0G|  0   |  0   | 100  | 0 |  0  |  0  |  0   |  0  |  0  | 1024|
|588| 0  | 0  | 25 | 0 | 0 |1024| 0 | 0 | 20|  0  |  0   | 1.0G| 105K| 108K | 1.0G|  0   |  0   | 100  | 0 |  0  |  0  |  0   |  0  |  0  | 1024|
|618| 0  | 9  | 25 | 0 | 6 |1024| 0 | 0 | 20|  0  |  0   | 1.0G| 8.0M|14.9M | 1.0G|  0   |  0   | 100  | 0 |  0  |  0  |  0   |  0  |  0  | 1024|
|639| 0  | 0  | 25 | 0 | 0 |1024| 0 | 0 | 20|  0  |  0   | 1.0G| 12K | 12K  | 1.0G|  0   |  0   | 100  | 0 |  0  |  0  |  0   |  0  |  0  | 1024|
+---+----+----+----+---+---+----+---+---+---+-----+------+-----+-----+------+-----+------+------+------+---+-----+-----+------+-----+-----+-----+

Query historical information about LVE usage by username.

# /usr/sbin/lveinfo -d
+--------+----+----+----+---+---+----+---+---+---+-----+-----+-----+-----+------+-----+------+------+------+---+-----+-----+------+-----+-----+-----+
|   ID   |aCPU|mCPU|lCPU|aIO|mIO|lIO |aEP|mEP|lEP|aVMem|mVMem|lVMem|aPMem|mPMem |lPMem|aNproc|mNproc|lNproc|EPf|VMemF|PMemF|NprocF|aIOPS|mIOPS|lIOPS|
+--------+----+----+----+---+---+----+---+---+---+-----+-----+-----+-----+------+-----+------+------+------+---+-----+-----+------+-----+-----+-----+
|daygeekc| 1  | 25 |100 | 0 | 0 | 0  | 0 | 3 | 0 | 1.9M|87.1M|  0  |12.6M|118.1M|  0  |  0   |  3   |  0   | 0 |  0  |  0  |  0   |  0  |  0  |  0  |
|dhanjale| 0  | 0  | 25 | 0 | 0 |1024| 0 | 0 | 20|  0  |  0  | 1.0G| 172K| 172K | 1.0G|  0   |  0   | 100  | 0 |  0  |  0  |  0   |  0  |  0  | 1024|
|earthrec| 0  | 0  | 25 | 0 | 0 |1024| 0 | 0 | 20|  0  |  0  | 1.0G| 72K | 72K  | 1.0G|  0   |  0   | 100  | 0 |  0  |  0  |  0   |  0  |  0  | 1024|
|electron| 0  | 0  | 25 | 0 | 0 |1024| 0 | 0 | 20|  0  |  0  | 1.0G| 104K| 112K | 1.0G|  0   |  0   | 100  | 0 |  0  |  0  |  0   |  0  |  0  | 1024|
|hindusta| 0  | 0  | 25 | 0 | 0 |1024| 0 | 0 | 20|  0  |  0  | 1.0G| 68K | 68K  | 1.0G|  0   |  0   | 100  | 0 |  0  |  0  |  0   |  0  |  0  | 1024|
|icaisale| 0  | 0  | 25 | 0 | 0 |1024| 0 | 0 | 20|  0  |  0  | 1.0G| 156K| 156K | 1.0G|  0   |  0   | 100  | 0 |  0  |  0  |  0   |  0  |  0  | 1024|
|jiptech | 0  | 0  | 25 | 0 | 0 |1024| 0 | 0 | 20|  0  |  0  | 1.0G| 188K| 188K | 1.0G|  0   |  0   | 100  | 0 |  0  |  0  |  0   |  0  |  0  | 1024|
|needsbuy| 0  | 0  | 25 | 0 | 0 |1024| 0 | 0 | 20|  0  |  0  | 1.0G| 5.5M| 5.5M | 1.0G|  0   |  0   | 100  | 0 |  0  |  0  |  0   |  0  |  0  | 1024|
|nivasign| 0  | 0  | 25 | 0 | 0 |1024| 0 | 0 | 20|  0  |  0  | 1.0G| 5.0M| 5.2M | 1.0G|  0   |  0   | 100  | 0 |  0  |  0  |  0   |  0  |  0  | 1024|
|renghaho| 0  | 0  | 25 | 0 | 0 |1024| 0 | 0 | 20|  0  |  0  | 1.0G| 280K| 280K | 1.0G|  0   |  0   | 100  | 0 |  0  |  0  |  0   |  0  |  0  | 1024|
+--------+----+----+----+---+---+----+---+---+---+-----+-----+-----+-----+------+-----+------+------+------+---+-----+-----+------+-----+-----+-----+

Find the top 10 users who have consumed the maximum CPU usage for a period of time.

# lveinfo --from='2015-07-25' --to='2015-08-05' -o cpu_max --display-username
+--------+----+----+----+---+----+----+---+---+---+------+------+-----+-----+------+-----+------+------+------+----+-----+-----+------+-----+------+-----+
|   ID   |aCPU|mCPU|lCPU|aIO|mIO |lIO |aEP|mEP|lEP|aVMem |mVMem |lVMem|aPMem|mPMem |lPMem|aNproc|mNproc|lNproc|EPf |VMemF|PMemF|NprocF|aIOPS|mIOPS |lIOPS|
+--------+----+----+----+---+----+----+---+---+---+------+------+-----+-----+------+-----+------+------+------+----+-----+-----+------+-----+------+-----+
|daygeekc| 2  |100 |100 | 1 |1024|1024| 6 |149| 20|212.6M| 3.9G | 1.0G|25.3M|738.2M| 1.0G|  6   | 152  | 100  |5996|  0  |  0  |  0   |  9  |100573| 1024|
|holidays| 0  | 25 | 25 | 2 |1024|1024| 0 | 20| 20| 341K |209.0M| 1.0G| 1.6M|113.1M| 1.0G|  0   |  22  | 100  | 9  |  0  |  0  |  0   |  1  |12431 | 1024|
|needsbuy| 0  | 25 | 25 | 1 |1024|1024| 0 | 15| 20| 1.5M |524.6M| 1.0G| 7.0M|657.4M| 1.0G|  0   |  15  | 100  | 0  |  0  |  0  |  0   |  0  | 2270 | 1024|
|renghaho| 0  | 25 | 25 | 0 |1024|1024| 0 | 20| 20| 26K  |265.8M| 1.0G| 293K|666.6M| 1.0G|  0   |  20  | 100  | 46 |  0  |  0  |  0   |  0  | 3517 | 1024|
|royaljo | 0  | 25 | 25 | 0 |1020|1024| 0 | 2 | 20| 884  |35.5M | 1.0G| 154K|122.9M| 1.0G|  0   |  2   | 100  | 0  |  0  |  0  |  0   |  0  |  95  | 1024|
|workstud| 0  | 25 | 25 | 3 |1024|1024| 0 | 20| 20| 1.0M |650.1M| 1.0G| 7.1M|688.9M| 1.0G|  0   |  20  | 100  | 3  |  0  |  0  |  0   |  0  | 2302 | 1024|
|  619   | 0  | 25 | 25 | 2 |1024|1024| 0 | 20| 20| 564K |331.9M| 1.0G| 1.9M|718.8M| 1.0G|  0   |  21  | 100  |214 |  0  |  0  |  0   |  1  | 6145 | 1024|
|  620   | 0  | 25 | 25 | 0 |1024|1024| 0 | 3 | 20| 48K  |39.3M | 1.0G| 744K|82.0M | 1.0G|  0   |  3   | 100  | 0  |  0  |  0  |  0   |  0  | 2011 | 1024|
|brockcoi| 0  | 25 | 25 | 0 |1024|1024| 0 | 7 | 20| 84K  |126.0M| 1.0G| 797K|296.9M| 1.0G|  0   |  7   | 100  | 0  |  0  |  0  |  0   |  0  | 195  | 1024|
|ginnyhel| 0  | 25 | 25 | 0 |1024|1024| 0 | 3 | 20|  1K  |35.4M | 1.0G| 187K|99.5M | 1.0G|  0   |  3   | 100  | 0  |  0  |  0  |  0   |  0  | 315  | 1024|
+--------+----+----+----+---+----+----+---+---+---+------+------+-----+-----+------+-----+------+------+------+----+-----+-----+------+-----+------+-----+

Find specific user statistics for a specific period of time.

# lveinfo --from='2015-08-01' --to='2015-08-05' --user=daygeekc --display-username
+-----------+-----------+----+----+----+---+---+---+---+
|    From   |     To    |aCPU|mCPU|lCPU|aEP|mEP|lEP|EPf|
+-----------+-----------+----+----+----+---+---+---+---+
|07-31 23:30|08-01 00:30| 1  | 55 |100 | 0 | 1 | 0 | 0 |
|08-01 00:30|08-01 01:30| 0  | 26 |100 | 0 | 2 | 0 | 0 |
|08-01 01:30|08-01 02:30| 7  | 79 |100 | 0 | 2 | 0 | 0 |
|08-01 02:30|08-01 03:30| 0  | 21 |100 | 0 | 2 | 0 | 0 |
|08-01 03:30|08-01 04:30| 0  | 19 |100 | 0 | 2 | 0 | 0 |
.
.
|08-04 15:30|08-04 16:30| 1  | 31 |100 | 0 | 2 | 0 | 0 |
|08-04 16:30|08-04 17:30| 1  | 36 |100 | 0 | 2 | 0 | 0 |
|08-04 17:30|08-04 18:30| 1  | 39 |100 | 0 | 1 | 0 | 0 |
|08-04 18:30|08-04 19:30| 2  | 31 |100 | 0 | 2 | 0 | 0 |
|08-04 19:30|08-04 20:30| 4  | 39 |100 | 0 | 2 | 0 | 0 |
|08-04 20:30|08-04 21:30| 1  | 38 |100 | 0 | 2 | 0 | 0 |
|08-04 21:30|08-04 22:30| 1  | 36 |100 | 0 | 2 | 0 | 0 |
|08-04 22:30|08-04 23:30| 1  | 31 |100 | 0 | 2 | 0 | 0 |
+-----------+-----------+----+----+----+---+---+---+---+

Other tools that are part of the LVE-stats 2 utility

Creates a chart representing LVE usage for user.

# /usr/sbin/lvechart [--OPTIONS]

Creates a chart representing MySQL usage for user.

# /usr/sbin/dbgovchart [--OPTIONS]

Displays information from system state (snapshots) for user.

# lve-read-snapshot [--OPTIONS]

Creates/recreates database for lve-stats.

# lve_create_db [-h] [--recreate] [--print-sql]

Utility provides information about current MySQL and LVE usage of a running system in JSON format.

# /usr/sbin/cloudlinux-top [--OPTIONS]

Utility provides historical information about resource usage.

# /usr/sbin/cloudlinux-statistics [--OPTIONS]

6) cagefsctl Command Usage

CageFS is a virtualized file system per user that connects each client individually, preventing users from viewing each other and their sensitive information.

In addition, CageFS prevents a number of attacks, including most privilege escalation and information disclosure attacks.

cagefsctl is used to manage CageFS. It allows you to initialize and update CageFS, as well as enable/disable CageFS for individual users.

Syntax: /usr/sbin/cagefsctl [-OPTIONS]

Initialize CageFS (create CageFS if it does not exist)

# /usr/sbin/cagefsctl --init

List users that added in CageFS

# /usr/sbin/cagefsctl --list-enabled
190 enabled user(s)
absolute
adhavacashew
aishwary
.
.
mageshco
.
.

List disabled users.

# /usr/sbin/cagefsctl --list-disabled
2 disabled user(s)
mageshco
whmza

7) MySQL Governor Usage

MySQL Governor monitors the CPU and disk IO usage of each user in real time using the dbtop application and triggers MySQL queries based on LVE limits.

This will automatically detect and kill long-running queries.

This monitor MySQL usage. It requires db_governor to be running. It shows usage for the current, mid and long intervals.

# dbtop [-OPTIONS]

dbctl

# dbctl command [parameter] [options]

Displays information about DB Governor historical usage.

# lveinfo --dbgov [options]

dbgovchart is analog of lvechart tool to create charts representing customer’s to MySQL usage.

# /usr/sbin/dbgovchart [OPTIONS]

8) cl-quota (Inode) Usage

cl-quota utility is designed to control disk quotas.

Syntax: /usr/bin/cl-quota [options]

Print inode limits for all users.

# /usr/bin/cl-quota | more
                              id     inodes_used     inodes_soft     inodes_hard
--------------------------------------------------------------------------------
                               0               -               0               0
                               1              57               0               0
                               2               3               0               0
                              25             221               0               0
                              27            9529               0               0
                              47             183               0               0
                              68               2               0               0
                              89              27               0               0
                              97               8               0               0
                              99               4               0               0
                             173               4               0               0
                             497               4               0               0
                             498               1               0               0

Print inode limits for particular user.

# /usr/bin/cl-quota -u daygeekc
                              id     inodes_used     inodes_soft     inodes_hard
--------------------------------------------------------------------------------
                             621           15294               0               0

9) PHP Selector Usage

PHP Selector is a CloudLinux component that sits on top of CageFS. It allows each user to select required PHP version and it’s module based on their needs. PHP Selector requires account to have CageFS enabled to work.

Lists all available alternatives for an interpreter.

# selectorctl --list

5.2 5.2.17 /opt/alt/php52/usr/bin/php-cgi
5.3 5.3.28 /opt/alt/php53/usr/bin/php-cgi
5.4 5.4.23 /opt/alt/php54/usr/bin/php-cgi
5.5 5.5.7 /opt/alt/php55/usr/bin/php-cgi

It shows the current PHP version of the user.

# selectorctl --user-current --user=username

Use the following command to set specific version of the PHP to user.

# selectorctl --set-user-current=5.4 --user=username

List users that use particular version of PHP. For instance, to see all users that use PHP version 5.3.

# selectorctl --list-users --version=5.3

Switch the PHP version for the user from one version to another.

# selectorctl --user=user1 --change-to-version=5.2 --version=5.3

Magesh Maruthamuthu

Love to play with all Linux distribution

You may also like...