August 2025
M T W T F S S
 123
45678910
11121314151617
18192021222324
25262728293031

Categories

August 2025
M T W T F S S
 123
45678910
11121314151617
18192021222324
25262728293031

Quick postfix queue depth script

for i in `ls -al /var/spool/postfix |grep ‘^d’|awk ‘{print $9}’|grep -v ‘\.$’`; do c=`find $i|wc -l`; echo “$c $i”; done;

Install Kernel 3.10 on CentOS 6.7

CentOS 6.7 ships with kernel 2.6 and it’s a quite old for now(CentOS 7 already comes with 3.10), but compile a kernel on CentOS is a mess and it’s not recommended.
But fear no more, guys from Elrepo took care of that for us and made a package, let’s see how we can install it.

Enable ELRepo Project repository

rpm –import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -Uvh http://www.elrepo.org/elrepo-release-6-6.el6.elrepo.noarch.rpm

Install the kernel

yum –enablerepo=elrepo-kernel install kernel-lt

Configure grub

You also need edit /etc/grub.conf to change the kernel order, change default from 1 to 0, must looks like the below:

default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (3.10.55-1.el6.elrepo.x86_64)
root (hd0,0)
kernel /vmlinuz-3.10.55-1.el6.elrepo.x86_64 ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD rd_LVM_LV=VolGroup/lv_swap SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=VolGroup/lv_root rd_NO_DM  KEYBOARDTYPE=pc KEYTABLE=br-abnt2 rhgb quiet

Reboot and profit!

reboot

Install LAMP + phpMyAdmin on 7 CentOS 7 / RHEL

Install LAMP + phpMyAdmin on 7 CentOS 7 / RHEL

The main attention is now replaced by the MySQL database MariaDB, and therefore representative of the LAMP Linux + Apache + MariaDB + PHP up.

System: The new CentOS 7 using systemd, thus some instruction vary ; now use alternative MariaDB MySQL as the database software, there will also be installed directly MariaDB.

Set HOSTNAME

echo “HOSTNAME=clusterserver3.rmohan.com” >> /etc/sysconfig/network
hostname “clusterserver3.rmohan.com”

INSTALL VIM

yum -y install vim

To make a color display code, and also supports line numbers and mouse positioning mark, you need to edit vim configuration file:

vim /etc/vimrc

set nu
set mouse=a

update configuration file /etc/hosts

192.168.1.22 clusterserver3.rmohan.com clusterserver3

remove the dhcp

systemctl list-unit-files –type=service dhcp

add timezone

ln -sf /usr/share/zoneinfo/Singapore /etc/localtime
timedatectl set-timezone Asia/Singapore ; timedatectl

yum update

install http

yum install httpd

http://192.168.1.22

[root@clusterserver3 ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@clusterserver3 ~]#

firewall-cmd –add-service=http –permanent
firewall-cmd –add-service=https –permanent
firewall-cmd –zone=public –add-port=22/tcp –permanent

systemctl restart firewalld

firewall-cmd –list-all

# firewall-cmd –state
# firewall-cmd –list-all
# firewall-cmd –list-interfaces
# firewall-cmd –get-service
# firewall-cmd –query-service service_name
# firewall-cmd –add-port=8080/tcp

install Mariadb

yum install mariadb-server mariadb

systemctl enable mariadb

[root@clusterserver3 ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@clusterserver3 ~]#

top -u mysql

systemctl start mariadb
systemctl stop mariadb
systemctl restart mariadb
systemctl disable mariadb
systemctl is-active mariadb

Test MariaDB server in the local virtual machine CentOS 7 system, every time execution mysql command will always encounter “ERROR 2006 (HY000): MySQL server has gone away” error. Calibration of the time within a virtual machine, the aforementioned problems hours. Is there a necessary connection between the two is not to say, temporarily be recorded.

Execute an instruction casually in MariaDB, whether create database or just flush privileges or, before the implementation of the results will show a similar instruction such output,

MariaDB [(none)]> select now ();
ERROR 1305 (42000): FUNCTION now does not exist
MariaDB [(none)]>

mysql_secure_installation

[root@clusterserver3 ~]# mysql_secure_installation
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we’ll need the current
password for the root user.  If you’ve just installed MariaDB, 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):
ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)
Enter current password for root (enter for none):
OK, successfully used password, moving on…

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] Y
New password:
Re-enter new password:
Sorry, passwords do not match.

