[HOW TO] dash_bootstrap_components installed succesfully but no recognised

tphack:master !2 ?2 > python3 app.py                                                                                                                            
Traceback (most recent call last):
  File "/Users/tien.phan/Documents/github/dashboard/app/app.py", line 7, in <module>
    import dash_bootstrap_components as dbc
ModuleNotFoundError: No module named 'dash_bootstrap_components'

It was perfectly installed 
tphack:master !2 ?2 > pip install dash-bootstrap-components                                                                                                      

Requirement already satisfied: dash-bootstrap-components in /usr/local/lib/python3.11/site-packages (1.4.1)

However, when I run the app, I still got this error:
tphack:master !2 ?2 > python3 app.py                                                                                                                            
Traceback (most recent call last):
  File "/Users/tien.phan/Documents/github/dashboard/app/app.py", line 7, in <module>
    import dash_bootstrap_components as dbc
ModuleNotFoundError: No module named 'dash_bootstrap_components'

How to fix? 
I install that package to user folder 
tphack:master !2 ?2 > python -m pip install --user dash-bootstrap-components

python -m explaination: it will locate the module and execute its content as the __main__ module. This allows you to run a module directly from the command line.

tphack:master !2 ?3 > source ./env/bin/activate
tphack:master !2 ?3 > python -m pip install dash-bootstrap-components 

Now it works
tphack:master !2 ?3 > python3 app.py                                                                                                                      py app at 16:00:37
Dash is running on http://0.0.0.0:8050/

INFO:dash.dash:Dash is running on http://0.0.0.0:8050/

[HOW TO] ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

Hello,

I wanted to export the csv file from MySQL command line. And used the guide following the article [HOW TO] Export mysql result to csv file

All are good if there is no any issue.
mysql> select * from devices where status = '2' INTO OUTFILE '/tmp/PLC_active.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';
ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

It means that my MySQL server has been started with --secure-file-priv option which basically limits from which directories you can load files using LOAD DATA INFILE

so I have two options
1. Move the file to specified directory
2. Disable --secure-file-priv

Now, I choose option 1.

mysql> SHOW VARIABLES LIKE "secure_file_priv";
+------------------+-----------------------+
| Variable_name    | Value                 |
+------------------+-----------------------+
| secure_file_priv | /var/lib/mysql-files/ |
+------------------+-----------------------+
1 row in set (0.00 sec)
mysql> select * from devices where status = '2' INTO OUTFILE '/var/lib/mysql-files/PLC_active.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';
Query OK, 769 rows affected (0.00 sec)

mysql> select * from devices where status != '2' INTO OUTFILE '/var/lib/mysql-files/PLC_inactive.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';
Query OK, 113 rows affected (0.01 sec)

These files can export without any issue.

Tiến Phan - R0039

Knowledge is Endless
Sharing for Success 

[HOW TO] install Visual Studio Code in Arch Linux

I am moving Linux working environment from Ubuntu to Antergos. And I need to install Visual Studio Code for working with Git. 

Also saw something on this progress that is needed for newbie. So I write down this article. Hope it can be help you faster. 

This article follows step-by-step theory, so it is easy to do. 

Step 1:
You must download git repository 
[root@cliff Downloads]# git clone https://AUR.archlinux.org/visual-studio-code-bin.git

Step 2:
Then go inside 
[root@cliff Downloads]# cd visual-studio-code-bin/
[root@cliff visual-studio-code-bin]# ls
PKGBUILD  visual-studio-code.desktop  visual-studio-code-url-handler.desktop

Step 3:
And make a pacman package
[cliff@cliff visual-studio-code-bin]$ makepkg -s
==> Making package: visual-studio-code-bin 1.33.1-1 (Mon 29 Apr 2019 03:59:40 PM +07)
==> Checking runtime dependencies...
==> Installing missing dependencies...
...
==> Finished making: visual-studio-code-bin 1.33.1-1 (Mon 29 Apr 2019 04:00:34 PM +07)

