Xsession: unable to start x session

Xsession: unable to start x session — “no /home/teee/.xsession” file no session manager , no windows manager ,and no terminal emulator found, abourting

ข้อความผิดพลาดนี้บอกว่า X ไม่สามารถเริ่มเซสชันได้เพราะ:

  • ไม่มีไฟล์ ~/.xsession

  • ไม่มี session manager

  • ไม่มี window manager

  • ไม่มี terminal emulator

สาเหตุที่เป็นไปได้:

  1. XFCE ยังไม่ได้ติดตั้งครบ

  2. ไม่มี display manager หรือถูกตั้งค่าผิด

  3. X11 พยายามเริ่มต้นจาก .xsession แต่ไม่มีการกำหนดค่า

วิธีแก้ไข

วิธีที่ 1: ตรวจสอบและติดตั้ง XFCE พร้อม X11 อย่างถูกต้อง

sudo apt update
sudo apt install xfce4 xfce4-goodies xorg lightdm

ระหว่างการติดตั้ง ถ้ามีคำถามเรื่อง Display Manager ให้เลือก lightdm

วิธีที่ 2: ตรวจสอบว่ามี session ของ XFCE ใน /usr/share/xsessions

ls /usr/share/xsessions

ควรเห็นไฟล์ชื่อประมาณ:

  • xfce.desktop

วิธีที่ 3:ตรวจสอบว่าติดตั้ง terminal emulator ด้วย

เช่น xfce4-terminal หรือ xterm:

sudo apt install xfce4-terminal xterm

เสร็จแล้วลอง Reboot ดู

Debian แก้ไขคำสั่งบูต GRUB ชั่วคราวเพื่อเข้าผ่าน shell

เลือกบรรทัดแรก (Debian GNU/Linux) แล้วกด e เพื่อ “edit”

หาบรรทัดที่ขึ้นต้นว่า:

linux /boot/vmlinuz-… root=UUID=… ro quiet

ลบ quiet ออก และ เพิ่ม:

linux /boot/vmlinuz-… root=UUID=… ro systemd.unit=multi-user.target

กด Ctrl + X หรือ F10 เพื่อบูตด้วยค่าที่คุณแก้ไข

Debian เปิดเครื่องเจอแต่ loopback interface

อาจเป็นไปได้ว่า interface จะ down อยู่ ให้ใช้คำสั่งครวจสอบ

#ip link show
#ip link set enp0s3 up
#dhclient enp0s3

Ubuntu แก้ไข motd

ปิดระบบ dynamic MOTD (ให้แสดงแค่ /etc/motd)

