ติดตั้ง Visual Studio Code บน CentOS 7

อัพเดท repository

sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
sudo sh -c 'echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/vscode.repo'

ติดตั้ง code

yum check-update
sudo yum install code

เรียกใช้ code

code &

หรือกำหนดโฟลเดอร์

code . &

ติดตั้ง Python3 บน CentOS 7

เดิม CentOS7 จะติดตั้ง Python 2.7.5 มาให้

ติดตั้งจาก Package Manager

อัพเดท repo

$ sudo yum update

ติดตั้ง Python3

$ sudo yum install -y python3

ตรวจสอบเวอร์ชัน

$ python3 --version
Python 3.6.8
$ pip3 --version
pip 9.0.3 from /usr/lib/python3.6/site-packages (python 3.6)
$ python3 -m pip --version
pip 9.0.3 from /usr/lib/python3.6/site-packages (python 3.6)

ติดตั้งผ่าน Package Manager จะได้ Python3.6 ติดตั้งอยู่ที่ /usr/bin/python3.6

ติดตั้งเวอร์ขันที่ต้องการจาก Source Code

ติดตั้ง required packages and dependencies

sudo yum groupinstall "Development Tools" -y
sudo yum install gcc open-ssl-devel bzip2-devel libffi-devel -y
sudo yum install zlib-devel

ดาว์นโหลดเวอร์ชัน 3.7.12 (04-Sep-2021)

wget https://www.python.org/ftp/python/3.7.12/Python-3.7.12.tgz
tar xzf Python-3.7.12.tgz

ติดตั้ง

cd Python-3.7.12
./configure --with-openssl=/home/[username]/openssl
./configure --enable-optimizations
sudo make altinstall

Python3.7 จะติดตั้งอยู่ที่ /usr/local/bin

กำหนด default python ให้เป็น Python3.7

sudo ln -fs /usr/local/bin/python3.7   /usr/bin/python3
sudo ln -fs /usr/local/bin/pydoc3.7    /usr/bin/pydoc3
sudo ln -fs /usr/local/bin/pyvenv-3.7  /usr/bin/pyvenv3
sudo ln -fs /usr/local/bin/pip3.7      /usr/bin/pip3

สร้างไฟล์ทดสอบ helloworld.py

#!/usr/bin/python3

print("Hello World!")

เปลี่ยน permission

chmod 755 helloworld.py

รัน

./helloworld.py

เรื่องของ yum กับ Python3

ถ้าเซ็ตให้คำสั่ง python ชี้ไปที่ python3.7

sudo ln -fs /usr/local/bin/python3.7   /usr/bin/python   

จะใช้คำสั่ง yum ไม่ได้ โดยจะ error ประมาณนี้

$ sudo yum install tree
  File "/bin/yum", line 30
    except KeyboardInterrupt, e:
                            ^
SyntaxError: invalid syntax

Because yum does not support Python3.

ให้แก้ไขไฟล์ /bin/yum จาก !/usr/bin/python เป็น !/usr/bin/python2 ก็จะรัน yum ได้ (แต่อาจเจอปัญหาอื่นตามมาอีก – เปลี่ยน default python กลับไปที่ python2 ดีกว่า)

อัพเดท pip

ตรวจสอบเวอร์ชัน

$ pip3 --version
pip 20.1.1 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)

ไม่แน่ใจว่า require openssl openssl-devel กับ epel-release มั๊ย

sudo yum install openssl openssl-devel
sudo yum install epel-release

ตรวจสอบโมดูล ssl ถ้าปกติรัน python3 -m ssl แล้วจะไม่มีอะไรเกิดขึ้น

python3 -m ssl

อัพเดท pip

python3 -m pip install --upgrade pip

ตรวจสอบเวอร์ชันอีกที

$ pip3 --version
pip 21.2.4 from /home/jack/.local/lib/python3.7/site-packages/pip (python 3.7)

ติดตั้ง Chrome บน CentOS 7

1. Downloading the latest Google Chrome .rpm package

wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm

2. Install Google Chrome on your CentOS 7 system

sudo yum localinstall google-chrome-stable_current_x86_64.rpm

3. Starting Google Chrome

google-chrome &

Start Google Chrome by clicking on the Google Chrome icon (Applications → Internet → Google Chrome):

ติดตั้ง SQL Server 2017 บน CentOS 7

Install SQL Server 2017

1.Download the Microsoft SQL Server 2017 Red Hat repository configuration file:

sudo curl -o /etc/yum.repos.d/mssql-server.repo https://packages.microsoft.com/config/rhel/7/mssql-server-2017.repo

2.Run the following commands to install SQL Server:

sudo yum install -y mssql-server

3.After the package installation finishes, run mssql-conf setup and follow the prompts to set the SA password and choose your edition.

sudo /opt/mssql/bin/mssql-conf setup

4.Once the configuration is done, verify that the service is running:

systemctl status mssql-server

5.To allow remote connections, open the SQL Server port on the firewall on RHEL. The default SQL Server port is TCP 1433. If you are using FirewallD for your firewall, you can use the following commands:

sudo firewall-cmd --zone=public --add-port=1433/tcp --permanent
sudo firewall-cmd --reload

Install the SQL Server command-line tools

1.Download the Microsoft Red Hat repository configuration file.

sudo curl -o /etc/yum.repos.d/msprod.repo https://packages.microsoft.com/config/rhel/7/prod.repo

2.If you had a previous version of mssql-tools installed, remove any older unixODBC packages.

sudo yum remove unixODBC-utf16 unixODBC-utf16-devel

