MathJax

MathJax-2

MathJax-3

Google Code Prettify

置頂入手筆記

EnterproseDB Quickstart — 快速入門筆記

由於考慮採用 EnterpriseDB 或是直接用 PostgreSQL 的人,通常需要一些入手的資料。這邊紀錄便提供相關快速上手的簡單筆記 ~ 這篇筆記以 資料庫安裝完畢後的快速使用 為目標,基本紀錄登入使用的範例:

2018年5月15日 星期二

在 Slackware 14.2 裡面下載 LXC Image

類似 Docker 但不同設計目的的 LXC,也有一個小小的 Image Repository,以及相對應的工具叫做 LXD,也可以提供使用者拉一些其他 Linix DIstribution 的 Container。這裡便簡單的紀錄一下在 Slackware 裡面的 LXC 拉取映像檔的方式。

一般來說,雖然 LXC 有提供 template,但是在不同的 Distribution 執行總會遇到 Package Manager 不支援的問題。此時便可以利用像 docker 一樣拉現成的 Container Image。

但是,在 Slackware 裡面沒有 lxc 這個大指令,也沒有具體提供 LXD 這個管理工具,取而代之的是 lxc-create、lxc-start 等等個別指令。這和目前資料到的其他 Distribution(如 Ubuntu)不太一樣。

然而,在 Slackware 裡面,還是可以拉取 LXC Image 的~

目前這裡用的是 Current Channel,紀錄時的版本是最新的 2.0.9
bash-4.4$ lxc-create --version
2.0.9
bash-4.4$ 

拉取 LXC Container 的 Image,使用的是 lxc-create 這個指令,進行互動式的 Image 安裝:這裡我以拉取一個 Alpine Linux Container 為例直接產生一個叫做 alpine37 的 LXC Xontainer(紅色部份為互動問答部份):
bash-4.4$ su
Password: 
bash-4.4# lxc-create -t download -n alpine37 -- --server images.linuxcontainers.org
Setting up the GPG keyring
Downloading the image index

---
DIST    RELEASE ARCH    VARIANT BUILD
---
alpine  3.4     amd64   default 20180514_17:50
alpine  3.4     armhf   default 20180514_17:50
alpine  3.4     i386    default 20180514_17:50
alpine  3.5     amd64   default 20180514_17:50
alpine  3.5     armhf   default 20180514_17:50
alpine  3.5     i386    default 20180514_17:50
alpine  3.6     amd64   default 20180514_17:50
alpine  3.6     armhf   default 20180515_04:17
alpine  3.6     i386    default 20180514_17:50
alpine  3.7     amd64   default 20180514_17:50
alpine  3.7     armhf   default 20180515_04:17
alpine  3.7     i386    default 20180514_17:50
alpine  edge    amd64   default 20180514_17:50
alpine  edge    armhf   default 20180515_04:17
alpine  edge    i386    default 20180514_17:50
archlinux       current amd64   default 20180515_01:27
centos  6       amd64   default 20180515_02:16
centos  6       i386    default 20180515_02:16
centos  7       amd64   default 20180515_02:16
debian  buster  amd64   default 20180514_05:25
debian  buster  arm64   default 20180515_05:25
debian  buster  armel   default 20180514_17:01
debian  buster  armhf   default 20180514_14:38
debian  buster  i386    default 20180515_05:25
debian  buster  ppc64el default 20180515_05:29
debian  buster  s390x   default 20180515_05:37
debian  jessie  amd64   default 20180515_05:25
debian  jessie  arm64   default 20180515_05:25
debian  jessie  armel   default 20180515_05:30
debian  jessie  armhf   default 20180514_16:16
debian  jessie  i386    default 20180514_05:26
debian  jessie  powerpc default 20180515_05:26
debian  jessie  ppc64el default 20180515_05:29
debian  jessie  s390x   default 20180515_05:51
debian  sid     amd64   default 20180515_05:25
debian  sid     arm64   default 20180515_05:25
debian  sid     armel   default 20180514_14:38
debian  sid     armhf   default 20180515_05:30
debian  sid     i386    default 20180515_05:25
debian  sid     powerpc default 20180515_05:25
debian  sid     ppc64el default 20180515_05:29
debian  sid     s390x   default 20180515_05:38
debian  stretch amd64   default 20180514_05:25
debian  stretch arm64   default 20180515_05:32
debian  stretch armel   default 20180514_16:52
debian  stretch armhf   default 20180515_05:30
debian  stretch i386    default 20180515_05:25
debian  stretch ppc64el default 20180515_05:29
debian  stretch s390x   default 20180515_05:25
debian  wheezy  amd64   default 20180515_05:25
debian  wheezy  armel   default 20180514_16:16
debian  wheezy  armhf   default 20180514_14:38
debian  wheezy  i386    default 20180515_05:25
debian  wheezy  powerpc default 20180515_05:26
debian  wheezy  s390x   default 20180515_05:25
fedora  26      amd64   default 20180515_01:27
fedora  26      i386    default 20180515_01:27
fedora  27      amd64   default 20180515_01:27
fedora  27      i386    default 20180515_01:27
gentoo  current amd64   default 20180514_14:12
gentoo  current i386    default 20180514_14:12
opensuse        42.3    amd64   default 20180515_00:53
oracle  6       amd64   default 20180514_11:40
oracle  6       i386    default 20180514_11:40
oracle  7       amd64   default 20180514_11:40
plamo   5.x     amd64   default 20180514_21:36
plamo   5.x     i386    default 20180514_21:36
plamo   6.x     amd64   default 20180514_21:36
plamo   6.x     i386    default 20180514_21:36
ubuntu  artful  amd64   default 20180515_07:43
ubuntu  artful  arm64   default 20180515_07:43
ubuntu  artful  armhf   default 20180514_15:25
ubuntu  artful  i386    default 20180515_07:43
ubuntu  artful  ppc64el default 20180515_07:48
ubuntu  artful  s390x   default 20180515_07:57
ubuntu  bionic  amd64   default 20180515_07:43
ubuntu  bionic  arm64   default 20180515_07:43
ubuntu  bionic  armhf   default 20180514_16:14
ubuntu  bionic  i386    default 20180515_07:43
ubuntu  bionic  ppc64el default 20180515_07:48
ubuntu  bionic  s390x   default 20180515_07:43
ubuntu  trusty  amd64   default 20180515_07:43
ubuntu  trusty  arm64   default 20180515_07:50
ubuntu  trusty  armhf   default 20180514_15:14
ubuntu  trusty  i386    default 20180515_07:43
ubuntu  trusty  powerpc default 20180515_07:43
ubuntu  trusty  ppc64el default 20180515_07:48
ubuntu  xenial  amd64   default 20180515_07:43
ubuntu  xenial  arm64   default 20180515_07:43
ubuntu  xenial  armhf   default 20180514_15:26
ubuntu  xenial  i386    default 20180515_07:43
ubuntu  xenial  powerpc default 20180515_07:43
ubuntu  xenial  ppc64el default 20180515_07:47
ubuntu  xenial  s390x   default 20180515_07:43
---

