[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