3.Run the following commands to install mssql-tools with the unixODBC developer package. For more information, see Install the Microsoft ODBC driver for SQL Server (Linux).

sudo yum install -y mssql-tools unixODBC-devel

4.For convenience, add /opt/mssql-tools/bin/ to your PATH environment variable. This enables you to run the tools without specifying the full path. Run the following commands to modify the PATH for both login sessions and interactive/non-login sessions:

echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
echo $PATH

Connect locally

1.Run sqlcmd with parameters for your SQL Server name (-S), the user name (-U), and the password (-P).

sqlcmd -S localhost -U SA -P '<YourPassword>'

Create and query data

Create a new database

1.From the sqlcmd command prompt, paste the following Transact-SQL command to create a test database:

CREATE DATABASE TestDB

2.On the next line, write a query to return the name of all of the databases on your server:

SELECT Name from sys.Databases

3.The previous two commands were not executed immediately. You must type GO on a new line to execute the previous commands:

GO

Exit the sqlcmd command prompt

QUIT

ติดตั้ง Graphviz บน Ubuntu 18.04

ติดตั้ง Graphviz

sudo apt install graphviz
sudo yum install graphviz

ดูเวอร์ชันที่ติดตั้ง

$ dot -V
dot - graphviz version 2.40.1 (20161225.0304)

ทดลองใช้งานทาง Command Line

echo 'digraph { a -> b }' | dot -Tsvg > output.svg
echo 'digraph { a -> b }' | dot -Tsvg -o output.svg

ใส่ข้อความและกำหนดสีของข้อความ (set a graph attribute -Gname[=value])

echo 'digraph { a -> b }' | dot -Tsvg -Gfontcolor=red -Glabel="My favorite letters" > output2.svg

กำหนดรูปแบบของโหนด (set a default node attribute -Nname[=value] )

echo 'digraph { a -> b }' | dot -Tsvg -Nfontcolor=red -Nshape=rect > output3.svg

กำหนดรูปแบบของ edge และลูกศร (set a default edge attribute -Ename[=value])

บันทึกไฟล์ output เป็น png หรือฟอร์แมตอื่นๆดู supported formats

echo 'digraph { a -> b }' | dot -Tpng -Ecolor=red -Earrowhead=diamond > output4.png

Huawei obsutil tool

Configuration 

obsutil config -i=ak -k=sk -e=endpoint

ดู endpoint ของ Object Storage Service (OBS) เช่น region AP-Bangkok มี endpoint เป็น obs.ap-southeast-2.myhuaweicloud.com เวลานำไปใช้เติม https:// ด้านหน้าด้วย

> obsutil config -i=XXXXXXXXXXXXX -k=XXXXXXXXXXXXX -e=https://obs.ap-southeast-2.myhuaweicloud.com
Config file url:
  C:\Users\jack\.obsutilconfig

Update config file successfully!

Checking the Connectivity ด้วยการ แสดงรายการ bucket ที่มี

obsutil ls -s

Querying Bucket Properties ดู properties ของ bucket ชื่อ obs-test-daily

> obsutil stat obs://obs-test-daily

Listing Objects แสดงรายการไฟล์และโฟลเดอร์ใน bucket ชื่อ obs-test-daily

> obsutil ls obs://obs-test-daily

Creating a Folder สร้างโฟลเดอร์ชื่อ raw ใน bucket ชื่อ obs-test-daily

> obsutil mkdir obs://obs-test-daily/raw

Uploading an Object

อัพโหลดไฟล์ D:\temp\2021-07-28.json ไปที่ obs-test-daily/raw/ และเปลี่ยนชื่อไฟล์เป็น 210728.json

> obsutil cp D:\temp\2021-07-28.json obs://obs-test-daily/raw/210728.json

อัพโหลดทั้งโฟลเดอร์ D:\temp\2021-09-01\ ไปที่ obs-test-daily/raw/

> obsutil cp D:\temp\2021-09-01\ obs://obs-test-daily/raw/ -f -r

Deleting an Object

ลบไฟล์ raw/210728.json

> obsutil rm obs://obs-test-daily/raw/210728.json

Downloading an Object

ดาว์นโหลดโฟลเดอร์ 2021-09-01 มาไว้ที่ C:\OBS\

> obsutil cp obs://obs-test-daily/raw/2021-09-01 C:\OBS\ -f -r

ติดตั้ง obsfs บน Ubuntu 18.04

!! ใช้ Huawei obsutil tool ดีกว่า !!

ดาว์นโหลด obsfs จาก Developer Tools จะได้ไฟล์ติดตั้งสำหรับ Ubuntu 14.04

วิธีติดตั้ง Introduction to obsfs, Method 1: Downloading and Installing obsfs, Method 2: Generating obsfs by Compilation

wget https://obs-community-intl.obs.ap-southeast-1.myhuaweicloud.com/obsfs/current/obsfs_Ubuntu14.04_amd64.tar.gz

แตกไฟล์

tar -zxvf obsfs_Ubuntu14.04_amd64.tar.gz

ติดตั้ง obsfs

sudo ./install_obsfs.sh

ลองเรียกใช้งานจะ error

sudo obsfs
obsfs: /usr/lib/x86_64-linux-gnu/libcurl.so.4: version `CURL_OPENSSL_3' not found (required by obsfs)

ให้ติดตั้ง libcurl3

sudo apt-get install libcurl3 -y

ลองเรียกใช้อีกทีจะใช้ได้ละ

sudo obsfs
obsfs: missing BUCKET argument.
Usage: obsfs PFS:[PATH] MOUNTPOINT [OPTION]...
sudo obsfs --version
Huawei Object Storage Service File System V 3.19.7