ติดตั้ง Azkaban 3.84.14 บน Ubuntu 18.04.5 LTS

Link

อันนี้ติดตั้งแบบ Solo Server

In solo server mode, the DB is embedded H2 and both web server and executor server run in the same process.

The multiple executor mode is for most serious production environment. Its DB should be backed by MySQL instances with master-slave set up. The web server and executor servers should ideally run in different hosts

ติดตั้ง Azkaban 3.84.14 บน Ubuntu 18.04.5 LTS

และลอง ติดตั้ง Azkaban 3.90.0 บน Ubuntu 20.04.6 LTS ได้

แต่ลอง ติดตั้ง Azkaban 4.0.0 บน Ubuntu 20.04.6 LTS ไม่ได้ ติดตอน bin/start-solo.sh แล้ว error No implementation for azkaban.imagemgmt.services.ImageRampupService was bound.

อัพเดทแพกเกจ

sudo apt update

ถ้าเดิมมี ติดตั้ง Java 11 ให้เอาออกก่อน (Uninstall OpenJDK in Ubuntu. Though the Ubuntu environments comes… | by Hirosh Tharaka (BSc.Hons, CTFL) | Medium)

$ sudo apt-get purge --auto-remove openjdk*

ติดตั้ง Java 8

sudo apt install openjdk-8-jdk

ติดตั้ง Hadoop

ถ้าใช้ Hadoop ก็ ติดตั้ง Hadoop in Stand-Alone Mode บน Ubuntu 18.04

ติดตั้ง Azkaban

ดาว์นโหลด Azkaban 3.84.14

git clone https://github.com/phaisarnsut/azkaban3.84.14.git
หรือ
git clone https://github.com/phaisarnsut/azkaban3.90.0.git
$ mv azkaban3.84.14/ azkaban
$ cd azkaban/
$ chmod +x gradlew

Build

แก้ไขไฟล์ azkaban-web-server/build.gradle จาก

distBaseUrl = 'https://nodejs.org/dist'

เป็น

distBaseUrl = 'https://direct.nodejs.org/dist/'
$ ./gradlew distZip
Downloading https://services.gradle.org/distributions/gradle-4.6-all.zip
...

unzip Azkaban solo server

sudo apt install unzip
$ unzip azkaban-solo-server/build/distributions/azkaban-solo-server-0.1.0-SNAPSHOT.zip

สร้างไฟล์ config

หรือ copy ตัวอย่างมาจาก azkaban-solo-server/src/main/resources/conf/ หรือ azkaban/azkaban-solo-server/src/main/resources/conf at master · azkaban/azkaban · GitHub

$ cd azkaban-solo-server-0.1.0-SNAPSHOT/
$ mkdir conf
$ cd conf

สร้างไฟล์ azkaban.properties

# Azkaban Personalization Settings
azkaban.name=Test
azkaban.label=My Local Azkaban
azkaban.color=#FF3601
azkaban.default.servlet.path=/index
web.resource.dir=web/
default.timezone.id=America/Los_Angeles
# Azkaban UserManager class
user.manager.class=azkaban.user.XmlUserManager
user.manager.xml.file=conf/azkaban-users.xml
# Loader for projects
executor.global.properties=conf/global.properties
azkaban.project.dir=projects
database.type=h2
# h2.path=./h2
h2.path=.
# h2.create.tables=true
# Velocity dev mode
velocity.dev.mode=false
# Azkaban Jetty server properties.
jetty.use.ssl=false
jetty.maxThreads=25
jetty.port=8081
# Azkaban Executor settings
executor.port=12321
# mail settings
mail.sender=
mail.host=
# User facing web server configurations used to construct the user facing server URLs. They are useful when there is a reverse proxy between Azkaban web servers and users.
# enduser -> myazkabanhost:443 -> proxy -> localhost:8081
# when this parameters set then these parameters are used to generate email links.
# if these parameters are not set then jetty.hostname, and jetty.port(if ssl configured jetty.ssl.port) are used.
# azkaban.webserver.external_hostname=myazkabanhost.com
# azkaban.webserver.external_ssl_port=443
# azkaban.webserver.external_port=8081
job.failure.email=
job.success.email=
lockdown.create.projects=false
cache.directory=cache
# JMX stats
jetty.connector.stats=true
executor.connector.stats=true
# Azkaban plugin settings
azkaban.jobtype.plugin.dir=plugins/jobtypes
# Number of executions to be displayed
azkaban.display.execution_page_size=16
azkaban.use.multiple.executors=true
azkaban.executor.runtimeProps.override.eager=false
# Azkaban Ramp Feature Configuration
#Ramp Feature Related
azkaban.ramp.enabled=true
azkaban.ramp.status.polling.enabled=true
azkaban.ramp.status.polling.interval.min=30
azkaban.ramp.status.push.interval.threshold=15
azkaban.ramp.status.pull.interval.threshold=100