Distribution: alpine
Release: 3.7
Architecture: amd64

Downloading the image index
Downloading the rootfs
Downloading the metadata
The image cache is now ready
Unpacking the rootfs

---
You just created an Alpine Linux container (release=v3.7, arch=amd64, variant=default)

For security reason, container images ship without user accounts
and without a root password.

Use lxc-attach or chroot directly into the rootfs to set a root password
or create user accounts.
bash-4.4# 

這樣便完成了。可以檢查一下 Container 清單
bash-4.4# lxc-ls
alpine37 
bash-4.4# 

參照上次筆記,設定一個網路:這裡需要 Slackware 上面的 DHCP 服務來配發 IP,才可以通外面。
Host 部份有 Slackware 本身的 Network Bridge & IP Forwarding 設定,跟 Container 在外面的 Config。其中 Container Config 填寫的 IP 跟 Gateway 要跟 br0 界面產生的內容(IP Range 跟 route 指令呈現的 Gateway)相關才行
bash-4.4# cat << BRCNFEOF >> /etc/rc.d/rc.inet1.conf
# 
# Configure Network Bridging for Linux Container, *mylxc*

IFNAME[0]="br0"
BRNICS[0]="eth0"
IPADDR[0]=""
NETMASK[0]=""
USE_DHCP[0]="yes"
DHCP_HOSTNAME[0]=""
BRCNFEOF
bash-4.4# /etc/rc.d/rc.inet1 restart
RTNETLINK answers: File exists
Polling for DHCP server on interface br0:
DUID 00:01:00:01:21:b9:5d:91:08:00:27:ef:3d:1d
br0: IAID 27:ef:3d:1d
br0: adding address fe80::fa1e:ac2f:860c:2828
br0: soliciting an IPv6 router
br0: rebinding lease of 10.0.2.15
br0: carrier lost
br0: deleting address fe80::fa1e:ac2f:860c:2828
br0: carrier acquired
br0: IAID 27:ef:3d:1d
br0: adding address fe80::fa1e:ac2f:860c:2828
br0: soliciting an IPv6 router
br0: rebinding lease of 10.0.2.15
br0: probing address 10.0.2.15/24
br0: leased 10.0.2.15 for 86400 seconds
br0: adding route to 10.0.2.0/24
br0: adding default route via 10.0.2.2
forked to background, child pid 3492
bash-4.4# 
bash-4.4# ifconfig 
br0: flags=4163  mtu 1500
        inet 10.0.2.15  netmask 255.255.255.0  broadcast 10.0.2.255
        inet6 fe80::fa1e:ac2f:860c:2828  prefixlen 64  scopeid 0x20
        ether 08:00:27:ef:3d:1d  txqueuelen 1000  (Ethernet)
        RX packets 1  bytes 576 (576.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 18  bytes 1733 (1.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

docker0: flags=4099  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 0.0.0.0
        ether 02:42:74:81:ce:50  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=4163  mtu 1500
        ether 08:00:27:ef:3d:1d  txqueuelen 1000  (Ethernet)
        RX packets 11  bytes 5430 (5.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 189  bytes 22359 (21.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 16  bytes 1056 (1.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 16  bytes 1056 (1.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

bash-4.4# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.0.2.2        0.0.0.0         UG    203    0        0 br0
10.0.2.0        0.0.0.0         255.255.255.0   U     203    0        0 br0
10.0.2.0        0.0.0.0         255.255.255.0   U     425    0        0 br0
127.0.0.0       0.0.0.0         255.0.0.0       U     0      0        0 lo
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0
172.17.0.0      0.0.0.0         255.255.0.0     U     425    0        0 docker0
bash-4.4# 
bash-4.4# 
bash-4.4#  chmod +x /etc/rc.d/rc.ip_forward
bash-4.4# /etc/rc.d/rc.ip_forward start
Activating IPv4 packet forwarding.
Activating IPv6 packet forwarding.
bash-4.4# iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
bash-4.4# iptables-save > /etc/iptables.rules
bash-4.4# 
bash-4.4# sed '/lxc.network.type = empty/d' -i /var/lib/lxc/alpine37/config
bash-4.4# cat << EOF >> /var/lib/lxc/alpine37/config 
lxc.network.type=veth
lxc.network.link=br0
lxc.network.flags=up
lxc.network.ipv4 = 10.0.2.10/24
lxc.network.ipv4.gateway = 10.0.2.2
EOF
bash-4.4# 

接著啟動他,並進行 Container 內部有關的網路設定
bash-4.4# lxc-start --name alpine37
bash-4.4# 
bash-4.4# lxc-console --name alpine37

Connected to tty 1
                  Type  to exit the console,  to enter Ctrl+a itself

Welcome to Alpine Linux 3.7
Kernel 4.14.1 on an x86_64 (/dev/tty1)

alpine37 login: root
Welcome to Alpine!

The Alpine Wiki contains a large amount of how-to guides and general
information about administrating Alpine systems.
See .

You can setup the system with the command: setup-alpine

You may change this message by editing /etc/motd.

alpine37:~# 
alpine37:~# setup-interfaces 
Available interfaces are: eth0.
Enter '?' for help on bridges, bonding and vlans.
Which one do you want to initialize? (or '?' or 'done') [eth0] 
Ip address for eth0? (or 'dhcp', 'none', '?') [dhcp] 10.0.2.10 
Netmask? [255.0.0.0] 255.255.255.0
Gateway? (or 'none') [none] 10.0.2.1 
Configuration for eth0:
  type=static
  address=10.0.2.10
  netmask=255.255.255.0
  gateway=10.0.2.1
Do you want to do any manual network configuration? [no] 
alpine37:~# 
alpine37:~# /etc/init.d/networking restart
 * Stopping networking ... *   eth0 ... [ ok ]
 * Starting networking ... *   eth0 ... [ ok ]
alpine37:~# 
alpine37:~# ifconfig 
eth0      Link encap:Ethernet  HWaddr FE:C7:F6:7D:D7:3A  
          inet addr:10.0.2.10  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::fcc7:f6ff:fe7d:d73a/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:7 errors:0 dropped:0 overruns:0 frame:0
          TX packets:7 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:746 (746.0 B)  TX bytes:586 (586.0 B)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

alpine37:~# 
alpine37:~# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.0.2.2        0.0.0.0         UG    0      0        0 eth0
10.0.2.0        0.0.0.0         255.255.255.0   U     0      0        0 eth0
alpine37:~# 
alpine37:~# 
alpine37:~# ping 10.0.2.15
PING 10.0.2.15 (10.0.2.15): 56 data bytes
64 bytes from 10.0.2.15: seq=0 ttl=64 time=0.282 ms
64 bytes from 10.0.2.15: seq=1 ttl=64 time=0.102 ms
^C
--- 10.0.2.15 ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 0.102/0.192/0.282 ms
alpine37:~# 
alpine37:~# 
alpine37:~# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: seq=1 ttl=58 time=3.529 ms
64 bytes from 8.8.8.8: seq=2 ttl=58 time=3.452 ms
^C
--- 8.8.8.8 ping statistics ---
3 packets transmitted, 2 packets received, 33% packet loss
round-trip min/avg/max = 3.452/3.490/3.529 ms
alpine37:~# 
alpine37:~# cat << EOF >> /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4
EOF
alpine37:~# 
alpine37:~# ping ftp.yzu.edu.tw
PING ftp.yzu.edu.tw (140.138.144.170): 56 data bytes
64 bytes from 140.138.144.170: seq=0 ttl=53 time=4.172 ms
64 bytes from 140.138.144.170: seq=1 ttl=53 time=9.787 ms
^C
--- ftp.yzu.edu.tw ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 4.172/6.979/9.787 ms
alpine37:~# 

然後讓我們更新套件作最後收尾
alpine37:~# setup-apkrepos 

Available mirrors:
1) dl-cdn.alpinelinux.org
2) nl.alpinelinux.org
3) uk.alpinelinux.org
4) dl-2.alpinelinux.org
5) dl-3.alpinelinux.org
6) dl-4.alpinelinux.org
7) dl-5.alpinelinux.org
8) dl-8.alpinelinux.org
9) distrib-coffee.ipsl.jussieu.fr
10) mirror.yandex.ru
11) mirrors.gigenet.com
12) mirror1.hs-esslingen.de
13) liskamm.alpinelinux.uk
14) mirror.leaseweb.com
15) repository.fit.cvut.cz
16) alpine.mirror.far.fi
17) alpine.mirror.wearetriple.com
18) mirror.clarkson.edu
19) linorg.usp.br
20) ftp.yzu.edu.tw
21) mirror.aarnet.edu.au
22) mirror.csclub.uwaterloo.ca
23) ftp.acc.umu.se
24) ftp.halifax.rwth-aachen.de
25) speglar.siminn.is
26) mirrors.dotsrc.org
27) ftp.tsukuba.wide.ad.jp
28) mirror.rise.ph

