How to scan for new disks in CentOS 7 without Rebooting

After adding a new Hard disk to the virtual machine, now run the following commands to expand the disk space in the physical volume of the Operating System without rebooting the virtual machine by Re-scanning the SCSI Bus and then adding SCSI Device.

# ls /sys/class/scsi_host/

# echo “- – -” > /sys/class/scsi_host/host0/scan

# echo “- – -” > /sys/class/scsi_host/host1/scan

# echo “- – -” > /sys/class/scsi_host/host2/scan

Fixing broken roundcube installation on Directadmin servers

# ./build roundcube
Inserting data to mysql and creating database/user for roundcube...
ERROR 1142 (42000) at line 37 in file: 'SQL/mysql.initial.sql': REFERENCES command denied to user 'da_roundcube'@'localhost' for table 'users'
Database created, da_roundcube password is zITssQKiFHzB8sv
Editing roundcube configuration...
Replacing mod_php5 with mod_php7 in .htaccess
Roundcube 1.3.8 has been installed successfully.
Executing database schema update.
Updating database schema (2013011000)... [OK]
Updating database schema (2013042700)... [OK]
Updating database schema (2013052500)... [OK]
Updating database schema (2013061000)... [FAILED]
Error 500: Error in DDL upgrade 2013061000: [1146] Table 'da_roundcube.cache' doesn't exist
Reloading php-fpm72.

To fix this, simply delete all the tables in the da_roundcube database.

and run the SQL script found in /var/www/html/roundcube/SQL/mysql.initial.sql

Linux: Find Out Which Process Is Listening Upon a Port

How do I find out running processes were associated with each open port? How do I find out what process has open tcp port 111 or udp port 7000 under Linux?
You can the following programs to find out about port numbers and its associated process:

  1. netstat – a command-line tool that displays network connections, routing tables, and a number of network interface statistics.
  2. fuser – a command line tool to identify processes using files or sockets.
  3. lsof – a command line tool to list open files under Linux / UNIX to report a list of all open files and the processes that opened them.
  4. /proc/$pid/ file system – Under Linux /proc includes a directory for each running process (including kernel processes) at /proc/PID, containing information about that process, notably including the processes name that opened port.

You must run above command(s) as the root user.

netstat example

Type the following command:
# netstat -tulpn
Sample outputs:

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0*               LISTEN      1138/mysqld
tcp        0      0   *               LISTEN      850/portmap
tcp        0      0    *               LISTEN      1607/apache2
tcp        0      0 *               LISTEN      910/rpc.statd
tcp        0      0*               LISTEN      1467/dnsmasq
tcp        0      0    *               LISTEN      992/sshd
tcp        0      0 *               LISTEN      1565/cupsd
tcp        0      0  *               LISTEN      3813/transmission
tcp6       0      0 :::22                   :::*                    LISTEN      992/sshd
tcp6       0      0 ::1:631                 :::*                    LISTEN      1565/cupsd
tcp6       0      0 :::7000                 :::*                    LISTEN      3813/transmission
udp        0      0   *                           850/portmap
udp        0      0   *                           910/rpc.statd
udp        0      0*                           1467/dnsmasq
udp        0      0    *                           1467/dnsmasq
udp        0      0    *                           3697/dhclient
udp        0      0  *                           3813/transmission
udp        0      0 *                           910/rpc.statd   

TCP port 3306 was opened by mysqld process having PID # 1138. You can verify this using /proc, enter:
# ls -l /proc/1138/exe
Sample outputs:

lrwxrwxrwx 1 root root 0 2010-10-29 10:20 /proc/1138/exe -> /usr/sbin/mysqld

You can use grep command to filter out information:
# netstat -tulpn | grep :80

Sample outputs:

tcp        0      0    *               LISTEN      1607/apache2

Reset root’s MySQL password

If you have forgotten MYSQL password and need to reset it.

Step-by-step guide

Not the Server root user

A common issue is confusing the Server root user with the MySQL root user.

The Server root user is the server’s main user. The MySQL root user has complete control over MySQL only. The two ‘root’ users are not connected in any way.

Stop MySQL