makepkg should download *.tar.gz from Visual Studio Code and convert it to pacman package 
==> Finished making: visual-studio-code-bin 1.33.1-1 (Mon 29 Apr 2019 04:00:34 PM +07)

Step 4:
Then install 
[cliff@cliff visual-studio-code-bin]$ sudo pacman -U visual-studio-code-bin-1.33.1-1-x86_64.pkg.tar 

Step 5:
Finally, you can start it for now. I am using i3, so can take it via Ctrl + D and type "visual studio code" and press. 

Tiến Phan - R0039

Knowledge is Endless
Sharing for Success 

[HOW TO] fix ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

Hey guys,

I am working with MySQL, then want to export the data to csv file. 
mysql> select name,address from devices into outfile '/tmp/devices.csv' fields terminated by ',' enclosed by '"' lines terminated by '\n';ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

Oops! unlucky, it returns the error. Before me, someone started MySQL with --secure-file-priv
mysql> SHOW VARIABLES LIKE "secure_file_priv"; 
+------------------+-----------------------+| 
Variable_name    | Value                  
|+------------------+-----------------------+| 
secure_file_priv | /var/lib/mysql-files/ | 
+------------------+-----------------------+ 
1 row in set (0.00 sec)

it looks like that all of files store at /var/lib/mysql-files/ as declared. Then I try to export again.
mysql> select name,address from devices INTO OUTFILE '/var/lib/mysql-files/orders.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';Query OK, 891 rows affected (0.01 sec)

it works!!!


Tiến Phan - R0039

Knowledge is Endless
Sharing for Success 


[HOW TO] set application log to rsyslog on Ubuntu server

Depending on your application, also your purpose, you want to direct the log to fixed log path. So, if you are using rsyslog as a syslog service on Ubuntu, please follow this article.

I am using trigger to do this.

Go to log path
root@sta-tn:/etc/rsyslog.d#

then write a sub-rsyslog configuration.
root@sta-tn:/etc/rsyslog.d# vim 10-sta.conf 
if $programname == 'STA'  then {  
/var/log/sta.log    
stop 
}

You can declare more directive here. Then restart rsyslog service
root@sta-tn:/etc/rsyslog.d# systemctl restart rsyslog

Another way, you can use imfile module to do this.

Tiến Phan - R0039

Knowledge is Endless
Sharing for Success 

[HOW TO] The following signatures couldn't be verified because the public key is not available: NO_PUBKEY

sky@zabbix4-srv-01:/opt/packages$ sudo apt-get updateGet:1 http://repo.zabbix.com/zabbix/4.0/ubuntu xenial InRelease [7096 B]Hit:2 http://security.ubuntu.com/ubuntu xenial-security InReleaseGet:3 http://ppa.launchpad.net/ondrej/php/ubuntu xenial InRelease [23.9 kB]Hit:4 http://us.archive.ubuntu.com/ubuntu xenial InReleaseGet:5 http://repo.zabbix.com/zabbix/4.0/ubuntu xenial/main Sources [1196 B]Ign:3 http://ppa.launchpad.net/ondrej/php/ubuntu xenial InReleaseHit:6 http://us.archive.ubuntu.com/ubuntu xenial-updates InReleaseGet:7 http://repo.zabbix.com/zabbix/4.0/ubuntu xenial/main amd64 Packages [2697 B]Get:8 http://repo.zabbix.com/zabbix/4.0/ubuntu xenial/main i386 Packages [2685 B]Hit:9 http://us.archive.ubuntu.com/ubuntu xenial-backports InReleaseFetched 37.5 kB in 1s (33.2 kB/s)Reading package lists... DoneW: GPG error: http://ppa.launchpad.net/ondrej/php/ubuntu xenial InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 4F4EA0AAE5267A6CW: The repository 'http://ppa.launchpad.net/ondrej/php/ubuntu xenial InRelease' is not signed.N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.N: See apt-secure(8) manpage for repository creation and user configuration details.

