[HOW TO] Linux Server High Load

Hello,

I didn't write a article long time. In fact, I don't need to explain anymore, but I have a busy. I have changed the company. Today, I come back. Roughly two days ago, I met the incident about high load. My colleagues did to it, bu he didn't find out anything.

He told me: Tien, I didn't see anything related the high load. Because, as you see, the load of top process is okay.

Tien: Okay, I will take care of this.


And then, I started to find out.


top - 09:55:39 up 63 days, 21:42, 4 users, load average: 14.26, 14.27, 14.25Tasks: 168 total, 1 running, 167 sleeping, 0 stopped, 0 zombie%Cpu(s): 0.7 us, 0.1 sy, 0.0 ni, 99.2 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 stKiB Mem : 7747272 total, 1385396 free, 1415356 used, 4946520 buff/cacheKiB Swap: 0 total, 0 free, 0 used. 5655232 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1 root 20 0 190720 3760 2428 S 0.0 0.0 6:09.07 systemd 2 root 20 0 0 0 0 S 0.0 0.0 0:00.29 kthreadd 3 root 20 0 0 0 0 S 0.0 0.0 0:03.07 ksoftirqd/0


Firstly, I see the process is running normally, and taking a normal performance load. But, the load average always high as above.

So, what happened?
After went around, I saw the php-fpm as potential event. It always sit on top process. So, I used the HTOP to see the STATE of process. And, I saw 14 uninterruptible sleep PHP-FPM: POOL WWW at here.

What is D - uninterruptible sleep state?
An uninterruptable process is a process which happens to be in a system call (kernel function) that cannot be interrupted by a signal. Unlike interruptible sleep, you cannot wake up this process with a signal. That is why many people dread seeing this state. You can't kill such processes because killing means sending SIGKILL signals to processes. Of course, it stays at here.

What happened in uninterruptible sleep PHP-FPM?
I used strace command to see what is going on? 
AWS:[root@71 ~]# strace -p 5087strace: Process 5087 attachedflock(10, LOCK_EX) = 0gettimeofday({1510306801, 695208}, NULL) = 0gettimeofday({1510306801, 695321}, NULL) = 0open("/data/shared/partners/typo3temp/var/locks/flock_cc5e752af9d3afa9e93ad2244046b482", O_WRONLY|O_CREAT, 0666) = 11fstat(11, {st_mode=S_IFREG|0664, st_size=0, ...}) = 0...gettimeofday({1510306801, 702748}, NULL) = 0flock(11, LOCK_EX|LOCK_NB) = -1 EAGAIN (Resource temporarily unavailable)gettimeofday({1510306801, 702897}, NULL) = 0gettimeofday({1510306801, 703041}, NULL) = 0...gettimeofday({1510306801, 833556}, NULL) = 0chmod("/data/partners/www/typo3temp/var/locks/flock_cc5e752af9d3afa9e93ad2244046b482", 0664) = 0gettimeofday({1510306801, 837579}, NULL) = 0flock(12, LOCK_EX|LOCK_NB) = -1 EAGAIN (Resource temporarily unavailable)(and more if you use strace -p 5087 )

It means that this PHP-FPM is uninterruptible sleep, but it still try to get the resource in /data/partners/www/typo3temp/var/locks/flock_*. It made the System Load Averages up by the time.

Interestingly, /data/partners/www/ is network mount
e-----.amazonaws.com:/ 8.0E 994M 8.0E 1% /data/shared

So, I think that the Linux load averages increase due to a disk (or network mount) I/O workload, not just CPU demand. In my mind, it's mean to reflect demand in a more general sense, rather than just CPU demand (e.g Disk Performance Read/ Write ). It also is a reason that Linux engineer changed from "CPU load averages" to what one might call "System Load Averages".

Finally, I cannot make sure about kill uninterruptible sleep process, so I suggest you should restart the PHP-FPM process to kill them.

To investigate this problem, I read some useful link. you can refer here & here.

Tiến Phan - R0039

Knowledge is Endless

Sharing for Success

[HOW TO] install x11vnc on CentOS 6/ CentOS 7

Few weeks ago I received the requirement from developer when he need to remote control to server on company.

I talked him: please wait me a minutes
And then, I installed x11vnc on server. You was familiar with x11vnc, if you didn't also nothing. On this article I will show you how to install x11vnc? how to implement it?

Firstly you need to install x11vnc from repositories as below:
yum search x11vncyum install x11vnc.x86_64

After that, you need to create x11vnc file in path /etc/xinetd.d/x11vnc
vim /etc/xinetd.d/x11vnc
service x11vnc
{
port = 5900
type = UNLISTED
socket_type = stream
protocol = tcp
wait = no
user = long
server = /usr/bin/x11vnc
server_args = -inetd -o /home/long/log/x11vnc.log -display :0 -auth /var/gdm/:0.Xauth -passwdfile /home/long/.vncpasswd -many -bg
disable = no
}
You can see that I defined the display, vncpasswd, background or foreground service running. You also change it by your way.

And then, you start xinetd
service xinetd start

