วันจันทร์ที่ 11 กันยายน พ.ศ. 2566

Mount drive in linux and set auto-mount at boot

 https://confluence.jaytaala.com/display/TKB/Mount+drive+in+linux+and+set+auto-mount+at+boot


Guide to mount a drive in linux (deb/ubuntu) and set to auto-mount at boot.

Mount drive

Make a folder (will be mount point)

sudo mkdir /media/data
sudo mount /dev/sdb1 /media/data

Now you can access the drive at /media/data.

Auto-mount at boot

We want the drive to auto-mount at boot.  This usually means editing /etc/fstab.

Firstly, it's always best to use the drives UUID.  To find the drive's UUID do

ls -al /dev/disk/by-uuid/

Copy the resultant UUID (for your disk) and then open fstab for editing (note I'm using vim here but use whatever editor you prefer):

sudo vim /etc/fstab

You want to add an entry for the UUID and mount point.  Below is an example of an fstab file with an entry added for the mount above:

# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sdb1 during installation
UUID=63a46dce-b895-4c1f-9034-b1104694a956 /               ext4    errors=remount-ro 0       1
# swap was on /dev/sdb5 during installation
UUID=b9b9ee49-c69c-475b-894b-1279d44034ae none            swap    sw              0       0
# data drive
UUID=19fa40a3-fd17-412f-9063-a29ca0e75f93 /media/data   ext4    defaults        0       0

Note: the entry added is the last line.

Test fstab

We always want to test the fstab before rebooting (an incorrect fstab can render a disk unbootable).  To test do:

findmnt --verify

check the last line for errors.  Warnings can help in improving your fstab.

Unmounting drive with umount

You can unmount drives using umount.  For example, to unmount the data drive above mount at /media/data you would do:

sudo umount /media/data

วันพฤหัสบดีที่ 10 สิงหาคม พ.ศ. 2566

วันอาทิตย์ที่ 6 สิงหาคม พ.ศ. 2566

Checking the Health of a Storage Device in Linux

 https://www.baeldung.com/linux/storage-device-check-health

dnf install  e2fsprogs


 badblocks -sv /dev/sdd1


Checking blocks 0 to 15247359
Checking for bad blocks (read-only test):   0.00% done, 0:00 elapsed. (0/0/0 err  0.53% done, 0:04 ela    0.81% done, 0:  1.08% done, 0:08 elapse  1.22% done, 0:09 done                                                 
Pass completed, 0 bad blocks found. (0/0/0 errors)


mount: unknown filesystem type ‘LVM2_member’.

 https://serverok.in/mount-unknown-filesystem-type-lvm2_member


https://www.autodesk.com/support/technical/article/caas/sfdcarticles/sfdcarticles/Mount-mount-dev-mapper-vg00-lvol1-on-mnt-StorageMedia-failed-Structure-needs-cleaning-error-when-trying-to-mount-storage-in-Flame.html


https://www.linuxsysadmins.com/resize-root-lvm-partition-in-linux/


https://www.linuxsysadmins.com/resize-root-lvm-partition-in-linux/


https://linuxhint.com/xfs-repair/#post-276244-_sx44t3s3ishr


************************* Linux Emergency Mode Error RHEL/CentOS

https://www.youtube.com/watch?v=mnZ3YUnKzDU

https://systemzone.net/lvm-management-in-centos-red-hat-7-linux/



 




Activating Volume Group


# vgchange -ay


Check for file System error


# e2fsck -ff /dev/mapper/rhel-root


xfs_repair -L  /dev/mapper/centos-root

วันอังคารที่ 22 กันยายน พ.ศ. 2563

ตั้งเวลาเครื่อง CentOS8

 systemctl status chronyd

Installing Chrony on RHEL 8 / CentOS 8

Set timezone.

sudo timedatectl set-timezone Asia/Bangkok

Chrony can be installed on RHEL 8 / CentOS 8 from package manager.

sudo yum -y install chrony

After the installation, start and enable chronyd service.

sudo systemctl enable --now chronyd

The service status should show running

$ systemctl status chronyd
● chronyd.service - NTP client/server
Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2018-12-31 08:11:50 EAT; 5min ago
Docs: man:chronyd(8)
man:chrony.conf(5)
Main PID: 743 (chronyd)
Tasks: 1 (limit: 5061)
Memory: 1.7M
CGroup: /system.slice/chronyd.service
└─743 /usr/sbin/chronyd

Configuring Chrony on RHEL 8 / CentOS 8

After the installation, you can make the changes on Chrony main configuration file /etc/chrony.conf

One main configuration change you can make is to set the time servers closest to you. Since I’m in Nairobi, I’ll set Africa NTP pool of servers.

วันพฤหัสบดีที่ 9 สิงหาคม พ.ศ. 2561

วันจันทร์ที่ 28 พฤษภาคม พ.ศ. 2561

วันอาทิตย์ที่ 20 พฤษภาคม พ.ศ. 2561

Remote desktop Protocol server ( xrdp RDP) to Linux server from Windows

xrdp is an Open Source Remote desktop Protocol server, which allows you to RDP to your Linux server from Windows 


https://www.itzgeek.com/how-tos/linux/centos-how-tos/install-xrdp-on-centos-7-rhel-7.html

วันอังคารที่ 22 ธันวาคม พ.ศ. 2558

วันจันทร์ที่ 13 เมษายน พ.ศ. 2558

Monitor SMART status of HDD’s in CentOS

http://www.betweendots.com/topic/56-monitor-smart-status-of-hdd%E2%80%99s-in-centos/



yum install smartmontools
Find out what drive you have to monitor. One way you can do this is by checking what partitions are on what drive:
 
cat /proc/partitions
You’ll get a result like this:
 
major minor  #blocks  name

   8       16 1953514584 sdb
   8       17   16777216 sdb1
   8       18     524288 sdb2
   8       19 1936208984 sdb3
   8        0 1953514584 sda
   8        1   16777216 sda1
   8        2     524288 sda2
   8        3 1936208984 sda3
   9        2 1936208832 md2
   9        1     524224 md1
   9        0   16777088 md0
You can see we have sda and sdb devices, the "md" devices are software raid partitions. 

You can usually identify which hard disks are on your system also by looking in /proc/ide and in /proc/scsi.

If you want to do a quick test to see what the health of a device is you can do this by entering the following command:
smartctl -H /dev/sdb
smartctl 5.43 2012-06-30 r3573 [x86_64-linux-2.6.32-431.11.2.el6.x86_64] (local build)
Copyright (C) 2002-12 by Bruce Allen, http://smartmontools.sourceforge.net


=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED
If you want to be notified as soon as a devices fails SMART testing automatically, then you can run the smartd daemon:
service smartd start
chkconfig smartd on 

วันจันทร์ที่ 12 มกราคม พ.ศ. 2558

เริ่มต้นใช้งาน PHP + MongoDB

เริ่มต้นใช้งาน PHP + MongoDB


ติดตั้งบน CentOS
วิธีที่ง่ายคือ ติดตั้งผ่าน PECL
--------------------------------------------------------------------------------------
pecl install mongo--------------------------------------------------------------------------------------

เมื่อติดตั้ง mongo เรียบร้อยแล้ว จะมีข้อความแจ้งว่า ติดตั้งเรียบร้อยแล้ว และจะมีข้อความแจ้งว่า mongo.so วางไว้ที่ไหน เช่น /usr/lib64/php/modules/mongo.so
* ถ้ายังไม่ติดตั้ง PECL ให้ติดตั้งผ่านคำสั่งนี้ก่อน
--------------------------------------------------------------------------------------
yum install gcc php-devel--------------------------------------------------------------------------------------

เปิดไฟล์ /etc/php.ini ขึ้นมา แล้วเพิ่มบรรทัดนี้เข้าไป
--------------------------------------------------------------------------------------
extension=/usr/lib64/php/modules/mongo.so--------------------------------------------------------------------------------------

จากนั้น restart apache หนึ่งครั้ง--------------------------------------------------------------------------------------service httpd restart--------------------------------------------------------------------------------------

เช็คว่า PHP รองรับ Mongo เรียบร้อยแล้ว โดยสร้างไฟล์ขึ้นมาและใส่คำสั่งนี้เข้าไป 
(ไฟล์ชื่อ info.php)
--------------------------------------------------------------------------------------
<?php phpinfo() ?>
--------------------------------------------------------------------------------------


จากนั้นดูผ่านหน้าเว็บไซด์ เช่น
--------------------------------------------------------------------------------------http://localhost/info.php--------------------------------------------------------------------------------------

ติดตั้งผ่าน Window
ดาวน์โหลดไฟล์จากลิงค์นี้ https://s3.amazonaws.com/drivers.mongodb.org/php/index.html
เลือกดาวน์โหลดเวอร์ชั่นล่าสุด เช่น php_mongo-1.4.1.zip แล้วทำการแตกไฟล์ออกมา เลือกเอาเฉพาะไฟล์ mongo.dll ที่เราต้องการเช่น php_mongo-1.4.1-5.3-vc9-x86_64.dll แล้วนำไปวางไว้ที่โฟลเดอร์ ext ของ php เรา เช่น D:\server\xampp\php\ext\php_mongo-1.4.1-5.3-vc9-x86_64.dll 

จากนั้นเปิดไฟล์ php.ini ขึ้นมา แล้วเพิ่มคำสั่งบรรทัดนี้
--------------------------------------------------------------------------------------extension=php_mongo-1.4.1-5.3-vc9-x86_64.dll--------------------------------------------------------------------------------------
จากนั้น restart apache หนึ่งครั้ง
เช็คว่า PHP รองรับ Mongo เรียบร้อยแล้ว โดยสร้างไฟล์ขึ้นมาและใส่คำสั่งนี้เข้าไป 
(ไฟล์ชื่อ info.php)
--------------------------------------------------------------------------------------
<?php phpinfo() ?>
--------------------------------------------------------------------------------------


จากนั้นดูผ่านหน้าเว็บไซด์ เช่น
--------------------------------------------------------------------------------------http://localhost/info.php--------------------------------------------------------------------------------------

เท่านี้เราก็ใช้งาน PHP+MongoDB ได้แล้ว

แต่ถ้าใครไม่อยากติดตั้งอะไรให้วุ่นวาย หรือใช้ Hosting ปกติอยู่แล้ว ลองสอบถามว่า Hosting ได้ทำการติดตั้ง PHP Driver สำหรับ MongoDB ไว้หรือเปล่า หรือเราจะ ใช้คำสั่ง phpinfo() ดูเองก็ได้

Hosting ที่รองรับ PHP Driver for MongoDB เช่น www.pathosting.co.th เป็นต้น 

ส่วนคำสั่ง PHP สำหรับติดต่อ MongoDB Server สามารถหาดูได้จากลิงค์นี้
http://www.php.net/manual/en/book.mongo.php
http://www.thaimongo.com/%E0%B8%9A%E0%B8%97%E0%B8%84%E0%B8%A7%E0%B8%B2%E0%B8%A1-mongodb/35-%E0%B9%80%E0%B8%A3%E0%B8%B4%E0%B9%88%E0%B8%A1%E0%B8%95%E0%B9%89%E0%B8%99%E0%B9%83%E0%B8%8A%E0%B9%89%E0%B8%87%E0%B8%B2%E0%B8%99-php-mongodb.html