sky@zabbix4-srv-01:/opt/packages$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4F4EA0AAE5267A6CExecuting: /tmp/tmp.8btYCLAEE0/gpg.1.sh --keyserverkeyserver.ubuntu.com--recv-keys4F4EA0AAE5267A6Cgpg: requesting key E5267A6C from hkp server keyserver.ubuntu.comgpg: key E5267A6C: public key "Launchpad PPA for Ond\xc5\x99ej Sur�" importedgpg: Total number processed: 1gpg:               imported: 1  (RSA: 1)


sky@zabbix4-srv-01:/opt/packages$skylab@zabbix4-srv-01:/opt/packages$ sudo apt-get updateHit:1 http://repo.zabbix.com/zabbix/4.0/ubuntu xenial InReleaseHit:2 http://security.ubuntu.com/ubuntu xenial-security InReleaseGet:3 http://ppa.launchpad.net/ondrej/php/ubuntu xenial InRelease [23.9 kB]Hit:4 http://us.archive.ubuntu.com/ubuntu xenial InReleaseHit:5 http://us.archive.ubuntu.com/ubuntu xenial-updates InReleaseHit:6 http://us.archive.ubuntu.com/ubuntu xenial-backports InReleaseFetched 23.9 kB in 1s (22.1 kB/s)Reading package lists... Done

Tiến Phan - R0039

Knowledge is Endless
Sharing for Success 

[HOW TO] using loopback files

Morning, 

Sometimes, you want to have a specified mount point for backing up. But, you could not find any free mount point. 

Also I explain why do we need to have a specified mount point.
1. To mark as a backup mount point other purpose, then nobody have a mistake with this. 
2. Clearly mount point for managing 

So, why did I us "loopback file? 
Using "loopback file", I do it. Loopback filesystems are very interesting components of Linux-like systems. Daily, we create filesystems on device (disk drive partitions). These storage devices are available as device files such as /dev/device_name. Then we mount it at a directory called a mount point. On the other hand, loopback filesystems are those that we create in files rather than a physical device. We can then mount those files as filesystems at a mount point. It is logical disk inside a file on your physical disk.

How I do it? 
Create raw file with "dd" command
$ dd if=/dev/zero of=loopbackfile.img bs=1GB count=1

then I have a 1GB file loopbackfile.img. Then I format this file to ext4 using mkfs command as follows:
$ mkfs.ext4 loopbackfile.img

and create a new directory 
$mkdir /mnt/loopback

mount the loopback file to /mnt/loopback as follows
$ mount -o loop loopbackfile.img /mnt/loopback

option "-o loop" is used to mount loopback filesystems. Also it attaches to a device called /dev/loop1 or loop2.

then I use "df -h" command
/dev/loop0      976M  2,6M  907M   1% /mnt/loopback

finally, I should add "mount -o loop loopbackfile.img /mnt/loopback" to /etc/fstab. Why? because it will follow the system startup and already have the mount point. I could not remember to add it every system boot. Of course, I need to use it as a static partition on this case. If you don't need it, you can ignore this. 

Good luck! 

Tiến Phan - R0039

Knowledge is Endless

Sharing for Success

[HOW TO] Puppet Validation of Exec[generating file] failed: '....' is not qualified and no path was specified. Please qualify the command or specify a path

I just run executable resource in Puppet and could not run successful. Here is content of Puppet file.
root@puppet:/etc/puppet/manifests# cat exec.pp
exec { 'generating file':
cwd => '/tmp/',
command => 'for i in {1.2}.txt; do touch $name; done',
creates => '/tmp/1.txt',
}
root@puppet:/etc/puppet/manifests# puppet apply --noop exec.pp
Notice: Compiled catalog for puppet in environment production in 0.10 seconds
Error: Validation of Exec[generating file] failed: 'for name in {1.2}.txt; do touch $name; done' is not qualified and no path was specified. Please qualify the command or specify a path. at /etc/puppet/manifests/exec.pp:5

