MathJax

MathJax-2

MathJax-3

Google Code Prettify

置頂入手筆記

EnterproseDB Quickstart — 快速入門筆記

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

2019年4月4日 星期四

CentOS 7.x 上面的 LXC 測試環境 (6) - 在 CentOS 7 Host 建立 CentOS 6 LXC Container

有時需要準備 CentOS 6 的環境,可以直接利用 LXC Container。
LXC 的進階專案 LXD 提供 Container Image Repository,可以直接抓需要的 Linux Distribution。
這份筆記紀錄在 LXC 產生 CentOS 6 Container 的方式。
Note] 由於 RHEL 6 會在 11/30/2020 EOL,不能確定到時是否 Repository 是否還會提供



這邊示範的方法,是透過既有的 LXC centos Template,直接指定 OS 版本,就可以下載。
[user@labenv-lxc ~]$ sudo lxc-create -n centos6 -t centos -- --help
Host CPE ID from /etc/os-release: cpe:/o:centos:centos:7
usage:
    /usr/share/lxc/templates/lxc-centos -n|--name=
        [-p|--path=] [-c|--clean] [-R|--release=] [-a|--arch=]
        [-h|--help]
Mandatory args:
  -n,--name         container name, used to as an identifier for that container from now on
Optional args:
  -p,--path         path to where the container rootfs will be created, defaults to /var/lib/lxc/name.
  -c,--clean        clean the cache
  -R,--release      CentOS release for the new container. If the host is CentOS, then it will default to the host's release.
     --fqdn         fully qualified domain name (FQDN) for DNS and system naming
     --repo         repository to use (url)
  -a,--arch         Define what arch the container will be [i686,x86_64]
  -h,--help         print this help
[user@labenv-lxc ~]$ sudo lxc-create -n centos_6 -t centos -- -R 6 
Host CPE ID from /etc/os-release: cpe:/o:centos:centos:7
Checking cache download in /var/cache/lxc/centos/x86_64/6/rootfs ... 
Downloading CentOS minimal ...
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: repos-va.psychz.net
 * updates: repos-va.psychz.net
base                                                                 | 3.7 kB  00:00:00     
updates                                                              | 3.4 kB  00:00:00     
(1/3): base/group_gz                                                 | 242 kB  00:00:00     
(2/3): base/primary_db                                               | 4.7 MB  00:00:00     
(3/3): updates/primary_db                                            | 3.0 MB  00:00:00     
Resolving Dependencies
--> Running transaction check
---> Package chkconfig.x86_64 0:1.3.49.5-1.el6 will be installed
--> Processing Dependency: rtld(GNU_HASH) for package: chkconfig-1.3.49.5-1.el6.x86_64
--> Processing Dependency: libpopt.so.0(LIBPOPT_0)(64bit) for package: chkconfig-1.3.49.5-1.el6.x86_64
 . . . 中間略 . . .
  xz-libs.x86_64 0:4.999.9-0.5.beta.20091007git.el6                                         
  yum-metadata-parser.x86_64 0:1.1.2-16.el6                                                 
  yum-plugin-fastestmirror.noarch 0:1.1.30-42.el6_10                                        
  zlib.x86_64 0:1.2.3-29.el6                                                                

Complete!
Download complete.
Copy /var/cache/lxc/centos/x86_64/6/rootfs to /var/lib/lxc/centos_6/rootfs ... 
Copying rootfs to /var/lib/lxc/centos_6/rootfs ...
Storing root password in '/var/lib/lxc/centos_6/tmp_root_pass'
Expiring password for user root.
passwd: Success

Container rootfs and config have been created.
Edit the config file to check/enable networking setup.

The temporary root password is stored in:

        '/var/lib/lxc/centos_6/tmp_root_pass'


The root password is set up as expired and will require it to be changed
at first login, which you should do as soon as possible.  If you lose the
root password or wish to change it without starting the container, you
can change it from the host by running the following command (which will
also reset the expired flag):

        chroot /var/lib/lxc/centos_6/rootfs passwd

[user@labenv-lxc ~]$ 

把必要的設定補上
[user@labenv-lxc ~]$ sudo tee -a /var/lib/lxc/centos_6/config << EOF 
# Manual Setting
lxc.network.ipv4 = 192.168.68.14/24
lxc.network.ipv4.gateway = 192.168.68.10
lxc.start.auto = 1
# Fix some portential journald high CPU consumption
#lxc.kmsg = 0
EOF
[user@labenv-lxc ~]$ sudo sh -c "echo 'nameserver 192.168.68.10' >> /var/lib/lxc/centos_6/rootfs/etc/resolv.conf"
[user@labenv-lxc ~]$ sudo chroot /var/lib/lxc/centos_6/rootfs passwd
Changing password for user root.
New password: root
BAD PASSWORD: it is too short
BAD PASSWORD: is too simple
Retype new password: root
passwd: all authentication tokens updated successfully.
[user@labenv-lxc ~]$ 
[user@labenv-lxc ~]$ sudo ./envlogin.sh centos_6

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


CentOS release 6.10 (Final)
Kernel 3.10.0-957.5.1.el7.x86_64 on an x86_64

centos_6 login: root
Password: root
[root@centos_6 ~]# 
[root@centos_6 ~]# ip a
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
18: eth0@if19:  mtu 1500 qdisc noqueue state UP qlen 1000
    link/ether fe:e8:b4:2f:95:c6 brd ff:ff:ff:ff:ff:ff
    inet 192.168.68.35/24 brd 192.168.68.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::fce8:b4ff:fe2f:95c6/64 scope link 
       valid_lft forever preferred_lft forever
[root@centos_6 ~]# 
[root@centos_6 ~]# ping www.google.com
PING www.google.com (173.194.197.105) 56(84) bytes of data.
64 bytes from iy-in-f105.1e100.net (173.194.197.105): icmp_seq=1 ttl=51 time=0.863 ms
64 bytes from iy-in-f105.1e100.net (173.194.197.105): icmp_seq=2 ttl=51 time=0.587 ms
^C
--- www.google.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1453ms
rtt min/avg/max/mdev = 0.587/0.725/0.863/0.138 ms
[root@centos_6 ~]# 

這樣就 OK 了~

若需要從 https://us.images.linuxcontainers.org/ 下載 Image,則換成使用 download Template 即可。可以參考之前在 Slackware 示範過的內容。

沒有留言:

張貼留言