สร้างไฟล์ azkaban-users.xml

<azkaban-users>
  <user groups="azkaban" password="azkaban" roles="admin" username="azkaban"/>
  <user password="metrics" roles="metrics" username="metrics"/>

  <role name="admin" permissions="ADMIN"/>
  <role name="metrics" permissions="METRICS"/>
</azkaban-users>

สร้างไฟล์เปล่า global.properties

touch global.properties
cd ..

Start the server

$ cd azkaban-solo-server-0.1.0-SNAPSHOT/
$ pwd
/home/jack/Downloads/azkaban/azkaban-solo-server-0.1.0-SNAPSHOT

Start the solo server:

$ bin/start-solo.sh

ดูว่า start ขึ้นมั๊ย

$ cat soloServerLog_*
เช่น
$ cat soloServerLog__2022-05-05+14:52:27.out

Stop server

$ bin/shutdown-solo.sh

ทดลองเรียกไปที่ http://localhost:8081/

ตัวอย่าง Flow แบบง่าย

สร้างไฟล์ flow20.project

azkaban-flow-version: 2.0

สร้างไฟล์ basic.flow

nodes:
  - name: jobA
    type: command
    config:
      command: echo "This is an echoed text."

ตัวอย่าง Flow แบบมี Dependencies

แก้ไขไฟล์ basic.flow

nodes:
  - name: jobC
    type: noop
    # jobC depends on jobA and jobB
    dependsOn:
      - jobA
      - jobB

  - name: jobA
    type: command
    config:
      command: echo "This is an echoed text."

  - name: jobB
    type: command
    config:
      command: pwd

