[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