r) Add random from the above list
f) Detect and add fastest mirror from above list
e) Edit "/"etc/apk/repositores with text editor

Enter mirror number (1-28) or URL to add (or r/f/e/done) [f]: 
Finding fastest mirror... 
  0.34 http://dl-cdn.alpinelinux.org/alpine/
  0.87 http://nl.alpinelinux.org/alpine/
  0.92 http://uk.alpinelinux.org/alpine/
  0.63 http://dl-2.alpinelinux.org/alpine/
  0.36 http://dl-3.alpinelinux.org/alpine/
  1.13 http://dl-4.alpinelinux.org/alpine/
  0.82 http://dl-5.alpinelinux.org/alpine/
  0.83 http://dl-8.alpinelinux.org/alpine/
wget: server returned error: HTTP/1.1 404 Not Found
  0.52 http://mirror.yandex.ru/mirrors/alpine/
  0.64 http://mirrors.gigenet.com/alpinelinux/
  0.68 http://mirror1.hs-esslingen.de/pub/Mirrors/alpine/
  1.69 http://liskamm.alpinelinux.uk/
  1.05 http://mirror.leaseweb.com/alpine/
  0.97 http://repository.fit.cvut.cz/mirrors/alpine/
  0.92 http://alpine.mirror.far.fi/
  0.80 http://alpine.mirror.wearetriple.com/
  0.47 http://mirror.clarkson.edu/alpine/
  0.76 http://linorg.usp.br/AlpineLinux/
  0.04 http://ftp.yzu.edu.tw/Linux/alpine/
  0.66 http://mirror.aarnet.edu.au/pub/alpine
  0.49 http://mirror.csclub.uwaterloo.ca/alpine
  1.22 http://ftp.acc.umu.se/mirror/alpinelinux.org
  0.66 http://ftp.halifax.rwth-aachen.de/alpine
  0.97 http://speglar.siminn.is/alpine
  0.64 http://mirrors.dotsrc.org/alpine
  0.24 http://ftp.tsukuba.wide.ad.jp/Linux/alpine
  0.50 http://mirror.rise.ph/alpine
Added mirror ftp.yzu.edu.tw
Updating repository indexes... done.
alpine37:~# 
alpine37:~# apk update
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/community/x86_64/APKINDEX.tar.gz
fetch http://ftp.yzu.edu.tw/Linux/alpine/v3.7/main/x86_64/APKINDEX.tar.gz
v3.7.0-165-g5692f7146c [http://dl-cdn.alpinelinux.org/alpine/v3.7/main]
v3.7.0-166-g9428b7ef60 [http://dl-cdn.alpinelinux.org/alpine/v3.7/community]
v3.7.0-165-g5692f7146c [http://ftp.yzu.edu.tw/Linux/alpine/v3.7/main]
OK: 9048 distinct packages available
alpine37:~# 

看來沒有套件要更新~
驗證到此結束。因此除了 Docker 之外,用 LXC 也可以設置不同 Linux Distribution 的測試環境了~


參考資料

網路部份的處理

沒有留言:

張貼留言