type: noop คือ A job that takes no parameters and is essentially a null operation. Used for organizing your graph. (Azkaban 3.0 Documentation #builtin-jobtypes)

ตัวอย่าง Flow แบบมี Dependencies เป็น flow

nodes:
  - name: jobC
    type: noop
    dependsOn:
      - embedded_flow

  - name: embedded_flow
    type: flow
    config:
      flow.num.job.threads: 3
    nodes:
      - name: job01
        type: command
        config:
          command: sleep 10

      - name: job02
        type: command
        config:
          command: sleep 10

      - name: job03
        type: command
        config:
          command: sleep 10

      - name: job04
        type: command
        config:
          command: sleep 10

      - name: job05
        type: command
        config:
          command: sleep 10

      - name: job06
        type: command
        config:
          command: sleep 10

กำหนดจำนวน thread ที่ flow.num.job.threads

การสั่งให้ job รันมากกว่า 1 คำสั่ง

ถ้าใส่มากกว่า 1 คำสั่งเข้าไปตรงๆ จะ error เช่น

command: cd /home/jack/; ./run_some_job

ให้ปรับเป็นใส่คำสั่งเรียก shell script แทน เช่น

command: /home/jack/run_some_shell.sh

แล้วใส่คำสั่งใน run_some_shell.sh แทน

cd /home/jack/
./run_some_job

ติดตั้ง Hadoop 3.2.3 in Stand-Alone Mode บน Ubuntu 18.04

ทดสอบบน Ubuntu 18.04.5

อัพเดทแพกเกจ

sudo apt update

ติดตั้ง Java

sudo apt install openjdk-8-jdk
$ java -version
openjdk version "1.8.0_312"
OpenJDK Runtime Environment (build 1.8.0_312-8u312-b07-0ubuntu1~18.04-b07)
OpenJDK 64-Bit Server VM (build 25.312-b07, mixed mode)

ติดตั้ง Hadoop

ไปที่ Apache Hadoop แล้วคลิกเลือกที่ binary

เวอร์ชัน 3.2.3

ดาว์นโหลดด้วย wget

$ wget https://dlcdn.apache.org/hadoop/common/hadoop-3.2.3/hadoop-3.2.3.tar.gz
$ tar -zxvf hadoop-3.2.3.tar.gz
sudo mv hadoop-3.2.3 /usr/local/hadoop

อัพเดทค่า JAVA_HOME ในไฟล์ hadoop-env.sh

sudo nano /usr/local/hadoop/etc/hadoop/hadoop-env.sh
#export JAVA_HOME=${JAVA_HOME}
export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")

ดูเวอร์ชันของ Hadoop

$ /usr/local/hadoop/bin/hadoop version
Hadoop 3.2.3
Source code repository https://github.com/apache/hadoop -r abe5358143720085498613d399be3bbf01e0f131
Compiled by ubuntu on 2022-03-20T01:18Z
Compiled with protoc 2.5.0
From source with checksum 39bb14faec14b3aa25388a6d7c345fe8
This command was run using /usr/local/hadoop/share/hadoop/common/hadoop-common-3.2.3.jar

ตั้งค่า HADOOP_HOME

$ nano .bashrc

เพิ่ม export HADOOP_HOME=/usr/local/hadoop ไว้ท้ายสุดของไฟล์

$ source .bashrc

ตรวจสอบ

$ echo $HADOOP_HOME
/usr/local/hadoop

คอนฟิก SSH ต่อ GitHub บน Ubuntu 18.04

สร้าง ssh key

ssh-keygen

จะได้ output อยู่ที่ /home/jack/.ssh/

  • Private key – in /home/jack/.ssh/id_rsa
  • Public key – in /home/jack/.ssh/id_rsa.pub

GitHub configuration

ไปที่ https://github.com/settings/keys

เลือกปุ่ม “New SSH key”

แล้วใส่ Key โดยนำค่ามาจาก เสร็จแล้วกด  “Add SSH Key”

cat /home/jack/.ssh/id_rsa.pub

Clone the repository using SSH

git clone git@github.com:phaisarnsut/WebAppCore.git

Ubuntu 18.04 ใน VirtualBox

ติดตั้ง Ubuntu 18.04 ใน VirtualBox แล้วลง Guest Addition แต่พอ reboot แล้วปรับขนาดหน้าจอไม่ได้ และขึ้น Error ว่า

VBoxClient the VirtualBox kernel service is not running. 

ลองดู /var/log/vboxadd-setup.log เจอว่า

modprobe vboxguest failed

ให้แก้ไขด้วยคำสั่ง

sudo apt-get install dkms build-essential linux-headers-$(uname -r)

restart แล้วก็น่าจะใช้ได้ปกติละ

ติดตั้ง 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

ติดตั้ง 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

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

vsftpd – FTP Server Installation
vsftpd is an FTP daemon available in Ubuntu.

$ sudo apt install vsftpd

Anonymous FTP Configuration
By default vsftpd is not configured to allow anonymous download. If you wish to enable anonymous download edit /etc/vsftpd.conf by changing:

anonymous_enable=Yes

During installation a ftp user is created with a home directory of /srv/ftp. This is the default FTP directory.

If you wish to change this location, to /srv/files/ftp for example, simply create a directory in another location and change the ftp user’s home directory:

sudo mkdir /srv/files/ftp
sudo usermod -d /srv/files/ftp ftp

After making the change restart vsftpd:

sudo systemctl restart vsftpd.service

Finally, copy any files and directories you would like to make available through anonymous FTP to /srv/files/ftp, or /srv/ftp if you wish to use the default.

กำหนดให้สามารถ upload ไฟล์เข้ามาได้

แก้ไขไฟล์ /etc/vsftpd.conf

write_enable=YES

เสร็จแล้ว restart vsftpd:

sudo systemctl restart vsftpd.service

Link

ติดตั้ง Git

  1. ติดตั้ง Git
  2. Getting a Git Repository
  3. Recording Changes to the Repository
  4. Branch
    • Delete branch
    • Rename branch
  5. Tag
  6. Fix

1. ติดตั้ง Git

Install Git with Yum

sudo yum install git

Install Git with apt

sudo apt install git

ตรวจสอบการติดตั้ง

git --version

Set Up Git

Name and email address

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

Git can handle this by auto-converting CRLF line endings into LF when you add a file to the index, and vice versa when it checks out code onto your filesystem. You can turn on this functionality with the core.autocrlf setting. If you’re on a Windows machine, set it to true — this converts LF endings into CRLF when you check out code:

Formatting

git config --global core.autocrlf true

If you’re on a Linux or macOS system that uses LF line endings, then you don’t want Git to automatically convert them when you check out files; however, if a file with CRLF endings accidentally gets introduced, then you may want Git to fix it. You can tell Git to convert CRLF to LF on commit but not the other way around by setting core.autocrlf to input:

git config --global core.autocrlf input

Your default branch name

By default Git will create a branch called master when you create a new repository with git init. From Git version 2.28 onwards, you can set a different name for the initial branch.

git config --global init.defaultBranch main

Ignorecase

git config --global core.ignorecase false

Checking Your Settings

ค่าที่แสดงออกมา มีทั้งค่า global และ user

git config --list

You can view all of your settings and where they are coming from using:

ดูว่า config อะไรมาจากไฟล์ไหนใช้ --show-origin

git config --list --show-origin

Git config file locations

2. Getting a Git Repository

Initializing a Repository in an Existing Directory

cd /home/user/my_project
git init
git add *.c
git add LICENSE
git commit -m 'Initial project version'

หรือ add ทุกไฟล์ใน directory ด้วย

git add .

แต่ถ้าจะลบไฟล์ก็ git rm (ลบไฟล์พร้อมกับ stage ให้ด้วย)

git rm <filename>

แต่ถ้าจะ discard (Undoing Uncommitted Changes) – Git Undo Commit: How to Undo Changes in Git (cloudbees.com)

$ git stash

Cloning an Existing Repository

You clone a repository with git clone <url>. For example, if you want to clone the Git linkable library called libgit2, you can do so like this:

git clone https://github.com/libgit2/libgit2

If you want to clone the repository into a directory named something other than libgit2, you can specify the new directory name as an additional argument:

git clone https://github.com/libgit2/libgit2 mylibgit

ถ้า clone แล้วได้ error

fatal: unable to access 'https://gitxxx.com/jack/jack.git/': Peer's Certificate issuer is not recognized.

ให้แก้ไขโดยการ ignore CA – git – what does this error message imply: fatal: unable to access ‘https:URL’: Peer’s Certificate issuer is not recognized? – Stack Overflow

env GIT_SSL_NO_VERIFY=true git clone https://github...

หรือ set http.sslverify ให้เป็น false เลย

$ git config --global http.sslverify false

3. Recording Changes to the Repository

Checking the Status of Your Files

git status

ถ้าจะให้แสดง diff (staged) ด้วยก็

git status -v

หรือถ้าจะดูสรุปสั้นๆก็

git status -s
$ echo 'My Project' > README
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
  (use "git add <file>..." to include in what will be committed)

    README

nothing added to commit but untracked files present (use "git add" to track)

Tracking New Files

git add README
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)

    new file:   README

