顯示具有 Ubuntu 標籤的文章。 顯示所有文章
顯示具有 Ubuntu 標籤的文章。 顯示所有文章

2019年10月27日 星期日

Ubuntu 16.04/18.04 installation


Ubuntu 在安裝完成時會設DHCP 並自動取得 IP,可透過文字介面來手動設定固定IP。

1.修改 Ethernet 網路設定

root@management:~# vim /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).source /etc/network/interfaces.d/*# The loopback network interface
auto lo
iface lo inet loopback# The primary network interface
auto ens160
iface ens160 inet static # 固定 (靜態) IP
address 10.159.xx.xx # IP 位址
netmask 255.255.255.0 # 網路遮罩
gateway 10.159.xx.xx # 預設閘道
dns-nameservers 168.95.1.1 #DNS第一組
dns-nameservers 8.8.8.8 #DNS第二組


2. 修改完可使用以下指令重新啟動網路讀取網路設定
root@management:~# /etc/init.d/networking restart
[ ok ] Restarting networking (via systemctl): networking.service


Add User Ubuntu create user account commands
Let us say you need to add a new user in Ubuntu called vivek, type the following command in your shell:

$ sudo adduser John

Verify
$ cat /etc/passwd

Ubuntu 快速將使用者設成 Sudoer
max@ubuntu:~$ sudo adduser s01224566 sudo
Adding user `s01224566' to group `sudo' ...
Adding user s01224566 to group sudo
Done.

max@ubuntu:~$ sudo cat /etc/group | grep sudo
sudo:x:27:max,sena,gary,s01224566


Ubuntu 18.04 Configuring the network interface
Edit /etc/netplan/00-installer-config.yaml

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
     dhcp4: yes/no
     addresses:  [192.168.1.222/24]
     gateway4: 192.168.1.1
     nameservers:
       addresses: [8.8.8.8,8.8.4.4]


$sudo netplan apply

2018年3月8日 星期四

Configure apt-get behind proxy server for Ubuntu 14/15/16


$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04 LTS
Release:        16.04
Codename:       xenial


$ sudo vi /etc/apt/apt.conf

Acquire::http::Proxy "http://proxy_host:port";


To make this command permanent add it to ~/.bash.rc in your home directory:

vi ~/.bash.rc


Now Check and restart the updates:

root@ubuntu:~# apt-get  update
Hit:1 http://security.ubuntu.com/ubuntu xenial-security InRelease
Get:2 http://us.archive.ubuntu.com/ubuntu xenial InRelease [95.8 kB]
:::
Okay


To use wget behind proxy

sudo vi /etc/wgetrc

https_proxy  = http://username:password@proxy:port
http_proxy = http://username:password@proxy:port
http_proxy = http://Domain\username:password@proxy:port # (in case of LDAP)
ftp_proxy = http://username:password@proxy:port
Uncomment 'use_proxy = on'


Now  try to use  wget

root@ubuntu:~# wget http://repo.zabbix.com/zabbix/2.4/ubuntu/pool/main/z/zabbix-release/zabbix-release_2.4-1+trusty_all.deb
--2016-03-03 06:05:26--  http://repo.zabbix.com/zabbix/2.4/ubuntu/pool/main/z/zabbix-release/zabbix-release_2.4-1+trusty_all.deb
Connecting to 10.133.80.35:8080... connected.
Proxy request sent, awaiting response... 200 OK
Length: 2674 (2.6K) [application/x-debian-package]
Saving to: ‘zabbix-release_2.4-1+trusty_all.deb’

Okay

2017年12月4日 星期一

Create LXC Virtual Machine on AWS Ubuntu 16 Container



更新系統套件

ubuntu@ip-172-31-16-58:~$ sudo apt-get update
Hit:1 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu xenial InRelease
Get:2 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]
Get:3 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB]
Get:4 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu xenial/main Sources [868 kB]
Get:5 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu xenial/restricted Sources [4,808 B]
:::

Get:38 http://security.ubuntu.com/ubuntu xenial-security/multiverse Translation-en [1,336 B]
Fetched 24.5 MB in 4s (5,661 kB/s)
Reading package lists... Done

ubuntu@ip-172-31-16-58:~$ sudo apt-get upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages will be upgraded:
  curl dnsmasq-base dpkg klibc-utils libcurl3-gnutls libdb5.3 libklibc libpython3.5 libpython3.5-minimal
  libpython3.5-stdlib lxcfs python3.5 python3.5-minimal
13 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 9,338 kB of archives.
After this operation, 21.5 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y

安裝LXC core model

ubuntu@ip-172-31-16-58:~$ sudo apt-get install lxc
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  bridge-utils cloud-image-utils debootstrap distro-info genisoimage libaio1 libboost-iostreams1.58.0
  libboost-random1.58.0 libboost-system1.58.0 libboost-thread1.58.0 libiscsi2 libnspr4 libnss3 libnss3-nssdb
  libpam-cgfs librados2 librbd1 lxc-templates lxc1 python3-lxc qemu-block-extra qemu-utils sharutils
Suggested packages:
  cloud-utils-euca shunit2 wodim cdrkit-doc qemu-user-static lxctl bsd-mailx | mailx