New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
… Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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] y
… 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] y
… Success!

By default, MariaDB 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] y
– 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] y
… Success!

Cleaning up…

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

Thanks for using MariaDB!
[root@clusterserver3 ~]#

MariaDB [(none)]> show global variables like ‘max_allowed_packet’;
+——————–+———+
| Variable_name      | Value   |
+——————–+———+
| max_allowed_packet | 1048576 |
+——————–+———+
1 row in set (0.00 sec)

MariaDB [(none)]>

MariaDB [(none)]> set global max_allowed_packet=1024*1024*16;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> show global variables like ‘max_allowed_packet’;
+——————–+———-+
| Variable_name      | Value    |
+——————–+———-+
| max_allowed_packet | 16777216 |
+——————–+———-+
1 row in set (0.00 sec)

MariaDB [(none)]>
time in centos 7
yum -y -q install ntp
ntpdate -s ntp.org
date

MariaDB [(none)]> select now();
+———————+
| now()               |
+———————+
| 2016-01-03 16:18:47 |
+———————+
1 row in set (0.00 sec)

MariaDB [(none)]>
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

MariaDB [(none)]> select now();
+———————+
| now()               |
+———————+
| 2016-01-03 07:15:34 |
+———————+
1 row in set (0.00 sec)

MariaDB [(none)]>

yum install php

cp /etc/php.ini ~/confbak/php.ini.bak
cp /etc/httpd/conf.d/php.conf ~/confbak/httpd/conf.d/php.conf.bak
cp /etc/httpd/conf.modules.d/10-php.conf ~/confbak/httpd/conf.modules.

vi /etc/php.ini

error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR
display_errors = Off
log_errors = On
max_execution_time = 300
memory_limit = 32M

yum install php-mysql

yum install http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7

yum install phpmyadmin

cp /etc/httpd/conf.d/phpMyAdmin.conf ~/confbak/httpd/conf.d/phpMyAdmin.conf.bak

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

<Directory /usr/share/phpMyAdmin/>
………
</Directory>

Require ip 127.0.0.1
Require ip ::1

cp /etc/phpMyAdmin/config.inc.php ~/confbak/config.inc.php.bak
vi /etc/phpMyAdmin/config.inc.php

$cfg[‘blowfish_secret’] = ‘password’

systemctl restart httpd

SSH terminal login in linux

Windows VPS remotely manage the SSH login tool is PuTTY , but Linux, there is no need to use it. Linux, Unix (including Mac iOS) are bound to have a built-in command-line terminal, built OpenSSH commands. VPS Linux system through which to log on to be more convenient.

Open a command line terminal in Linux, the direct input instruction,

 

ssh <username>@<serverdomain or IP> -p <port>

Under normal circumstances, where ? indicates the current users of the system root directory, so this document may be /home/username/.ssh/config (system depends on the use of a).

Now enter the configuration, such as the above command used example, a user named username, VPS server server_IP, SSH service port on the server is 22, then,

 
cat >> ~/.ssh/config <<EOF
Host your_alias
    User username
    Hostname server_IP
    Port 22
EOF


Here your_alias can be any aliases you want, such as server.  Now you can simply type,
ssh your_alias 


This configuration can also be combined with something else to features such as connection remains.  We do not want to make it in time to send a meaningless data operations to keep the connection will not be disconnected server automatically at regular intervals 
cat "ServerAliveInterval 30" >> ~/.ssh/config


 

Swap on CentOS 7

we begin, we should take a look at our server’s storage to see if we already have some swap space available. While we can have multiple swap files or swap partitions, one should generally be enough.
We can see if the system has any configured swap by using swapon, a general-purpose swap utility. With the -s flag, swapon will display a summary of swap usage and availability on our storage device:

swapon -s

If nothing is returned by the command, then the summary was empty and no swap file exists.
Another way of checking for swap space is with the free utility, which shows us the system’s overall memory usage. We can see our current memory and swap usage (in megabytes) by typing:



[root@clusterserver3 ~]# free  -m
              total        used        free      shared  buff/cache   available
Mem:           3704         104        3464           8         135        3433
Swap:          3967           0        3967
[root@clusterserver3 ~]#

create a Swap File

