แสดงกระทู้

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - golfreeze

Pages: 1 [2] 3 4 ... 73
16
===สคิป find folder then chmod folder 755 and file 644 in wordpress
find /home/wordpress/htdocs \
\( -type f -exec chmod ug+rw,o+r {} \; \) , \
\( -type d -exec chmod ug+rwxs,o+rx {} \; \)

17
command , shell script ,tool , crontab / grep , egrep , fgrep howto
« on: กันยายน 04, 2022, 06:16:03 PM »
==show line number if found exact word "day" not "today" in file test.txt
grep -n -w "day" test.txt

18
command , shell script ,tool , crontab / basic of awk by golfreeze
« on: กันยายน 04, 2022, 10:24:46 AM »
##show second column contain word "account"
awk '$2 ~ account {print} ' filenamel

##show first column start with "e" in file check.sh
awk '$1 ~ /^e/ {print } ' check.sh

##show first column start with not contain "e" in file check.sh
awk '$1 !~ /^e/ {print } ' check.sh

##search and grep "account" from file
awk '/account/ {print } ' check.sh
awk '/^account/ {print }' check.sh

##if > < >= <= && || finding $5 more than 2000 and less than 2500 then print
awk '$5 > 2000 && $5 <2500 {print $0}' check.sh

##if > < >= <= && || finding $5 more than 2000 or $5 not contain "sal" in line then print
awk '$5 > 2000 || $5 !~ /sal/ {print $0}' check.sh

##if need change first line with specific "Start processing" and grep "account"
awk 'BEGIN {print "Start processing"} {print $0}' check.sh
awk 'BEGIN {print "Start processing"} /account/ {print $0}' check.sh

###if need add BEGIN and END of awk and grep "account"
awk 'BEGIN {print "Start processing"} /account/ {print $0} END {print "End processed"}' check.sh

##if need count NR=Number record , NF=Number of field
awk '{print NR,$0,NF} END {print "End processed"}' check.sh

##if need print LAST Field $NF
awk '{print NR,$0,$NF,FILENAME} ' check.sh

##if need only line4 until line8 in file to show
awk 'NR==4,NR==8  {print $0}' check.sh
awk 'NR==4,NR==8 {print $0}' check.sh | awk '$3 ~ /username/'

##if substitute space with some character use OFS=output field substitute => if see space " " then replace with "@@"
awk 'NR==4,NR==8 {print $0}' check.sh | awk 'BEGIN{OFS="@@"} {print $2,$3}'
awk 'BEGIN {print "Start processing"} {print $0}' text3 | awk 'BEGIN{OFS="@"} {print $1,$2".com"}'

##if substitute space with some character use FS=field substitute => if see ":" then replace with space " "
awk 'BEGIN{FS=":"} {print $2,$3}' text4

##if substitute space with some character use FS=field substitute => if see ":" then replace with "@@"
awk 'BEGIN{FS=":";OFS="@@"} {print $2,$3}' text4

##if substitute last character in file use ORS=":" with :
awk 'BEGIN {print "Start processing"} {print $0}' text3 | awk 'BEGIN{OFS="@";ORS=":"} {print $1,$2".com"}'
output=> Start@processing.com:store@manager.com:Woodridge,Australia@Jon.com:Lethbridge,Canada@Mike.com:Bridge,
Canada@Mike.com:Sisaket,Thailand@Liamthong.com:Pathumthani,Thailand@White.com:Saimai,Bangkok@Packetlove.com:

###if need awk run if condition or run condition on script file
awk '{if ($3 > 2000) print $0 }' text3
output=>
store                manager       total_sales
Woodridge,Australia  Jon Stephens     33726.77
Lethbridge,Canada    Mike Hillyer     33679.79
Bridge,Canada   Mike Hillyer          43679.89
Saimai,Bangkok          Packetlove      8229.4

awk '{if ($3 > 2000) print $0; else print "Low" }' text3
output=>
store                manager       total_sales
Woodridge,Australia  Jon Stephens     33726.77
Lethbridge,Canada    Mike Hillyer     33679.79
Bridge,Canada   Mike Hillyer          43679.89
Low
Low
Saimai,Bangkok          Packetlove      8229.4

###if need awk run if condition or run condition on script file
awk -f script text4

###toupper=change small character to BIG capital leeter  on first column , length=count length of character on $3
awk '{print toupper($1),length($3)} {print $0}' text3