sudo chmod -x /etc/update-motd.d/*

sudo nano /etc/motd

วิธีการใช้งาน scrcpy เพื่อ mirror หน้าจอ samsung s24 บนเครื่อง mac

#ที่มือถือให้ทำการเปิด Developer Mode

1. ไปที่ settings > About phone > Software information >

กดย้ำๆที่ Build number 7 ครั้ง มือถือจะแจ้งว่า Developer mode On

2. เลือก Settings > Security and privacy. กด ปิด Auto Blocker

3. ที่เครื่องมือถือจะมีป๊อปอัพเตือนว่ามีการเสียบสาย USB เข้ากับเครื่อง MAC. ให้เลือกใช้งานตามจุดประสงค์

4. ให้ทำการติดตั้งโปรแกรม scrcpy โดยจะติดตั้งผ่าน homebrew.

ถ้ายังไม่เคยติดตั้งใช้งาน homebrew ให้ไปติดตั้ง homebrew ก่อน

ติดตั้ง Homebrew บน Mac (ถ้ายังไม่มี)

# /bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)”

5. จากนั้นติดตั้ง ADB และ scrcpy ผ่าน Homebrew

brew install android-platform-tools # สำหรับ ADB
brew install scrcpy # ติดตั้ง scrcpy

6.เชื่อมต่อ S24 เข้ากับ Mac ผ่าน USB-C Cable

•ใช้สายแท้ หรือสายที่รองรับ Data Transfer

•หลังเสียบ → บนมือถือจะขึ้น “Allow USB Debugging?”กด Allow

7.ตรวจสอบว่า Mac เจอ S24 หรือไม่

พิมพ์ใน Terminal:

adb devices

ถ้าเจออุปกรณ์มือถือจะแจ้งว่า

List of devices attached

xxxxxxxxxxxx device

8. รัน scrcpy

teee@NP Programs % scrcpy
scrcpy 3.1 <https://github.com/Genymobile/scrcpy>
INFO: ADB device found:
INFO: –> (usb) RFCxxxxxxxx device SM_S921B
/opt/homebrew/Cellar/scrcpy/3.1/share/scrcpy/scrcpy-server: 1 file pushed, 0 skipped. 106.3 MB/s (90640 bytes in 0.001s)
[server] INFO: Device: [samsung] samsung SM-XXXXX (Android 14)
INFO: Renderer: metal
INFO: Texture: 1080×2336
2025-03-17 15:31:22.355 scrcpy[37968:994087] +[IMKClient subclass]: chose IMKClient_Modern
2025-03-17 15:31:22.355 scrcpy[37968:994087] +[IMKInputSession subclass]: chose IMKInputSession_Modern

 

 

 

 

Install freeswitch 1.10.12 on debian12

root@san:~# apt-get update && sudo apt upgrade -y
root@san:~# apt-get install -y git build-essential autoconf automake libtool-bin g++ python3-dev uuid-dev zlib1g-dev libjpeg-dev libncurses5-dev libssl-dev libpcre3-dev libdb-dev libsndfile1-dev libedit-dev libldns-dev libcurl4-openssl-dev libpq-dev libspeex-dev libspeexdsp-dev libsqlite3-dev libopus-dev libsndfile1-dev libtiff-dev libavformat-dev libswscale-dev liblua5.2-dev liblua5.3-dev libmpg123-dev libpq-dev libvpx-dev libopusfile-dev libshout3-dev libfreeimage-dev libyuv-dev libx264-dev cmake pkg-config libbroadvoice16-dev libsilk-dev libflite1-dev libilbc-dev libgsm1-dev libopenh264-dev unzip wget libswresample-dev

E: Package ‘libavresample-dev’ has no installation candidate
แพ็กเกจ libavresample-dev ถูกลบออกจาก Debian 12 (Bookworm) เนื่องจาก FFmpeg ได้เลิกใช้ libavresample แล้ว

apt install libswresample-dev

Download Freeswitch
https://files.freeswitch.org/freeswitch-releases/
root@san:~# cd /usr/src
root@san:/usr/src# wget https://files.freeswitch.org/freeswitch-releases/freeswitch-1.10.12.-release.tar.gz
root@san:/usr/src# tar xvf freeswitch-1.10.12.-release.tar.gz
root@san:/usr/src# cd freeswitch-1.10.12.-release

root@san:/usr/src/freeswitch-1.10.12.-release# ./rebootstrap.sh
เปืด Modules ที่ต้องการที่จะใช้งาน
root@san:/usr/src/freeswitch-1.10.12.-release# nano modules.conf

say/mod_say_th
databases/mod_mariadb

root@san:/usr/src/freeswitch-1.10.12.-release# ./configure –prefix=/usr/local/freeswitch –enable-core-pgsql-support

root@san:/usr/src/freeswitch-1.10.12.-release# make -j$(nproc)

make[4]: Entering directory ‘/usr/src/freeswitch-1.10.12.-release/src/mod/applications/mod_spandsp’
CC mod_spandsp_la-mod_spandsp.lo
CC mod_spandsp_la-udptl.lo
CC mod_spandsp_la-mod_spandsp_fax.lo
CC mod_spandsp_la-mod_spandsp_dsp.lo
mod_spandsp_dsp.c: In function ‘get_v18_mode’:
mod_spandsp_dsp.c:159:17: error: ‘V18_MODE_5BIT_4545’ undeclared (first use in this function)
159 | int r = V18_MODE_5BIT_4545;
| ^~~~~~~~~~~~~~~~~~
mod_spandsp_dsp.c:159:17: note: each undeclared identifier is reported only once for each function it appears in
mod_spandsp_dsp.c:165:29: error: ‘V18_MODE_5BIT_50’ undeclared (first use in this function)
165 | r = V18_MODE_5BIT_50;
| ^~~~~~~~~~~~~~~~
mod_spandsp_dsp.c: In function ‘spandsp_tdd_send_session’:
mod_spandsp_dsp.c:216:21: error: too few arguments to function ‘v18_init’
216 | tdd_state = v18_init(NULL, TRUE, get_v18_mode(session), V18_AUTOMODING_GLOBAL, put_text_msg, NULL);
| ^~~~~~~~
In file included from /usr/local/include/spandsp.h:114,
from mod_spandsp.h:50,
from mod_spandsp_dsp.c:36:
/usr/local/include/spandsp/v18.h:138:29: note: declared here
138 | SPAN_DECLARE(v18_state_t *) v18_init(v18_state_t *s,
| ^~~~~~~~
mod_spandsp_dsp.c: In function ‘spandsp_tdd_encode_session’:
mod_spandsp_dsp.c:263:26: error: too few arguments to function ‘v18_init’
263 | pvt->tdd_state = v18_init(NULL, TRUE, get_v18_mode(session), V18_AUTOMODING_GLOBAL, put_text_msg, NULL);
| ^~~~~~~~
/usr/local/include/spandsp/v18.h:138:29: note: declared here
138 | SPAN_DECLARE(v18_state_t *) v18_init(v18_state_t *s,
| ^~~~~~~~
mod_spandsp_dsp.c: In function ‘spandsp_tdd_decode_session’:
mod_spandsp_dsp.c:341:26: error: too few arguments to function ‘v18_init’
341 | pvt->tdd_state = v18_init(NULL, FALSE, get_v18_mode(session), V18_AUTOMODING_GLOBAL, put_text_msg, pvt);
| ^~~~~~~~
/usr/local/include/spandsp/v18.h:138:29: note: declared here
138 | SPAN_DECLARE(v18_state_t *) v18_init(v18_state_t *s,

ที่เป็นแบบนี้เพราะ Module mod_spandsp มี BUG ที่แก้ไขแล้วแต่ไม่ได้แก้ไขที่ Code Release จะต้องทำการ patch ก่อน

https://github.com/zenthangplus/ansible-role-fsmrf/blob/9a73a47bfa19a485ddfc10f496bfc2041594f552/files/mod_spandsp_dsp.c.patch

root@san:/usr/src/freeswitch-1.10.12.-release# cd src/mod/applications/mod_spandsp/
root@san:/usr/src/freeswitch-1.10.12.-release/src/mod/applications/mod_spandsp# wget https://raw.githubusercontent.com/zenthangplus/ansible-role-fsmrf/9a73a47bfa19a485ddfc10f496bfc2041594f552/files/mod_spandsp_dsp.c.patch

root@san:/usr/src/freeswitch-1.10.12.-release/src/mod/applications/mod_spandsp# root@san:/usr/src/freeswitch-1.10.12.-release/src/mod/applications/mod_spandsp# patch -p0 < mod_spandsp_dsp.c.patch ลอง make ดู root@san:/usr/src/freeswitch-1.10.12.-release/src/mod/applications/mod_spandsp# make ถ้าไม่มี error ก็กลับไปลอง สั่ง make freeswitch ใหม่ root@san:/usr/src/freeswitch-1.10.12.-release/src/mod/applications/mod_spandsp# cd /usr/src/freeswitch-1.10.12.-release root@san:/usr/src/freeswitch-1.10.12.-release# make clean ปรับแต่ง Banner root@san:/usr/src/freeswitch-1.10.12.-release# cd libs/esl/ root@san:/usr/src/freeswitch-1.10.12.-release/libs/esl/ee fs_cli.c static const char *banner =”YOUR BANNER email@mydomain.com”; root@san:/usr/src/freeswitch-1.10.12.-release/libs/esl# cd /usr/src/freeswitch-1.10.12.-release/src/include/ root@san:/usr/src/freeswitch-1.10.12.-release/src/include# mv cc.h cc.bak root@san:/usr/src/freeswitch-1.10.12.-release/src/include# nano cc.h const char *cc = “”; const char *cc_s = “”; root@san:/usr/src/freeswitch-1.10.12.-release/src/include# cd ../../ root@san:/usr/src/freeswitch-1.10.12.-release# ./configure –prefix=/usr/local/freeswitch –enable-core-pgsql-support root@san:/usr/src/freeswitch-1.10.12.-release# make install tab >q. กด Y

root@san:/usr/src/freeswitch-1.10.12.-release# make cd-sounds-install && make cd-moh-install && make uhd-sounds-install && make uhd-moh-install && make hd-sounds-install && make hd-moh-install && make sounds-install && make moh-install

root@san:/usr/src/freeswitch# make samples

root@san:/usr/local/freeswitch/conf/autoload_configs# cp event_socket.conf.xml event_socket.conf.orig

root@san:/usr/local/freeswitch/conf/autoload_configs# nano event_socket.conf.xml

<configuration name=”event_socket.conf” description=”Socket Client”>
<settings>
<param name=”listen-ip” value=”0.0.0.0″/>
<param name=”listen-port” value=”8021″/>
<param name=”password” value=”(YourPass)”/>
<!–<param name=”apply-inbound-acl” value=”loopback.auto”/>–>
<!–<param name=”stop-on-bind-error” value=”true”/>–>
</settings>
</configuration>

root@san:/etc# nano /etc/fs_cli.conf

[default]

; Put me in /etc/fs_cli.conf or ~/.fs_cli_conf
key_f1 => help
key_f2 => status
key_f3 => show channels
key_f4 => show calls
key_f5 => sofia status
key_f6 => reloadxml
key_f7 => /log console
key_f8 => /log debug
key_f9 => sofia status profile internal
key_f10 => fsctl pause
key_f11 => fsctl resume
key_f12 => version

[default]
profile => (Your Profile Name)
host => 127.0.0.1
port => 8021
password => (YourPass)
debug => 2
loglevel => debug

root@san:/etc# cd /usr/local/freeswitch/bin
root@san:/usr/local/freeswitch/bin# ln -s /usr/local/freeswitch/bin/freeswitch /bin/freeswitch
root@san:/usr/local/freeswitch/bin# ln -s /usr/local/freeswitch/bin/fs_cli /bin/fs_cli

root@san:/usr/local/freeswitch/bin# cd /usr/local/freeswitch/conf/
root@san:/usr/local/freeswitch/conf# cp vars.xml vars.orig
root@san:/usr/local/freeswitch/conf# nano vars.xml

<X-PRE-PROCESS cmd=”set” data=”ChangeDefaultPasswordToYourPassword”/>

Goto
FreeSWICH will default to $${local_ip_v4} unless changed. Changing this setting does
affect the sip authentication. Please review conf/directory/default.xml for more
information on this topic.

<!– Specific Macro Variables for Networking –>
<X-PRE-PROCESS cmd=”set” data=”domain=yourdomain.com”/>
<X-PRE-PROCESS cmd=”set” data=”local_ip_v4=(Your_IP_Address)”/>
<X-PRE-PROCESS cmd=”set” data=”local_mask_v4=(Your_Netmask)”/>
<X-PRE-PROCESS cmd=”set” data=”internet_public_ip_v4=(Your_Public_IP_Address)”/>
<X-PRE-PROCESS cmd=”set” data=”hostname=PBX”/>
<X-PRE-PROCESS cmd=”set” data=”session_name=PBX”/

<X-PRE-PROCESS cmd=”stun-set” data=”external_rtp_ip=(Your_Public_IP_Address)”/>
<X-PRE-PROCESS cmd=”stun-set” data=”external_sip_ip=(Your_Public_IP_Address)”/>

<X-PRE-PROCESS cmd=”set” data=”outbound_caller_name=(Your_Outbound_Number)”/>
<X-PRE-PROCESS cmd=”set” data=”outbound_caller_id=(Your_Outbound_Number)”/>

Save:Exit

ถ้ายังไม่มี freeswitch Start Script ให้ลอง Start ด้วย Command นี้ดู

root@san:# freeswitch -nonat -nc &
และลอง ใช้คำสั่ง netstat -lntup เพื่อดู freeswitch process

ลองใช้ fs_cli เพื่อเข้า console ดู
root@san:/usr/local/freeswitch/conf/autoload_configs# fs_cli
pbx.omtel.ltd teee@khun-teee.com
Type /help to see a list of commands

[This app Best viewed at 160×60 or more..]
+OK log level [7]

root@san:/usr/local/freeswitch/conf# nano /etc/systemd/system/freeswitch.service

[Unit]
Description=FreeSWITCH
After=network.target

[Service]
User=root
Group=root
WorkingDirectory=/usr/local/freeswitch
ExecStart=/usr/local/freeswitch/bin/freeswitch -u root -g root -nonat -nc
Restart=always
LimitCORE=infinity
LimitNOFILE=100000
LimitNPROC=60000
LimitSTACK=24000000
LimitRTPRIO=99
LimitRTTIME=7000000
IOSchedulingClass=realtime
IOSchedulingPriority=2
CPUQuota=80%
CPUSchedulingPolicy=rr
CPUSchedulingPriority=89

[Install]
WantedBy=multi-user.target

root@san:/usr/local/freeswitch/conf# sudo systemctl enable freeswitch

ข้อความ “Unable to negotiate with (router ip address) port 22: no matching key exchange method found”

ข้อความ “Unable to negotiate with 192.168.100.8 port 22: no matching key exchange method found” เกิดขึ้นเพราะ:

>Cisco IOS ใช้ Diffie-Hellman (DH) แบบเก่า เช่น diffie-hellman-group14-sha1 หรือ diffie-hellman-group-exchange-sha1

>SSH Client (เช่น OpenSSH, PuTTY) ไม่รองรับ DH แบบเก่าด้วยเหตุผลด้านความปลอดภัย

วิธีแก้ไข

1. ใช้ SSH Client ที่รองรับ DH แบบเก่า (ชั่วคราว)
หากใช้ OpenSSH บน Linux/macOS ให้ลองระบุ Key Exchange (KEX) ที่รองรับ:
#ssh -o KexAlgorithms=+diffie-hellman-group14-sha1 admin@192.168.x.x

หรือ
#ssh -o KexAlgorithms=+diffie-hellman-group-exchange-sha1 admin@192.168.x.x
ข้อเสีย: วิธีนี้ปลอดภัยน้อยลง ควรใช้แค่ชั่วคราว

2. เปิดใช้ Key Exchange ที่ใหม่กว่าใน Cisco Router
ถ้าเข้าถึง CLI ของ Cisco Router ได้ ให้เพิ่ม Key Exchange ที่รองรับ SHA2 หรือ ECDH
Router#configure terminal
Router#ip ssh dh min size 2048
Router#exit
Routetr#write memory # บันทึกค่า
จากนั้นลอง SSH ใหม่อีกครั้ง

3. อัปเกรด OpenSSH หรือ Cisco IOS (ถ้าเป็นไปได้)
>บน Linux/macOS อัปเดต OpenSSH เป็นเวอร์ชันใหม่ล่าสุด
>บน Cisco Router ถ้าใช้ IOS รุ่นเก่า ควรอัปเกรดเป็น IOS 15.7 หรือใหม่กว่า

แก้ปัญหา %Error opening tftp://255.255.255.255/(hostname)-confg (Timed out)

Error นี้มักเกิดขึ้นใน Cisco Router หรือ Switch เนื่องจากอุปกรณ์พยายามหาไฟล์ network-confg หรือ router-confg จาก TFTP Server เพื่อใช้เป็น Auto Configuration แต่ไม่มีไฟล์นั้นอยู่จริง

วิธีแก้ไข
1. ปิดการค้นหา Auto Configuration บน TFTP
หากไม่ต้องการให้ Router หรือ Switch ค้นหาไฟล์ network-confg สามารถปิดการทำงานนี้ได้โดยใช้คำสั่ง:
Router#configure terminal
Router#no service config
Router#exit
Router#write memory # บันทึกการตั้งค่า
คำสั่ง no service config ปิดฟังก์ชันการค้นหาไฟล์ Config ผ่าน TFTP Server

2. ตรวจสอบว่ามีการตั้งค่า BOOTP หรือ DHCP Option 66 ไว้หรือไม่

ถ้าอุปกรณ์ได้รับ IP จาก DHCP และ DHCP Server ส่ง Option 66 (TFTP Server) ไปด้วย อาจทำให้อุปกรณ์พยายามดาวน์โหลด Config จาก TFTP โดยอัตโนมัติ
ให้ตรวจสอบการตั้งค่า DHCP ด้วยคำสั่ง:

Router#show running-config | include dhcp
หากมีการตั้งค่าให้ลองปิดด้วยคำสั่ง:
Router#no ip dhcp bootp ignore

3. ตรวจสอบว่า Router หรือ Switch ได้รับ IP Address ถูกต้องหรือไม่
ใช้คำสั่ง:
Router#show ip interface brief

หากไม่มี IP Address ให้กำหนดใหม่ เช่น:
Router#interface GigabitEthernet0/0
Router#ip address 192.168.1.100 255.255.255.0
Router#no shutdown
Router#exit

4. หากต้องการใช้ TFTP จริง ๆ ให้ตรวจสอบการตั้งค่า TFTP Server
>ตรวจสอบว่า TFTP Server ทำงานอยู่
>ตรวจสอบว่า ไฟล์ network-confg มีอยู่จริง
>ตรวจสอบ Firewall ว่าเปิดพอร์ต UDP 69 หรือไม่

หากต้องการดาวน์โหลดไฟล์จาก TFTP Server ให้ใช้คำสั่ง:
Router#copy tftp://192.168.1.10/config.txt running-config
(เปลี่ยน 192.168.1.10 เป็น IP ของ TFTP Server)

วิธีแก้ปัญหา Cisco Router Write ลง Mem แล้ว Reload Config หาย

สรุปวิธีแก้ปัญหา
ให้ลองเช็ค config-register
#show version | include Configuration register

ถ้าเป็น 0x2142 ให้แก้เป็น 0x2102

ค่าปกติควรเป็น 0x2102
ถ้าเป็น 0x2142 แสดงว่า router ถูกตั้งค่าให้ข้าม startup-config

#configure terminal
#config-register 0x2102
#end
#write memory
#reload

ติดตั้ง Elasticsearch V.8

REF >> https://www.elastic.co/guide/en/elasticsearch/reference/current/deb.html?nsukey=PjPLDGO3g/gIcuZ9p/7jsKolgoArD7qLdeCl2OonaUuBdL5Gg3wcUfJ2O/VkyeY/q2a/3N6Mf1iw%2B/EJ8VvzYashR1MyYLCTAF0JZJVCDhlVhDwvLMI92hDIjdf8i%2BDi3NgXl2uth/cddnE2xHHBQECd0vvSrL4Hv%2Bs/Z025f6r%2B%2BGJhYDmWD%2B7iF1aRakGss3N4OIFvU0bJd0CnvniKbg==

root@serv:/home/teee# wget -qO – https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg –dearmor -o /usr/share/keyrings/elasticsearch-keyring.gpg
sudo: gpg: command not found
root@serv:/home/teee# apt-get install gpg -y

root@serv:/home/teee# wget -qO – https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg –dearmor -o /usr/share/keyrings/elasticsearch-keyring.gpg

root@serv:/home/teee# echo “deb [signed-by=/usr/share/keyrings/elasticsearch-keyring.gpg] https://artifacts.elastic.co/packages/8.x/apt stable main” | sudo tee /etc/apt/sources.list.d/elastic-8.x.list

root@serv:/home/teee# sudo apt-get update && sudo apt-get install elasticsearch

————————— Security autoconfiguration information ——————————

Authentication and authorization are enabled.
TLS for the transport and HTTP layers is enabled and configured.

The generated password for the elastic built-in superuser is : EvW+InHCo0sPl-ej_M8t

If this node should join an existing cluster, you can reconfigure this with
‘/usr/share/elasticsearch/bin/elasticsearch-reconfigure-node –enrollment-token ‘
after creating an enrollment token on your existing cluster.

You can complete the following actions at any time:

Reset the password of the elastic built-in superuser with
‘/usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic’.

Generate an enrollment token for Kibana instances with
‘/usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s kibana’.

Generate an enrollment token for Elasticsearch nodes with
‘/usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s node’.

### Reset Elasticsearch Password ###
root@sanserv:/home/teee# /usr/share/elasticsearch/bin/elasticsearch-reset-password –interactive -u elastic
This tool will reset the password of the [elastic] user.
You will be prompted to enter the password.
Please confirm that you would like to continue [y/N]y

Enter password for [elastic]:
Re-enter password for [elastic]:
Password for the [elastic] user successfully reset.

AddNewUser
root@serv:/home/teee# /usr/share/elasticsearch/bin/elasticsearch-users useradd teee -p (MyPassword) -r superuser
root@serv:/home/teee# cat /etc/elasticsearch/users
teee:$2a$10$239MhoPHF5SOYhzs4/x90uFJnvEDpzCpSB9LE6pLCQaxCHE.ZYR4m

ทดสอบการล็อกอิน

หลังเพิ่มผู้ใช้งานใหม่แล้ว ให้ทดสอบการล็อกอินด้วย curl:
# curl -u myuser:mypassword -X GET http://127.0.0.1:9200

root@serv:/home/teee# curl -u teee:(MyPassword)-X GET https://127.0.0.1:9200
curl: (60) SSL certificate problem: self-signed certificate in certificate chain
More details here: https://curl.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.

แก้ไขไฟล์คอนฟิก Elasticsearch:
root@serv:/home/teee# nano /etc/elasticsearch/elasticsearch.yml
เพิ่มหรือแก้ไขบรรทัดต่อไปนี้:

ตั้งค่าใหม่
root@serv:/home/teee# nano /etc/elasticsearch/elasticsearch.yml
#TEEE
cluster.name: (YourClustername)
node.name: node-1
path.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch
network.host: 127.0.0.1
http.port: 9200
transport.port: 9300
cluster.initial_master_nodes: [“127.0.0.1”]

elasticsearch_username = teee
elasticsearch_password = (MyPassword)
elasticsearch_hosts = http://127.0.0.1:9200
elasticsearch_ssl_verification_mode = none

# ตั้งค่าจาก true เป็น false ถ้าเชื่อมต่อแบบ http
# Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents
xpack.security.http.ssl:
enabled: false
keystore.path: certs/http.p12

ตั้งค่าจาก true เป็น false ถ้าเชื่อมต่อแบบ http
# Enable encryption and mutual authentication between cluster nodes
xpack.security.transport.ssl:
enabled: false
verification_mode: certificate
keystore.path: certs/transport.p12
truststore.path: certs/transport.p12

network.host: 0.0.0.0 # เปิดให้เข้าถึงจากทุกที่
# หรือ
network.host: 192.168.1.10 # ตั้งให้เฉพาะเครื่องที่มี IP นี้เท่านั้นที่สามารถเชื่อมต่อได้

คุณต้องตั้งค่าอย่างน้อยหนึ่งในตัวแปรด้านล่างในไฟล์ elasticsearch.yml เพื่อให้ Elasticsearch รู้จักวิธีค้นหาโหนดในคลัสเตอร์:
1.discovery.seed_hosts: ใช้ระบุโฮสต์หรือ IP ของโหนดในคลัสเตอร์ที่จะใช้ในการค้นหาโหนดอื่นๆ
2.discovery.seed_providers: ใช้ระบุโปรแกรมค้นหาของโหนดภายนอก เช่น zen-disco
3.cluster.initial_master_nodes: กำหนดโหนดที่สามารถเริ่มต้นเป็น Master Node ในคลัสเตอร์แรก

วิธีตั้งค่าที่แนะนำ:
•สำหรับการตั้งค่าผลิตภัณฑ์ที่มีหลายโหนด (Multiple Nodes), คำแนะนำคือการใช้ discovery.seed_hosts และ cluster.initial_master_nodes

# ตั้งค่า discovery.seed_hosts เป็น IP ของโหนดในคลัสเตอร์
discovery.seed_hosts: [“192.168.1.10”, “192.168.1.11”]

# ตั้งค่า cluster.initial_master_nodes สำหรับ Master Node เริ่มต้นในคลัสเตอร์
cluster.initial_master_nodes: [“node-1”, “node-2”]

ในที่นี้:
•discovery.seed_hosts คือรายการของ IP หรือชื่อโฮสต์ของโหนดที่สามารถค้นหาคลัสเตอร์ได้
•cluster.initial_master_nodes คือรายชื่อโหนดที่ Elasticsearch จะเลือกเป็น Master Node แรกเมื่อเริ่มต้นคลัสเตอร์ (สำหรับกรณีเริ่มต้นคลัสเตอร์ใหม่)

หมายเหตุ:
•cluster.initial_master_nodes จะต้องตั้งค่าบนโหนดทุกตัวในคลัสเตอร์ตอนเริ่มต้นครั้งแรก (หลังจากนั้นจะไม่จำเป็นต้องตั้งค่าอีก)
•เมื่อคลัสเตอร์เริ่มต้นแล้ว, คุณไม่จำเป็นต้องใช้ cluster.initial_master_nodes อีกต่อไป เพราะระบบจะใช้การตั้งค่า discovery.seed_hosts หรือ discovery.zen-disco สำหรับการค้นหาโหนดต่อไป

เริ่มบริการและตั้งค่าให้ Elasticsearch เริ่มทำงานทุกครั้งที่ระบบบูต:
SystemDiag ขณะที่ทำการ StartUP
root@serv:~# tail -f /var/log/elasticsearch/graylog.log

การเปิดใช้งานการเชื่อมต่อแบบ SSL/TLS ใน Elasticsearch ต้องทำการตั้งค่าคีย์และใบรับรองที่จำเป็นในไฟล์ elasticsearch.yml และสร้างหรือเพิ่มใบรับรองที่เหมาะสมสำหรับเซิร์ฟเวอร์
ขั้นตอนการเปิดใช้งาน SSL/TLS ใน Elasticsearch:
1. สร้างใบรับรอง (Certificate)
Elasticsearch มีเครื่องมือสำหรับสร้างใบรับรองที่มาพร้อมกับแพ็กเกจชื่อว่า elasticsearch-certutil:
สร้างใบรับรองสำหรับ HTTPS:
root@serv:/home/teee# cd /usr/share/elasticsearch/bin
root@serv:/usr/share/elasticsearch/bin# ./elasticsearch-certutil http
Generate a CSR? [y/N]y
Generate a certificate per node? [y/N]y
You can use any descriptive name that you like, but we recommend using the name
of the Elasticsearch node.

node #1 name: node-1
Enter all the hostnames that you need, one per line.
When you are done, press once more to move on to the next step.

localhost
Is this correct [Y/n]y

Enter all the IP addresses that you need, one per line.
When you are done, press once more to move on to the next step.

(enter your graylog ip address)
Is this correct [Y/n]y
Key Name: node-1
Subject DN: CN=node-1
Key Size: 2048

Do you wish to change any of these options? [y/N]n
Generate additional certificates? [Y/n]n

## What password do you want for your private key(s)?

Your private key(s) will be stored as a PEM formatted file.
We recommend that you protect your private keys with a password

If you do not wish to use a password, simply press at the prompt below.
Provide a password for the private key: [ for none]
What filename should be used for the output zip file? [/usr/share/elasticsearch/elasticsearch-ssl-http.zip]

root@serv:/usr/share/elasticsearch/bin# cd /usr/share/elasticsearch/
root@serv:/usr/share/elasticsearch# apt-get install zip -y
root@serv:/usr/share/elasticsearch# unzip elasticsearch-ssl-http.zip -d /etc/elasticsearch/certs
root@serv:/usr/share/elasticsearch# cd /etc/elasticsearch/certs
root@serv:/etc/elasticsearch/certs# ls -l
total 32
drwxr-xr-x 4 root root 4096 Jan 30 04:46 elasticsearch
-rw-rw—- 1 root elasticsearch 10029 Jan 30 02:07 http.p12
-rw-rw—- 1 root elasticsearch 1915 Jan 30 02:07 http_ca.crt
drwxr-xr-x 2 root root 4096 Jan 30 04:46 kibana
-rw-rw—- 1 root elasticsearch 5838 Jan 30 02:07 transport.p12

เปิดใช้งาน SSL
# Enable security features
xpack.security.enabled: true

xpack.security.enrollment.enabled: true

# Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents
xpack.security.http.ssl:
enabled: true
keystore.path: /etc/elasticsearch/certs/http.p12

# Enable encryption and mutual authentication between cluster nodes
xpack.security.transport.ssl:
enabled: true
verification_mode: certificate
keystore.path: /etc/elasticsearch/certs/transport.p12
truststore.path: /etc/elasticsearch/certs/transport.p12
root@serv:/home/teee# systemctl start elasticsearch

ทดสอบการเชื่อมต่อแบบ SSL
root@serv:/etc/elasticsearch/certs# curl -u teee:MyPassword –cacert /etc/elasticsearch/certs/http_ca.crt -X GET https://127.0.0.1:9200
{
“name” : “node-1”,
“cluster_name” : “graylog”,
“cluster_uuid” : “B92A2i1YQNSmfsRo60NRnQ”,
“version” : {
“number” : “8.17.1”,
“build_flavor” : “default”,
“build_type” : “deb”,
“build_hash” : “d4b391d925c31d262eb767b8b2db8f398103f909”,
“build_date” : “2025-01-10T10:08:26.972230187Z”,
“build_snapshot” : false,
“lucene_version” : “9.12.0”,
“minimum_wire_compatibility_version” : “7.17.0”,
“minimum_index_compatibility_version” : “7.0.0”
},
“tagline” : “You Know, for Search”
}