Ignoring Files

$ cat .gitignore
*.[oa]
*~

Viewing Your Staged and Unstaged Changes

To see what you’ve changed but not yet staged, type git diff with no other arguments:

git diff

If you want to see what you’ve staged that will go into your next commit, you can use git diff --staged or git diff --cached.

git diff --staged

หรือ

git status -v

Committing Your Changes

git commit -m "Story 182: fix benchmarks for speed"

ดูประวัติการ commit

git log
git log --oneline
git log --oneline --graph

การ reset (ย้อนกลับ) โดย default จะเป็นแบบ mixed

git reset <เลข commit ที่ได้จาก git log>

ดูประวัติ commit (รวมที่ reset ไปแล้วด้วย)

git reflog

ถ้าอยากย้อนกลับไป commit ที่เคย reset หายไปแล้ว ก็ทำได้ด้วย

git reset <เลข commit ที่ได้จาก git reflog>

git push

git push origin main

git pull

git pull

git fetch

git fetch

4. Branch

Create Branch

git branch <branch_name>

Remove Branch (Local)

git branch -d <branch_name>

Switch Branch

git checkout <branch_name>

Create and Switch Branch

git checkout -b <branch_name> <commit_id (optional)>

List branch

git branch

Git Merge

git merge <branch_name>
git merge <branch_name> --no-ff # merge commit