Now that we know our available storage space, we can go about creating a swap file within our filesystem. We will create a file called swapfile in our root (/) directory, though you can name the file something else if you prefer. The file must allocate the amount of space that we want for our swap file.
 The fastest and easiest way to create a swap file is by using fallocate. This command creates a file of a preallocated size instantly. We can create a 4 gigabyte file by typing:
 fallocate -l 4G /swapfile


[root@clusterserver3 /]# ls -ltr /swapfile
-rw-r--r-- 1 root root 4294967296 Jan  2 00:34 /swapfile
[root@clusterserver3 /]#

Enable a Swap File

Right now, our file is created, but our system does not know that this is supposed to be used for swap. We need to tell our system to format this file as swap and then enable it.
 Before we do that, we should adjust the permissions on our swap file so that it isn't readable by anyone besides the root account. Allowing other users to read or write to this file would be a huge security risk. We can lock down the permissions with chmod:
 chmod 600 /swapfile


[root@clusterserver3 /]# mkswap /swapfile
Setting up swapspace version 1, size = 4194300 KiB
no label, UUID=75cdf9e6-f034-4aed-845e-59035534eeaf
[root@clusterserver3 /]#

Make the Swap File Permanent

Our swap file is enabled at the moment, but when we reboot, the server will not automatically enable the file for use. We can change that by modifying the fstab file, which is a table that manages filesystems and partitions.
 Edit the file with sudo privileges in your text editor:
vi /etc/fstab
At the bottom of the file, you need to add a line that will tell the operating system to automatically use the swap file that you created:
/swapfile   swap    swap    sw  0   0


weak Your Swap Settings (Optional)

There are a few options that you can configure that will have an impact on your system's performance when dealing with swap. These configurations are optional in most cases, and the changes that you make will depend on your application needs and your personal preference.

Swappiness

The swappiness parameter determines how often your system swaps data out of memory to the swap space. This is a value between 0 and 100 that represents the percentage of memory usage that will trigger the use of swap.
 With values close to zero, the system will not swap data to the drive unless absolutely necessary. Remember, interactions with the swap file are "expensive" in that they are a lot slower than interactions with memory, and this difference in read and write speed can cause a significant reduction in an application's performance. Telling the system not to rely on the swap as much will generally make your system faster.
 Values that are closer to 100 will try to put more data into swap in an effort to keep more memory free. Depending on your applications' memory profile, or what you are using your server for, this might be the better choice in some cases.
 We can see the current swappiness value by reading the swappiness configuration file:
cat /proc/sys/vm/swappiness
30
CentOS 7 defaults to a swappiness setting of 30, which is a fair middle ground for most desktops and local servers. For a VPS system, we'd probably want to move it closer to 0.
 We can set the swappiness to a different value by using the sysctl command. For instance, to set the swappiness to 10, we could type:
sudo sysctl vm.swappiness=10
vm.swappiness = 10
This setting will persist until the next reboot. To make the setting persist between reboots, we can add the outputted line to our sysctl configuration file:
sudo nano /etc/sysctl.conf
Add your swappiness setting to the bottom of the file:
vm.swappiness = 10
When you are finished adding the line, you can save and close the file. The server will now automatically set the swappiness to the value you declared on each bootup.

Cache Pressure

Another related value that you might want to modify is the vfs_cache_pressure. This setting affects the storage of special filesystem metadata entries. Constantly reading and refreshing this information is generally very costly, so storing it on the cache for longer is excellent for your system's performance.
 You can see the current value of this cache pressure by querying the proc filesystem again:
cat /proc/sys/vm/vfs_cache_pressure
100
As it is currently configured, our system removes inode information from the cache far too quickly. We can set this to a more conservative setting, like 50, by using sysctl:
sudo sysctl vm.vfs_cache_pressure=50
vm.vfs_cache_pressure = 50
Again, this is only valid for our current session. We can change that by adding it to our configuration file, like we did with our swappiness setting:
sudo nano /etc/sysctl.conf
At the bottom, add the line that specifies your new value:
vm.vfs_cache_pressure = 50


 

add grub password on centos 7 Rhel 7 and Fedora oracle linux

Red Hat Enterprise Linux 7/CentOS 7 system that requires manual entry of a bootloader password in order to boot any future kernels Adding users and custom menuentry