19
all application on unix knowledges by golfreeze / postgres export data to csv file
« on: สิงหาคม 20, 2022, 03:01:02 AM »
===== DB Task ===== run import script in sql
testdb=> \copy (select * from param_change_request where id in (161, 162)) TO '/home/testdb/backhour.csv' CSV HEADER;

แล้วสามารถไปดูที่ไฟล์ backhour.csv ได้ครับ

20
all application on unix knowledges by golfreeze / postgres psql command import query
« on: สิงหาคม 20, 2022, 02:56:45 AM »
ถ้าเรามีการเตรียม สคิปในไฟล์ check_query_alter_update.sql เพื่อทำรายการใน db=testdb เราสามารถรันผ่าน command psql ได้ดังนี้

postgres=> \c  testdb
testdb=> \i 19aug2022_operation/Script/check_query_alter_update.sql
ALTER TABLE

เท่านี้ครับผม

21
===for centos , debian 11
cd /usr/local/directadmin/scripts/custom
wget https://raw.githubusercontent.com/poralix/directadmin-utils/master/php/php-extension.sh -O php-extension.sh
chmod 750 php-extension.sh
./php-extension.sh install redis

==for freebsd
cd /usr/local/directadmin/scripts/custom
wget https://raw.githubusercontent.com/poralix/directadmin-utils/master/php/php-extension.sh -O php-extension.sh
chmod 750 php-extension.sh

mkdir -p /usr/local/src
และแก้ไข #!/bin/bash -> #!/usr/local/bin/bash ใน php-extension.sh แล้วรัน
./php-extension.sh install redis

22
csf lfd stop alert email for nrpe on debian os directadmin
กรณีมีอีเมลส่งมาแจ้ง เยอะ alert สามารถแก้ไขเพื่อไม่ให้ส่ง email จาก service csf ที่เป้นหัวข้อ lfd ได้โดย

If debian enable “csf” need allow on csf.conf “TCP_in” and “TCP_out” and
Disable lfd for resource usage

Subject: lfd on packetlove.com: Excessive resource usage: nagios (494190 (Parent PID:494190))
From:  <root@packetlove.com>
Message-Id: <E1ne3x7-002N0R-7t@packetlove.com>
Date: Tue, 12 Apr 2022 07:00:13 +0700

Time:         Tue Apr 12 07:00:13 2022 +0700
Account:      nagios
Resource:     Process Time
Exceeded:     75567 > 1800 (seconds)
Executable:   /usr/local/nagios/bin/nrpe
Command Line: /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -f
PID:          494190 (Parent PID:494190)
Killed:       No

--1649721613-eximdsn-849789542--

==แก้ไขเพื่อไม่ให้ส่ง email ได้โดย
vi /etc/csf/csf.pignore
user:nagios
exe:/usr/local/nagios/bin/nrpe
cmd:/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -f
==reload csf rule 1 รอบ
csf -r

23
วันนี้มีโจทย์ให้ทำ บน DirectAdmin ให้ uninstall pureftp และทำการ enable proftpd พร้อมกับ sFTP feature ขึ้นมา

==เริ่มด้วย stop pureftp first เพราะ default ลงมาเป็น pureftp
cd /usr/local/directadmin/custombuild
./build set pureftpd_uploadscan no

ทำการ build proftpd
# cd /usr/local/directadmin/custombuild
# ./build update
# ./build set ftpd proftpd
# mkdir -p custom/proftpd/conf (make a directory for custom ProFTPd config that adds mod_sftp)
# wget -O custom/proftpd/configure.proftpd http://files.directadmin.com/services/all/sftp/configure.proftpd.sftp
# wget -O custom/proftpd/conf/proftpd.conf http://files.directadmin.com/services/all/sftp/proftpd.conf
# chmod 755 custom/proftpd/configure.proftpd
# wget -O /etc/proftpd.sftp.conf http://files.directadmin.com/services/all/sftp/proftpd.sftp.conf
# mkdir /etc/proftpd.ssl
# cp /etc/ssh/ssh_host_rsa_key* /etc/proftpd.ssl
# chmod 400 /etc/proftpd.ssl/ssh_host_rsa_key
# cp /etc/proftpd.sftp.conf /etc/proftpd.sftp.conf_original