Following the notification, I should declare the qualified path of command, then I put a default path as /bin
root@puppet:/etc/puppet/manifests# vim exec.pp
exec { 'generating file':
cwd => '/tmp/',
path => '/bin',
command => 'for name in {1.2}.txt; do touch $name; done',
creates => '/tmp/1.txt',
}
root@puppet:/etc/puppet/manifests# puppet apply --noop exec.pp
Notice: Compiled catalog for puppet in environment production in 0.10 seconds
Notice: /Stage[main]/Main/Exec[generating file]/returns: current_value notrun, should be 0 (noop)
Notice: Class[Main]: Would have triggered 'refresh' from 1 events
Notice: Stage[main]: Would have triggered 'refresh' from 1 events
Notice: Finished catalog run in 0.04 seconds

It works!!!

So you can do like me to fix it.

Tiến Phan - R0039

Knowledge is Endless

Sharing for Success

[HOW TO] create a shadow hash of password

Sometimes, you may need to create a critical script to change the password of root or another user. Of course, you don't use the clear text of password. It is very risk and can leak. Then, what should we do on this case?

I want to bring you focus /ect/shadow. For sure, it is salted hash file where stores all of user's password. And it already hashed. 

It looks like this


catrulez:$6$3lOhJgJD$lUKZ0Q9LHT6YO3u1pS/0hM9yJOYTkqOh/XaR2O5xYwaPKI6TWIOEjYQSsa2XWJI7Ty.i2XQmHVdqNZDnGYiUT.:17482:0:99999:7:::

and 
$6$3lOhJgJD$lUKZ0Q9LHT6YO3u1pS/0hM9yJOYTkqOh/XaR2O5xYwaPKI6TWIOEjYQSsa2XWJI7Ty.i2XQmHVdqNZDnGYiUT

is the shadow hash corresponding to its password. 

So, in my imagination, I will create a shadow hash of password what I want to set for individual user and put it to critical script. Then it should be fine. 

Two steps:
1. Create a shadow hash 
root@catrulez:~# openssl passwd -1 -salt dsadsadd Zxcvbnm1$1$dsadsadd$y4h9pSp/9rS2kVv7x4xRB.

2. Create a user with shadow hash of password. 
root@catrulez:~# useradd -p '$1$dsadsadd$y4h9pSp/9rS2kVv7x4xRB.'  user_name

Also you can take them to script. Please clear bash history. 

Tiến Phan - R0039

Knowledge is Endless

Sharing for Success

[HOW TO] black list Postfix

Once upon a time I met a problem with Postfix. The customer sent to me the ticket, in this she told me that she received many email spams from @e-m-a-i-l.com

Politely I said to her that I will find the solution for this case. So, she can save time. I drank a cup of water before discovering.

In the first, I have to check the log to find the exactly email who is spammer?
So easy, because the customer sent me the email of spammer. Next, I went to postfix log to find out.
One moment in time, I found that.

So, I need to add the spammer to postfix's black-list file.
Firstly, I created the black-list file:
#vim /etc/postfix/sender_access

#DISCARD: the sender don't receive the response 
#REJECT: the sender receives the response.

And then, I created the postfix's database
postmap hash:/etc/postfix/sender_access

I added the paragraph below to /etc/postfix/main.conf 
smtpd_recipient_restrictions = check_sender_access hash:/etc/postfix/sender_access 

Restart to apply the change
service postfix restart

After that, I opened the Postfix's log and keep my eyes. I didn't see any email from w.morrison@gmail.com.

Tiến Phan - R0039

Knowledge is Endless

Sharing for Success

[HOW TO] get the server ID in MySQL

Sometimes, you have to know the Server ID of MySQL, and you don't know how to get it?

Here I show you.

What is Server ID? 
Server always use in MySQL Replication. It defines in numeric to classify the server.

As always, server ID 1 is master server. Then server ID n+1 is slave server.

How to find it?
You use below MySQL command
# Get MySQL server_id
mysql> SHOW VARIABLES LIKE 'server_id';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id     | 1     |
+---------------+-------+
1 row in set (0.01 sec)

# Change MySQL server_id
mysql>  SET GLOBAL server_id=21


Tiến Phan - R0039

Knowledge is Endless

Sharing for Success

[How To] show multi core of CPUs in Linux "top" command