Delete branch

git branch --delete <branch_name>

ถ้าเป็น branch ที่ยังไม่ได้ fully merged จะ error: The branch ‘<branch_name>‘ is not fully merged.
If you are sure you want to delete it, run ‘git branch -D <branch_name>‘.

git branch -D <branch_name>

Rename branch

There are a few ways to accomplish that:

  1. Change your local branch and then push your changes
  2. Push the branch to remote with the new name while keeping the original name locally

Renaming local and remote

# Rename the local branch to the new name
git branch -m <old_name> <new_name>

# Delete the old branch on remote - where <remote> is, for example, origin
git push <remote> --delete <old_name>

# Or shorter way to delete remote branch [:]
git push <remote> :<old_name>

# Prevent git from using the old name when pushing in the next step.
# Otherwise, git will use the old upstream name instead of <new_name>.
git branch --unset-upstream <new_name>

# Push the new branch to remote
git push <remote> <new_name>

# Reset the upstream branch for the new_name local branch
git push <remote> -u <new_name>

ลองเปลี่ยนชื่อ branch จาก develop เป็น dev

> git branch -m develop dev

> git push origin --delete develop

> git branch --unset-upstream dev

> git push origin dev
> git push origin -u dev

Renaming Only remote branch

# In this option, we will push the branch to the remote with the new name
# While keeping the local name as is
git push <remote> <remote>/<old_name>:refs/heads/<new_name> :<old_name>

5. Tag

Listing Your Tags

Listing the existing tags in Git is straightforward. Just type git tag (with optional -l or --list):

$ git tag
v1.0
v2.0

This command lists the tags in alphabetical order; the order in which they are displayed has no real importance.

You can also search for tags that match a particular pattern. The Git source repo, for instance, contains more than 500 tags. If you’re interested only in looking at the 1.8.5 series, you can run this:

$ git tag -l "v1.8.5*"
v1.8.5
v1.8.5-rc0
v1.8.5-rc1
v1.8.5-rc2
v1.8.5-rc3
v1.8.5.1
v1.8.5.2
v1.8.5.3
v1.8.5.4
v1.8.5.5

Creating Tags

Git supports two types of tags: lightweight and annotated.

A lightweight tag is very much like a branch that doesn’t change — it’s just a pointer to a specific commit.

Annotated tags, however, are stored as full objects in the Git database. They’re checksummed; contain the tagger name, email, and date; have a tagging message; and can be signed and verified with GNU Privacy Guard (GPG). It’s generally recommended that you create annotated tags so you can have all this information; but if you want a temporary tag or for some reason don’t want to keep the other information, lightweight tags are available too.