Okay, now you have a x11vnc service. Next, importantly, I set the x11vnc's password. At least It helps me to prevent the victim to remote ours server.
bozo@dev01  ~  x11vnc -storepasswd ~/.vncpasswd  
Enter VNC password:
Verify password:  
Write password to /home/bozo/.vncpasswd?  [y]/n y
Password written to: /home/bozo/.vncpasswd
bozo@dev01  ~  -rw------- 1 long long 8 Jul 10 20:46 /home/long/.vncpasswd 
ls -lrt
-rw------- 1 bozo bozo 8 Jul 10 20:46 /home/bozo/.vncpasswd 

So how to vnc?
You need to ssh to x11vnc's server, and run following command line:
bozo@dev01  ~  x11vnc -rfbauth ~/.vncpasswd

On developer computer, we install VNC viewer/ client. And now they can access server by the information:
vnc server: IP/ DNS:5901
[IP server]:[VNC Port]

Please notice you don't kill terminal above step to keep session VNC.

Finally the developer inputs the VNC's password to authenticate.

Tiến Phan - R0039

Knowledge is Endless

Sharing for Success

[HOW TO] install erlang, elixir on CentOS 6

Roughly 30 minutes ago I installed Erlang & Elixir into our server. It doesn't matter for everyone but until when everyone need help lolz.

So I write down the shortly instruction below. 

I. What is erlang & elixir? 
Please google to know it.

II. How to install?
Please ensure wget already installed on your server. The next commands retrieve a package that adds a new repository to CentOS's repository.
[@ ~]# wget http://packages.erlang-solutions.com/erlang-solutions-1.0-1.noarch.rpm
[@ ~]## rpm -Uvh erlang-solutions-1.0-1.noarch.rpm
[@ ~]# yum search erlang
[@ ~]# yum install -y erlang.x86_64 
[@ ~]# erl --versionErlang/OTP 20 [erts-9.0] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:10] [hipe] [kernel-poll:false]Eshell V9.0  (abort with ^G)1> 
Well done, you have already installed erlang.

Next you need to download elixir. In this article, I use elixir 1.4.2 and you can download at here . Also you can download from elixir github officially follows:

If you download source code elixir, you don't have to compile. If you download binary on github, you have to install as below:
[@ ~]# git clone https://github.com/elixir-lang/elixir.git
[@ ~]# make clean test
Now, you have to add Elixir's bin path to your PATH environment variable. Otherwise, Elixir will not work. To do so, you open .bash_profile
[teamcity@s04 ~]$ vim ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi
# User specific environment and startup programs
export ELIXIR_HOME=/opt/elixir
export PATH=$PATH:$ELIXIR_HOME/bin
To verify Elixir is work or not, run:
[teamcity@s04 ~]$ iex
Erlang/OTP 20 [erts-9.0] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:10] [hipe] [kernel-poll:false]
Interactive Elixir (1.4.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> 
If you see as above, elixir works. Cheer!

III. If you want to install the specify elixir version
You have to go elixir's github , and then you download the specify version of elixir. Next, you need to extract the elixir compression file.

After that, you go to elixir directory & combine as below
cd otp
./otp_build autoconf
./configure
make
make install


Tiến Phan - R0039

Knowledge is Endless

Sharing for Success

[HOW TO] set umask for user has /sbin/nologin environment

Come back to the last week, I worked on case "change umask for SFTP/ SSH user"

At that time, I simply thought that it is umask. So I added umask to ~/.bashrc and ~/.bash_profile.

But nothing to change. It means that I need think logically.

User login -> ssh -> pam.d/ssh -> /etc/profile (~/.bash_profile)

Why? 
A few second I see that user's ssh/ sftp has shell environment is /sbin/nologin. So it is not affected by ~/.bash_profile, also /etc/profile

And then I need to add "umask" on "ssh" step of flowchart:
User login -> ssh -> pam.d/ssh -> /etc/profile (~/.bash_profile)

I go to /etc/ssh/sshd_config
# override default of no subsystems#Subsystem      sftp    /usr/libexec/openssh/sftp-serverSubsystem       sftp internal-sftpGatewayPorts no

add "-u 0022" umask as below
# override default of no subsystems
#Subsystem      sftp    /usr/libexec/openssh/sftp-server
Subsystem       sftp internal-sftp -u 0022
GatewayPorts no

After that, I re-login & create a file and I see that umask' file is 0022.
That's cool!

Tiến Phan - R0039

Knowledge is Endless

Sharing for Success

[HOW TO] check slot RAM information on Linux Operating System

One day you need to increase memory for physical server at Data-center. But you can't shutdown it to check the available slot. What's up next?

Luckily if you are using Linux Operating System. Because Linux has dmidecode to check hardware information.

I will tell you about dmidecode. In general you need to deeply understand what are you doing. I learned this mythology by my close friend.

dmidecode  is a tool for dumping a computer’s DMI (some say SMBIOS) table con-tents in a human-readable format. This table contains  a  description of the system’s  hardware  components,  as well as other useful pieces of information such as serial numbers and BIOS  revision.  Thanks  to  this  table, you  can retrieve  this  information  without  having to probe for the actual hardware. While this is a good point in terms of report speed and  safeness,  this  also makes the presented information possibly unreliable.

Are you know it? ok, let's check.

1. 
#dmidecode
it shows all of mainboard information.

2. 
#dmidecode -t memory
it shows only memory information, both slot available, memory type.

Ok, you get enough.

Tiến Phan - R0039

Knowledge is Endless

Sharing for Success