The following NEW packages will be installed:
  bridge-utils cloud-image-utils debootstrap distro-info genisoimage libaio1 libboost-iostreams1.58.0
  libboost-random1.58.0 libboost-system1.58.0 libboost-thread1.58.0 libiscsi2 libnspr4 libnss3 libnss3-nssdb
  libpam-cgfs librados2 librbd1 lxc lxc-templates lxc1 python3-lxc qemu-block-extra qemu-utils sharutils
0 upgraded, 24 newly installed, 0 to remove and 0 not upgraded.
Need to get 6,843 kB of archives.
After this operation, 26.1 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y

Check LXC 虛擬主機範本有那些

ubuntu@ip-172-31-16-58:~$ ll /usr/share/lxc/templates
total 412
drwxr-xr-x 2 root root  4096 Dec  5 07:08 ./
drwxr-xr-x 6 root root  4096 Dec  5 07:08 ../
-rwxr-xr-x 1 root root 13042 Jun 14 20:15 lxc-alpine*
-rwxr-xr-x 1 root root 13737 Jun 14 20:15 lxc-altlinux*
-rwxr-xr-x 1 root root 11156 Jun 14 20:15 lxc-archlinux*
-rwxr-xr-x 1 root root 11649 Jun 14 20:15 lxc-busybox*
-rwxr-xr-x 1 root root 29725 Jun 14 20:15 lxc-centos*
-rwxr-xr-x 1 root root 10374 Jun 14 20:15 lxc-cirros*
-rwxr-xr-x 1 root root 20171 Jun 14 20:15 lxc-debian*
-rwxr-xr-x 1 root root 18197 Jun 14 20:15 lxc-download*
-rwxr-xr-x 1 root root 49693 Jun 14 20:15 lxc-fedora*
-rwxr-xr-x 1 root root 28259 Jun 14 20:15 lxc-gentoo*
-rwxr-xr-x 1 root root 13849 Jun 14 20:15 lxc-openmandriva*
-rwxr-xr-x 1 root root 15910 Jun 14 20:15 lxc-opensuse*
-rwxr-xr-x 1 root root 41596 Jun 14 20:15 lxc-oracle*
-rwxr-xr-x 1 root root 11463 Jun 14 20:15 lxc-plamo*
-rwxr-xr-x 1 root root 19096 Jun 14 20:15 lxc-slackware*
-rwxr-xr-x 1 root root 26667 Jun 14 20:15 lxc-sparclinux*
-rwxr-xr-x 1 root root  6822 Jun 14 20:15 lxc-sshd*
-rwxr-xr-x 1 root root 25703 Jun 14 20:15 lxc-ubuntu*
-rwxr-xr-x 1 root root 11734 Jun 14 20:15 lxc-ubuntu-cloud*

建立LXC Virtual Machine

ubuntu@ip-172-31-16-58:~$ sudo lxc-create -t ubuntu -n myBig1
:::
  en_US.UTF-8... done
Generation complete.
Creating SSH2 RSA key; this may take some time ...
2048 SHA256:KYqB7UzN+QbBtdS0+MrWd0ei6Tl3ho0TppBVoQz+uuw root@ip-172-31-16-58 (RSA)
Creating SSH2 DSA key; this may take some time ...
1024 SHA256:241q0S+tE2CVTJ1el8UiZ3rkqAw9YIxdUaMOm8qTpOE root@ip-172-31-16-58 (DSA)
Creating SSH2 ECDSA key; this may take some time ...
256 SHA256:LZ5vr5pi/8CNPFPW8IPGYmoH7tcJ7Ih7idF6bKfltUk root@ip-172-31-16-58 (ECDSA)
Creating SSH2 ED25519 key; this may take some time ...
256 SHA256:cfF3FfPC2G4zI7Xz/d1wHntIVijYQcJdISrxiuGAyHs root@ip-172-31-16-58 (ED25519)
invoke-rc.d: could not determine current runlevel
invoke-rc.d: policy-rc.d denied execution of start.

Current default time zone: 'Etc/UTC'
Local time is now:      Tue Dec  5 07:23:42 UTC 2017.
Universal Time is now:  Tue Dec  5 07:23:42 UTC 2017.


##
# The default user is 'ubuntu' with password 'ubuntu'!
# Use the 'sudo' command to run tasks as root in the container.
##

顯示VM的目錄內容

ubuntu@ip-172-31-16-58:~$ sudo tree -L 2 /var/lib/lxc
/var/lib/lxc
└── myBig1
    ├── config
    └── rootfs

Start and Stop Container VM

ubuntu@ip-172-31-16-58:~$ sudo lxc-start -n myBig1
lxc-start: tools/lxc_start.c: main: 301 Container is already running.
ubuntu@ip-172-31-16-58:~$ sudo lxc-stop -n myBig1

複製 LXC VM
ubuntu@ip-172-31-16-58:~$ sudo lxc-clone -o myBig1 -n myBig1_Backup
lxc-clone is deprecated in favor of lxc-copy.

Created container myBig1_Backup as copy of myBig1

ubuntu@ip-172-31-16-58:~$ sudo lxc-destroy -n myBig1_Backup (刪除 LXC VM)

ubuntu@ip-172-31-16-58:~$ sudo tree -L 2 /var/lib/lxc
/var/lib/lxc
├── myBig1
│   ├── config
│   └── rootfs
└── myBig1_Backup
    ├── config
    └── rootfs

4 directories, 2 files






Docker Command

#1 pull images $docker pull chusiang/takaojs1607 #2 list images $docker images #3.1 run docker $docker run -it ### bash #3.2 run do...