Annotated Tags

Creating an annotated tag in Git is simple. The easiest way is to specify -a when you run the tag command:

$ git tag -a v1.4 -m "my version 1.4"
$ git tag
v0.1
v1.3
v1.4

You can see the tag data along with the commit that was tagged by using the git show command:

$ git show v1.4
tag v1.4
Tagger: Ben Straub <ben@straub.cc>
Date:   Sat May 3 20:19:12 2014 -0700

my version 1.4

commit ca82a6dff817ec66f44342007202690a93763949
Author: Scott Chacon <schacon@gee-mail.com>
Date:   Mon Mar 17 21:52:11 2008 -0700

    Change version number

Push a tag to a remote repository

To push a single tag:

git push origin <tag_name>

And the following command should push all tags (not recommended):

# not recommended
git push --tags

6. Fix

ยังไม่ได้เชื่อมต่อด้วย SSH

ดูที่ Generate an SSH key pair

SSL certificate problem: unable to get local issuer certificate

Resolution #1 – Self Signed certificate

Tell git to not perform the validation of the certificate using the global option:

git config --global http.sslVerify false

You must use a personal access token with ‘read_repository’ or ‘write_repository’ scope for Git over HTTP.

วิธีแก้

สร้าง personal access token ที่มีสิทธิ read_repository or write_repository เป็นอย่างน้อย

สั่งรัน git clone ใหม่ แล้วจะมีไดอะล็อก ให้ใส่ username, password ก็ใส่ตามนี้

username: login
password: <credential ที่ได้จากตอนสร้าง personal access token>

แต่ถ้าไม่มีไดอะล็อก ให้ลองไปลบ ของเดิมที่ Credential Manager

ถ้ารันคำสั่ง git เช่น git fetch แล้วถาม password ทุกครั้ง ให้ set ตามนี้เพื่อจำ password (Make Git store the username and password and it will never ask for them.) – How to fix Git always asking for user credentials (freecodecamp.org)

git config --global credential.helper store

คำสั่งพื้นฐาน Ubuntu 18.04

โปรแกรมน่าติดตั้ง

sudo apt update 
sudo apt install git
sudo apt install curl
sudo apt install tree
sudo apt install build-essential

Uninstall

sudo apt-get remove --auto-remove libcurl4-openssl-dev

ติดตั้ง Java

sudo apt install openjdk-8-jdk
$ java -version
openjdk version "1.8.0_312"
OpenJDK Runtime Environment (build 1.8.0_312-8u312-b07-0ubuntu1~18.04-b07)
OpenJDK 64-Bit Server VM (build 25.312-b07, mixed mode)

ถ้าติดตั้ง Java ไว้หลายตัว แล้วต้องการตั้ง default ใช้คำสั่ง

sudo update-alternatives --config java

ตรวจสอบพาท

$ readlink -f /usr/bin/java | sed "s:bin/java::"
/usr/lib/jvm/java-8-openjdk-amd64/jre/

Python จะติดมาอยู่แล้ว (18.04.5)

$ python3 --version
Python 3.6.9

เปิด Terminal กด Ctrl-Alt-T

ดู hostname

hostnamectl

ดู current directory (print working directory)

pwd

get back to home directory:

cd

whoami command will remind you of your username

whoami

ls (list) command:

ls
ls -l
ls -a

Creating folders

mkdir /tmp/tutorial
mkdir dir1 dir2 dir3
$ mkdir --help
Usage: mkdir [OPTION]... DIRECTORY...
Create the DIRECTORY(ies), if they do not already exist.