===Edit /etc/proftpd.sftp.conf ตรงส่วน SFTPHostKey ให้ไปชี้ /etc/proftpd.ssl/ssh_host_rsa_key แทน !!!! ไม่งั้นจะทำงาน sftp ไม่ได้ ===
<IfModule mod_sftp.c>
<VirtualHost 0.0.0.0>
# The SFTP configuration
# Port 23
Port 22 # Change to standard port now possible after moving SSH to 44
AuthUserFile /etc/proftpd.passwd
TransferLog /var/log/proftpd/xferlog.legacy
ExtendedLog /var/log/proftpd/75.126.244.2.bytes WRITE,READ userlog
SFTPEngine on
SFTPLog /var/log/proftpd/sftp.log
# SFTPHostKey /etc/ssh/ssh_host_rsa_key
SFTPHostKey /etc/proftpd.ssl/ssh_host_rsa_key # Change to use key pair copied to /etc/proftpd.ssl and given necessary rights (0400) for mod_sftp.c work.
SFTPAuthorizedUserKeys file:~/.sftp/authorized_keys

หลังจากนั้นทำการ rebuild อีกรอบ
# cd /usr/local/directadmin/custombuild
# ./build proftpd
service proftpd restart

แล้วเทสกับ Filezilla ก็จะใช้งาน sFTP ได้ครับผม  :)

===recompile proftpd
https://forum.directadmin.com/threads/how-to-set-up-your-proftpd-ftp-server-to-support-the-secure-protocols-while-disabling-insecure-ftp.65025/
https://forum.directadmin.com/threads/proftpd-issue-with-sftp.63352/
https://docs.directadmin.com/other-hosting-services/ftp/general.html

24
upgrade mac-os แล้วทำการ copy text content on terminal ไม่ได้

คือหลังจากอัฟเกรด mac os จาก mojave-> montery แล้วทำการ copy text บน terminal ไม่ได้แก้ไขโดย ไปที่
Terminal -> View -> ติ๊กถูก Allow Mouse Reporting ออก 

 8)

25
ถ้าเจอปัญหาเรื่อง nagios check_ping: CRITICAL - Could not interpret output from ping command #46
sh-4.4# su - nagios
$ /bin/ping -n -U -w 30 -c 5 127.0.0.1
ping: socket: Address family not supported by protocol
$ /bin/ping -4 -n -U -w 30 -c 5 127.0.0.1
ping: socket: Operation not permitted


สามารถทำการแก้ไขได้โดย
sh-4.4# chmod +s /bin/ping
sh-4.4# su - nagios
$ /bin/ping -4 -n -U -w 30 -c 5 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.097 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.053 ms

==special thank : https://github.com/bodsch/docker-icinga2/issues/46

26
On CentOS8.x End of life , then if you running "yum update" will found error

Failed to download metadata for repo ‘appstream’: Cannot prepare internal mirrorlist

So how to fixed

==change mirrorlist ==
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-Linux-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-Linux-*

== install centos-release-stream
sudo dnf install centos-release-stream -y
sudo dnf swap centos-{linux,stream}-repos -y
sudo dnf distro-sync -y

yum update
==finished ==
 ;)

Special Thank:
https://flutterq.com/failed-to-download-metadata-for-repo-appstream-cannot-prepare-internal-mirrorlist-no-urls-in-mirrorlist/

27
หลังจากทำการ extend disk ผ่าน vcenter ต้องทำการรัน eagerzeroedthick ด้วยสำหรับ disk ที่มีการ share กันระหว่าง clustering เนื่องจากมีการปรับค่ากลับไปเป็น lazy ในตอนแรกต้องทำกลับมาเป้น eagerzeroedthick
เปิด ssh service on esx-i แล้วใช้ putty login เข้าไปที่ console
 
vmkfstools --eagerzero /vmfs/volumes/myVMFS/VMName/disk.vmdk

รอการปรับ disk ระยะเวลาที่ใช้ประมาณ 30-60 นาทีสำหรับ 500GB ขึ้นอยู่กับขนาดที่ปรับ
https://docs.vmware.com/en/VMware-vSphere/7.0/com.vmware.vsphere.storage.doc/GUID-60B9C89A-6638-43FA-A8E3-4DACAC85FC29.html

28
===install squid on ubuntu20.04
apt update
apt install squid
systemctl status squid.service
systemctl enable squid.service
vi /etc/squid/squid.conf