.... --user SOMEUSER  directives to /etc/grub.d/40_custom as  per the the RHEL7 System Administrator’s Guide is great, but how can you configure grub so that ALL existing & future kernels require a password in order to boot?

 

  • Edit /etc/grub.d/10_linux, changing the line like the following:
    	CLASS="--class gnu-linux --class gnu --class os --unrestricted"

    to a line exactly like the following:

    	CLASS="--class gnu-linux --class gnu --class os --users '' "

    This could be done with a simple sed command, e.g., by running the following from a root shell:

    	sed -i "/^CLASS=/s/unrestricted/users '' /" /etc/grub.d/10_linux

 

Add a user to /etc/grub.d/40_custom as described in RHEL7 System Administrator’s Guide, e.g., by running the following from a root shell:

cat >>/etc/grub.d/40_custom <<\EOF
set superusers=”root”
password root test123
EOF
[root@clusterserver3 ~]# grub2-mkpasswd-pbkdf2
Enter password:
Reenter password:
PBKDF2 hash of your password is grub.pbkdf2.sha512.10000.86A0045A177A7C12C3649BE90A5A8CE1C9099EC4BFD50B0D4C1884FA13AD2893738F103C28888A819629DDE735AA1941C15732FB1ACCA9AF05B9E560C74ED474.61E9129DE99E0E7F6B7679534FF849046570C099A244D9D3215D849D5C1940FB50C478DCEFE4CE6086B41CA1BCDA185123166967B3933C0FDD5AA9E537B02505

 

cat >>/etc/grub.d/40_custom <<\EOF
set superusers=”root”
set superusers=”root”
password_pbkdf2  root  grub.pbkdf2.sha512.10000.E4827A5F6322572A56AAD8BC17E665160D4596290AFCB9C45D97DC6E621E7AF6D595946BE5291D9019DD51196835D54DACEB4047AAC3A510790BC2CE3B71BA07.6A5BC9851BD2EA5A505C558632F4FC049C41E0C44C49CDDE43C50DBE45D81FAEDC40A721D5EFA2A18758CE313541CD6035FDA1AA20FD5D7E1491ED2BF714CE4E
EOF

 

 

Reset Your Forgotten Root Password On CentOS 7

Reset Your Forgotten Root Password On CentOS 7

To get started, turn on the machine that you’ve forgotten the root password on. For CentOS 7 devices, you’ll be given 5 seconds at the boot menu to select the operating system kernel to boot into.

That 5 seconds is important, because allows for  admins to select different kernels or edit existing kernel parameters before booting.

At the boot menu, press e to edit the existing kernel (Core) as shown below.

centos7-forgot-root-password

 

Next, scroll down to the list until you see the line underlined below ( ro ) . What we need to do is change that ro to rw and start into a bash shell. It should look like this rw init=/sysroot/bin/sh.

centos7-forgot-root-password-1 centos7-forgot-root-password-2

Change the ro line to rw and add init=/sysroot/bin/sh

rw init=/sysroot/bin/sh

 

centos7-forgot-root-password-3

 

Sometimes you forget stuff. I do. I forget important passwords for important websites sometimes. Retrieving your forgotten passwords for most websites is easy, all one has to do remember few details that were used when signing up for the service to get a password reset for an account.

The difference is forgetting a password to a system or device with no easy way to reset it while locked out. CentOS 7 is one such system. If you forget the root password to your CentOS 7 machine, it’s almost virtually impossible to reset it while you’re locked out.

This brief tutorial is going to show you a simple trick that you can use to reset your forgotten root password for CentOS 7 servers. This will definitely come in handy for webmasters who are locked out of your CentOS machine and can’t sign on.

This tutorial will only work if you have direct access to the machine or serial terminal access with boot menu options. You can’t reset the root password if you’re remotely connected since you need boot menu access.

To get started, turn on the machine that you’ve forgotten the root password on. For CentOS 7 devices, you’ll be given 5 seconds at the boot menu to select the operating system kernel to boot into.

That 5 seconds is important, because allows for  admins to select different kernels or edit existing kernel parameters before booting.

At the boot menu, press e to edit the existing kernel (Core) as shown below.

Changing root password on centos 7

 

Next, scroll down to the list until you see the line underlined below ( ro ) . What we need to do is change that ro to rw and start into a bash shell. It should look like this rw init=/sysroot/bin/sh.

 