The first thing to do is stop MySQL. If you are using Ubuntu or Debian the command is as follows:

sudo /etc/init.d/mysql stop

For CentOS, Fedora, and RHEL the command is:

sudo /etc/init.d/mysqld stop

Safe mode

Next we need to start MySQL in safe mode – that is to say, we will start MySQL but skip the user privileges table. Again, note that you will need to have sudo access for these commands so you don’t need to worry about any user being able to reset the MySQL root password:

sudo mysqld_safe --skip-grant-tables &

Note: The ampersand (&) at the end of the command is required.


All we need to do now is to log into MySQL and set the password.

mysql -u root

Note: No password is required at this stage as when we started MySQL we skipped the user privileges table.

Next, instruct MySQL which database to use:

use mysql;

Reset Password

Enter the new password for the root user as follows:

update user set password=PASSWORD("mynewpassword") where User='root';

and finally, flush the privileges:

flush privileges;


Now the password has been reset, we need to restart MySQL by logging out:


and simply stopping and starting MySQL.

On Ubuntu and Debian:

sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start

On CentOS and Fedora and RHEL:

sudo /etc/init.d/mysqld stop
sudo /etc/init.d/mysql start


Test the new password by logging in:

mysql -u root -p

You will be prompted for your new password.

How to remove / purge MySQL binglos ?

By default, MySQL 5.x and above enables MySQL Binary Log. Keeping MySQL Binary Log will take up a lot of disk space for long run. Older MySQL Binary log can be removed in order to keep your hard disk space free.

MySQL Binary Log stores query event such as add, delete and update in a very details way.

The Binary Log is used for two main purposes:

  1. Replication between master and slave server, statement that has been made on Master server will later send it to slave server.
  2.  Recovery, certain recovery job required data stored in MySQL Binary Log.

Binlogs Location

MySQL binglogs usually stored in mysql root folder, in centos it’s usaully (/var/lib/mysql/) 

To cleanup binary logs on a slave server:

  1. Login to mysql from the command lineshell> mysql -u username -p
  2. To clean binary logs older than a specific date.mysql> PURGE BINARY LOGS BEFORE ‘2018
  3. -12-15 00:00:00′;

Fixing “InnoDB: Error: log file ./ib_logfile0 is of different size” Error

After changing INODDB parameters (at /etc/my.cnf) there might be an error starting MYSQL.

Jun 12 2012

So you wanted to change the value of “innodb_log_file_size” on your mysql server.

As it happens, you can’t just change it the “my.cnf” file, restart and make it work. If you do, Mysql will refuse to start and throw this error instead. You can the details of the startup error in your mysql error log file. 

To safely change this setting follow these steps

Make sure if you are changing things on a production server, you take due care of the mysql downtime due to the changes and restart, and have backups to recover quickly in case something goes wrong.

Step-by-step guide

  1. Shutdown your mysql server, make sure to check the error log that the shutdown had no issues
  2. Move the “ib_logfile0″ and “ib_logfile1″ files from your mysql data directory.
  3. Change “innodb_log_file_size” to your desired setting.
  4. Restart mysql. Check the error log to make sure everything started successfully, mysql may complain that the log files don’t exist, it will make new ones and start. rendering macro ‘contentbylabel’ : parameters should not be empty

CentOS Performance Tuning Checklist

1. Maximum Number of open files.

The default configuration for maximum open files allowed per process on CentOS is set at a very low number (1024), so let’s change this to 100K

Add the following 2 lines to the end of limits.conf file.

# vi /etc/security/limits.conf
*   soft   nofile    100000
*   hard   nofile    100000

Run ulimit -n to change the current runtime value of max open files.

ulimit -n 100000

2. Turn off filesystem access times.

/dev/sda1       /   xfs	defaults 0 0

Change it to

/dev/sda1       /   xfs	defaults,noatime,nodiratime	0 0

3. Change default I/O Scheduler

echo "noop" > /sys/block/sda/queue/scheduler
vi /etc/rc.local
# Add the following line to the end of the file.
echo "noop" > /sys/block/sda/queue/scheduler
chmod a+x /etc/rc.local