I believe you did think about how to show multi core of CPUs in "top" command. Don't amaze :D 

In fact, "top" only shows CPU usage as a percentage of a single CPU by default. Luckily, you can change this by pressing "1" to show break the CPU usage per CPU. 

Easy to understand, easy to do. 


top - 03:35:08 up 48 days, 22:30,  2 users,  load average: 104.92, 91.69, 78.27Tasks: 379 total,  55 running, 324 sleeping,   0 stopped,   0 zombie%Cpu0  : 86.5 us, 11.9 sy,  0.0 ni,  0.0 id,  0.0 wa,  0.0 hi,  1.6 si,  0.0 st%Cpu1  : 88.3 us, 10.0 sy,  0.0 ni,  0.0 id,  0.0 wa,  0.0 hi,  1.6 si,  0.0 st%Cpu2  : 87.4 us, 10.6 sy,  0.0 ni,  0.0 id,  0.0 wa,  0.0 hi,  1.9 si,  0.0 st%Cpu3  : 87.4 us, 11.3 sy,  0.0 ni,  0.0 id,  0.0 wa,  0.0 hi,  1.3 si,  0.0 st%Cpu4  : 85.8 us, 12.3 sy,  0.0 ni,  0.0 id,  0.0 wa,  0.0 hi,  1.9 si,  0.0 st%Cpu5  : 84.6 us, 13.5 sy,  0.0 ni,  0.0 id,  0.0 wa,  0.0 hi,  1.9 si,  0.0 stGiB Mem :     15.5 total,      1.9 free,      6.0 used,      7.7 buff/cacheGiB Swap:      2.0 total,      0.8 free,      1.2 used.      8.3 avail Mem 
  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND                              13433 mysql-1   20   0 7456476   2.4g   5784 S 25.3 15.2  32470:03 mysqld                               10884 root      20   0  424344 395060 220364 S  0.0  2.4   0:09.09 scanner                               1305 nails     20   0  427456 179340   2392 S  0.5  1.1   0:25.02 scanner                               1580 nails     20   0  427416 179340   2392 S  0.5  1.1   0:23.75 scanner                               3298 nails     20   0  426912 178576   2384 S  0.6  1.1   0:11.38 scanner                               2563 nails     20   0  426912 178564   2388 S  0.6  1.1   0:15.79 scanner                               4645 nails     20   0  425888 177600   2324 S  0.6  1.1   0:03.54 scanner                               4647 nails     20   0  425888 177596   2328 S  0.5  1.1   0:03.55 scanner                 
Tiến Phan - R0039

Knowledge is Endless
 
Sharing for Success 

[HOW TO] find LUN of SAN's logical unit numbers

How to find?

1. Show the disk space
[root@~:~]# df -hFilesystem            Size  Used Avail Use% Mounted on/dev/mapper/vg--hypprd01--data-lv--hypprd01--data                      335G  326G  8.6G  98% /home/databases/oracle/HYPPRD01/datafiles

2. Show volume group
[root@~:~]# vgs  VG                  #PV #LV #SN Attr   VSize   VFree    vg-hypprd01-data      2   1   0 wz--n- 339.99g      0 

3. Show physical disk 
[root@~:~]# pvs
  PV                  VG                  Fmt  Attr PSize   PFree
  /dev/mapper/mpathao vg-hypprd01-data    lvm2 a--u 180.00g      0
  ...
  /dev/mapper/mpathat vg-hypprd01-data    lvm2 a--u 160.00g      0 


4. Get LUN
In step 3, I already got the physical disk, so next, simple to get LUNs
[root@~:~]# multipath -l /dev/mapper/mpathao mpathao (36000144000000010706b857c63df5303) dm-9 EMC,Invistasize=180G features='1 queue_if_no_path' hwhandler='0' wp=rw`-+- policy='round-robin 0' prio=0 status=active  |- 1:0:0:10 sdl  8:176  active undef unknown  |- 0:0:0:10 sdau 66:224 active undef unknown  |- 1:0:1:10 sdad 65:208 active undef unknown  |- 0:0:1:10 sdcf 69:48  active undef unknown  |- 1:0:2:10 sdbh 67:176 active undef unknown  |- 0:0:2:10 sddd 70:176 active undef unknown  |- 1:0:3:10 sdci 69:96  active undef unknown  `- 0:0:3:10 sddt 71:176 active undef unknown