Mandatory arguments to long options are mandatory for short options too.
  -m, --mode=MODE   set file mode (as in chmod), not a=rwx - umask
  -p, --parents     no error if existing, make parent directories as needed
  -v, --verbose     print a message for each created directory
  -Z                   set SELinux security context of each created directory
                         to the default type
      --context[=CTX]  like -Z, or if CTX is specified then set the SELinux
                         or SMACK security context to CTX
      --help     display this help and exit
      --version  output version information and exit

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
Full documentation at: <http://www.gnu.org/software/coreutils/mkdir>
or available locally via: info '(coreutils) mkdir invocation'
mkdir -p -v dir4/dir5/dir6

Creating files using redirection

ls > output1.txt
cat output1.txt

echo "This is a test1" > output2.txt
echo "This is a test2" >> output2.txt

cat output1.txt output2.txt
cat t* > combined.txt

When viewing a file through less you can use the Up Arrow, Down Arrow, Page Up, Page Down, Home and End keys to move through your file

less combined.txt

Moving and manipulating files

mv combined.txt dir1
mv dir1/* .

The mv command also lets us move more than one file at a time. If you pass more than two arguments, the last one is taken to be the destination directory and the others are considered to be files (or directories) to move.

mv combined.txt test_* dir3 dir2
cp dir4/dir5/dir6/combined.txt .
rmdir folder_*
rm -r folder_6

Word count

wc -l combined.txt
$ wc --help
Usage: wc [OPTION]... [FILE]...
  or:  wc [OPTION]... --files0-from=F
Print newline, word, and byte counts for each FILE, and a total line if
more than one FILE is specified.  A word is a non-zero-length sequence of
characters delimited by white space.

With no FILE, or when FILE is -, read standard input.

The options below may be used to select which counts are printed, always in
the following order: newline, word, character, byte, maximum line length.
  -c, --bytes            print the byte counts
  -m, --chars            print the character counts
  -l, --lines            print the newline counts
      --files0-from=F    read input from the files specified by
                           NUL-terminated names in file F;
                           If F is - then read names from standard input
  -L, --max-line-length  print the maximum display width
  -w, --words            print the word counts
      --help     display this help and exit
      --version  output version information and exit

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
Full documentation at: <http://www.gnu.org/software/coreutils/wc>
or available locally via: info '(coreutils) wc invocation'
ls ~ | wc -l
ls /etc | less
cat combined.txt | uniq | wc -l
man uniq | less
sort combined.txt | less
sort combined.txt | uniq | wc -l

tree

sudo apt install tree
$ tree /home/
/home/
└── jack
    ├── Desktop
    ├── Documents
    ├── Downloads
    ├── Music
    ├── Pictures
    ├── Public
    ├── Templates
    └── Videos

9 directories, 0 files
tree
tree -a

ติดตั้ง phpMyAdmin ให้ Nginx บน Ubuntu 18.04

1.Installing phpMyAdmin

$ sudo apt update
$ sudo apt install phpmyadmin

During the installation process, you will be prompted to choose the web server (either Apache or Lighttpd) to configure. Because we are using Nginx as a web server, we shouldn’t make a choice here. Press tab and then OK to advance to the next step.

Next, you’ll be prompted whether to use dbconfig-common for configuring the application database. Select Yes. This will set up the internal database and administrative user for phpMyAdmin. You will be asked to define a new password for the phpmyadmin MySQL user. You can also leave it blank and let phpMyAdmin randomly create a password.

ถ้าจะ recofig ก็

sudo dpkg-reconfigure phpmyadmin

สร้าง link

$ sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin
https://server_domain_or_IP/phpmyadmin

แต่น่าจะติด 403 Forbidden

ให้ เพิ่ม index.php ในไฟล์ /etc/nginx/sites-available/example.com

$ sudo nano /etc/nginx/sites-available/example.com
server {
        listen 80;
        root /var/www/html;
        index index.php index.html index.htm index.nginx-debian.html index.php;
        server_name example.com;

        location / {
                try_files $uri $uri/ =404;
        }

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        }

        location ~ /\.ht {
                deny all;
        }
}

ทีนี้จะเข้าได้ละ