forgotten root password on centos 7

 

 

Change the ro line to rw and add init=/sysroot/bin/sh

rw init=/sysroot/bin/sh

changing root password on centos

 

After changing that, press Control + X  or Ctrl + X  on your keyboard to start into single user mode using the bash shell specified above. In this mode, we’re going to change the root password.

In the single user mode, run the command as shown below

chroot /sysroot

centos7-forgot-root-password-4

You’ll be prompted to create and confirm a new password.  After creating the password, run the commands below to update SELinux parameters

touch /.autorelabel

 

FIXING CORRUPT WINDOWS FILES

dism /online /cleanupimage /restorehealth
sfc /scannow

JAVA VERSIONS ON WINDOWS

Slow way

  1. Open your Start Menu
  2. Go to All Programs
  3. Go to Accessories
  4. Right-click Command Prompt
  5. Select Run as administrator
  6. Answer Yes to the following User Account Control question
  1. Go/Make somewhere you want this.
    > c:
    > mkdir \dev\java
    > cd \dev\java
  2. Set up the symlinks
    > mklink /d 1.5 “c:\Program Files\Java\jdk1.5.0_22”
    > mklink /d 1.7 “c:\Program Files\Java\jdk1.7.0”
    > mklink /d 1.6 “c:\Program Files\Java\jdk1.6.0_27”
    > mklink /d active 1.7
  3. Set your JAVA_HOME and PATH environment variables. *
    setx JAVA_HOME “C:\dev\java\active” /m
    setx PATH “%JAVA_HOME%\bin;%PATH%” /m
* The second command assumes you don’t have Java in your PATH already. If you do, you should edit it the usual way instead. Also note that if JAVA_HOME is already set, it will be expanded in the second command.

Now open up a new regular command prompt and run the following.

> java -version
> mvn –version

Both (skip mvn if you don’t have maven installed) should report Java version 1.7.

Swapping

So, let’s say we want to change to java 1.5, we just need to run the following in an elevated command prompt.

> cd \dev\java
> rmdir active && mklink /d active 1.5

If you now repeat the version checks we did in our regular command prompt they should both report version 1.5 instead of 1.7. And we didn’t even have to restart the command prompt.

Shortcut

To prevent us from having to do this manually we could also create a simple bat file. I made one I called swap.bat which I put in the same directory as the symlinks with the following contents.

@echo off
cd \dev\java && rmdir active && mklink /d active %~1

You could then create a short cut to for example c:\dev\java\swap.bat 1.5, set it to run as administrator, and you’d have a two click solution to change the Java version to 1.5. I created one shortcut for each version.

If you have a better way, please leave a comment though. Always on the lookout for things and techniques that can make my developer life simpler

Centos 7 NIC naming rules

Centos7 provide different naming convention is based on the default firmware, topology, location information to allocate.
The advantage of this is that the naming is fully automated, predictable disadvantage is more than eth0 , wlan0 harder to read. For example enp5s0

Naming rules Strategy
The default, systemd will be named interfaces based on the following strategies apply to the naming convention supports.

Rule 1 : For the on-board device naming merger firmware or BIOS provides an index number, if from a firmware or BIOS -readable information on the name, such ENO1 , this name is relatively common, otherwise the rule 2 .

Rule 2 : Naming merger firmware or BIOS provides a PCI-E hot-swappable port index, such as ENS1 , if the information is readable on the use, or the use of rule 3 .

Rule 3 : Naming merge the physical location of the interface hardware, such as enp2s0 , available on naming failure directly to the program 5 .

Rule 4 : Naming merge interface MAC address, such enx78e7d1ea46da , default is not used unless the user chooses to use this program.

Rule 5 : Using the conventional approach, if all the programs have failed, eth0 .

Meaning the first two characters of the
en Ethernet Ethernet
wl WLAN WLAN
ww wireless WAN WWAN
if you are not accustomed to using the new naming convention, you can use the traditional way to restore named edit grub file,
add two variables, then use grub2-mkconfig rebuild the configuration file.

vim /etc/sysconfig/grub
GRUB_CMDLINE_LINUX=”net.ifnames=0 biosdevname=0″
grub2-mkconfig -o /boot/grub2/grub.cfg