===start of squid.conf===
# Deny requests to certain unsafe ports
http_access deny !Safe_ports
 # Deny CONNECT to other than secure SSL ports
 http_access deny CONNECT !SSL_ports
 # Only allow cachemgr access from localhost
 http_access allow localhost manager
 http_access deny manager
 # We strongly recommend the following be uncommented to protect innocent
 # web applications running on the proxy server who think the only
 # one who can access services on "localhost" is a local user
 #http_access deny to_localhost
 #
 # INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
 #
 include /etc/squid/conf.d/*
 ##allow user pass authen via proxy
 auth_param basic program /usr/lib/squid3/basic_ncsa_auth /etc/squid/passwords
 auth_param basic realm proxy
 acl authenticated proxy_auth REQUIRED
 ##add from golf ip whois current ip check via https://whatismyipaddress.com/
 acl localnet src 49.228.38.136
 # Example rule allowing access from your local networks.
 # Adapt localnet in the ACL section to list your (internal) IP networks
 # from where browsing should be allowed
 #http_access allow localnet
 #http_access allow localhost
 http_access allow authenticated
 # And finally deny all other access to this proxy
 http_access deny all
===end of squid.conf===

===after that last step need to install for htaccess password user
apt install apache2-utils
htpasswd -c /etc/squid/passwords axpkl2
systemctl restart squid.service
ufw allow 3128

=====Ip: 116.204.180.2
=====setup proxy user and password
htpasswd  /etc/squid/passwords axpkl3


==test from pc or Macbook (49.228.38.136)
curl -v -x http://axpkl2:pklpkl2@116.204.180.2:3128 http://www.google.com/

=====show log could connect via proxy normally
===tail -f /var/log/squid/access.log
==DENIED
1643733370.341      0 49.228.38.136 TCP_DENIED/407 4051 CONNECT www.google.com:443 axpkl HIER_NONE/- text/html
==CONNECTED
1643733378.519    291 49.228.38.136 TCP_TUNNEL/200 26450 CONNECT www.google.com:443 axpkl2 HIER_DIRECT/142.250.199.36

29
migrate and export redis on prem and restore to AWS elasticache

======Example: Redis Backup ==> https://www.w3resource.com/redis/redis-backup.php
The example given below creates the backup of the current database.
127.0.0.1:6379> SAVE
OK
This command will create the dump.rdb file in your redis directory.

Restore:
CONFIG GET
To restore redis data just move redis backup file (dump.rdb) into your redis directory and start the server. To get your redis directory use CONFIG command can be used. The CONFIG GET command is used to read the configuration parameters of a running Redis server.
127.0.0.1:6379> CONFIG get dir
1) “dir"
2) "/var/lib/redis/6379”
In the output of above command "/var/lib/redis/6379" is the directory, where redis server is installed.

==== restore .rdb to AWS elastic ache  https://github.com/leonchen83/redis-rdb-cli
apt-get install openjdk-8-jdk
wget https://github.com/leonchen83/redis-rdb-cli/releases/download/v0.7.4/redis-rdb-cli-release.zip
unzip redis-rdb-cli-release.zip
cd ./redis-rdb-cli/bin
./rmt -h

==connect via stunnel4 need to connect via stunnel
./rmt -s dump.rdb -m redis://172.31.20.105:6374 -r
get golf2
or
./rmt -s dump.rdb -m redis://172.31.20.105:6374 -t list -d 0
 \[    5 B|    3 B/s]

30
upgrade php7.4 on directadmin

==== upgrade PHP7.4
cd /usr/local/directadmin/custombuild
./build update
./build set php1_release 7.4
./build set php1_mode php-fpm

./build php n
./build rewrite_confs

===If found error
Libjpeg not found

==fixed by install libjpeg-devel on centos
yum install libjpeg-devel
yum -y install krb5-devel

==fixed by install libjpeg-devel on Debian
apt install libjpeg-dev
apt install krb5-dev

==fixed by install on freebsd [checking whether to build with LIBXML support... yes
checking for libxml-2.0 >= 2.7.6... no
configure: error: in `/usr/local/directadmin/custombuild/php-7.4.2':
configure: error: The pkg-config script could not be found or is too old. Make sure it
is in your PATH or set the PKG_CONFIG environment variable to the full
path to pkg-config.]
=> fixed by
pkg install pkgconf krb5

===If found error
checking for icu-uc >= 50.1 icu-io icu-i18n… no
configure: error: Package requirements (icu-uc >= 50.1 icu-io icu-i18n) were not met:
Requested 'icu-uc >= 50.1' but version of icu-uc is 4.8.1.1

===fixed by re-build icu
./build update
./build icu
==start compile php again.
./build php n

==or build only 7.4
./build php_expert 7.4 php-fpm

Pages: 1 [2] 3 4 ... 73