[root@~:~]# multipath -l /dev/mapper/mpathatmpathat (36000144000000010706b857c63df79e8) dm-10 EMC,Invistasize=160G features='1 queue_if_no_path' hwhandler='0' wp=rw`-+- policy='round-robin 0' prio=0 status=active  |- 1:0:0:15 sdq  65:0   active undef unknown  |- 0:0:0:15 sdbg 67:160 active undef unknown  |- 1:0:1:15 sdan 66:112 active undef unknown  |- 0:0:1:15 sdcs 70:0   active undef unknown  |- 1:0:2:15 sdbq 68:64  active undef unknown  |- 0:0:2:15 sddi 71:0   active undef unknown  |- 1:0:3:15 sdcp 69:208 active undef unknown  `- 0:0:3:15 sddy 128:0  active undef unknown

Now I send them to Storage Admin and wait his feedback on time.

To that end, I have what I need. I would like to provide more information about LUN for you.  

Said Amol Sale.
LUN is a logical disk as created on SAN storage array and is assigned to host in SAN using LUN binding, It appears on the host as local disk.
Storage array usually have large storage capacity, we don't want one  server to use the whole thing, so we divide it into logical units (LUN) is actually Logical Unit Number, so we get storage sliced into usable chunks, and present  it to the server. In a simple example, suppose it shows up as local disk on server just like /dev/sdc.

Volume We carve out volume using one or more LUNs (storage disks from OS's view) We want to be able to add more space or shrink the space. volume makes it possible. We can resize that LUN on the  storage array (or even create another LUN and present that to the  server) and using LVM (Logical Volume Manager), We can grow the volume without rebooting.There are several good features like cloning, mirroring, high availability etc.of volumes.

Said J Michel Metz
It might help to think of the differences in terms of the perspective. That is, if you look at if from the computer's "perspective," versus the storage's "perspective," it can actually make sense.

On one end of a logical computing metaphor, you have the computer (also called a "host," "initiator," or even just "CPU" sometimes. At the other, you have the physical media (also called a "target," "drive," "HDD," or "SSD," etc.).

Hosts need Volumes, so those volumes have to be made up of something that eventually sits on a real, physical drive (whether it be spinning drives or SSDs, etc.).

Look at the simplified diagram below. From the From the "top down," then, a Host sees a Volume. That Volume, in turn, has to be made up of something that, in turn, can be interpreted (eventually by physical media). From the storage's perspective, the physical media is broken down from a physical entity (the actual drive), into a logical entity, and given a number (hence the "Logical Unit Number", or LUN).
In between there is a very important piece of software that makes a translation between that LUN and what the host can see as a Volume, called the Volume Manager.

Why go through all this work?

When storage requirements grow, so does the need to add in methods for protection, scale, performance, and other nifty features. On top of that, there needs to be room for networking capabilities as well. Those capabilities have to go somewhere, and having one big monolithic system doesn’t work quite so well.

Many modern systems that are in use today have a relationship between Volumes and LUNs that look like this:

Looking from the bottom-up, the media is located inside of some sort of storage enclosure, and is often pooled together into a logical format via a system called RAID (RAID, depending on the methods used, can improve performance and resiliency).

That pool, in turn, is carved up into LUNs - the exact same kind of LUN we used in our simple example above. Those LUNs are then provisioned to hosts. Many times there is a 1:1 relationship between LUNs and Volumes, but it does not have to be that way. Volume Managers are capable of taking more than one LUN and logically combining them into a single entity to present up to the host as an individual volume.

So, LUNs and Volumes can be the same thing, and they are related, but (especially in SANs), the usually are not.

Tiến Phan - R0039

Knowledge is Endless

Sharing for Success

[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