```bash # Membuat deployment dengan image nginx root@minikube:~# kubectl create deployment test-nginx --image=nginx deployment.apps/test-nginx created #melihat pods yang sudah dibuat dari pembuatan deployment root@minikube:~# kubectl get pods NAME READY STATUS RESTARTS AGE test-nginx-6dbb5ccbb6-ghxhm 1/1 Running 0 10s # menampilkan environment variabel dari pod yang sudah dibuat root@minikube:~# kubectl exec test-nginx-6dbb5ccbb6-ghxhm env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin HOSTNAME=test-nginx-6dbb5ccbb6-ghxhm KUBERNETES_PORT_443_TCP=tcp://10.96.0.1:443 KUBERNETES_PORT_443_TCP_PROTO=tcp KUBERNETES_PORT_443_TCP_PORT=443 KUBERNETES_PORT_443_TCP_ADDR=10.96.0.1 KUBERNETES_SERVICE_HOST=10.96.0.1 KUBERNETES_SERVICE_PORT=443 KUBERNETES_SERVICE_PORT_HTTPS=443 KUBERNETES_PORT=tcp://10.96.0.1:443 NGINX_VERSION=1.15.5-1~stretch NJS_VERSION=1.15.5.0.2.4-1~stretch HOME=/root # Mencoba akses ke shell dari pod root@minikube:~# kubectl exec -it test-nginx-6dbb5ccbb6-ghxhm bash root@test-nginx-6dbb5ccbb6-ghxhm:/# hostname test-nginx-6dbb5ccbb6-ghxhm root@test-nginx-6dbb5ccbb6-ghxhm:/# exit # menampilkan logs dari pod root@minikube:~# kubectl logs test-nginx-6dbb5ccbb6-ghxhm 127.0.0.1 - - [22/Oct/2018:04:53:47 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.52.1" "-" # melakukan scale out pada pod root@minikube:~# kubectl scale deployment test-nginx --replicas=3 deployment.extensions/test-nginx scaled # check pod yang sudah di scale out root@minikube:~# kubectl get pods NAME READY STATUS RESTARTS AGE test-nginx-6dbb5ccbb6-ghxhm 1/1 Running 0 4m test-nginx-6dbb5ccbb6-j4z2p 1/1 Running 0 11s test-nginx-6dbb5ccbb6-n54g4 1/1 Running 0 11s # meng expose service pod root@minikube:~# kubectl expose deployment test-nginx --type="NodePort" --port 80 service "test-nginx" exposed # check service yang sudah di expose root@minikube:~# kubectl get services test-nginx NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE test-nginx NodePort 10.96.215.19680:31051/TCP 10s # perintah pada minikube untuk menampikan ip dari service root@minikube:~# minikube service test-nginx --url http://192.168.39.30:31051 # check service apakah berjalan root@minikube:~# curl http://192.168.39.30:31051 # menghapus service root@minikube:~# kubectl delete services test-nginx service "test-nginx" deleted # menghapus pods root@minikube:~# kubectl delete deployment test-nginx deployment.extensions "test-nginx" deleted ``` Yaps, selesai sudah tutorial pada kesempatan kali ini, sampai jumpa di tutorial berikutnya!
Hallo semua, pada kesempatan kali ini kami akan share tentang minikube , di post ini akan kami share bagaimana cara installnya. Minikube sendiri adalah Perangkat lunak yang memungkinkan kita untuk menjalan kubernetes pada komputer lokal kita dengan single node dan cluster. Dengan minikube memungkinkan kita untuk belajar tentang kubernetes dan juga testing ataupun development pada Komputer lokal kita, karena minikube relatif lebih ringan, jika dibandingkan dengan kubernetes original. Hal yang perlu diperhatikan sebelum kita install minikube, adalah bahwa komputer kita support hypervisor untuk menjalankan minikube. Seperti virtualbox, vmware, kvm dan lainya. Dan disini saya menggunakan kvm. Untuk installasi dan panduan menggunakan KVM ada di postingan berikut install kvm
Berikut adalah langkah-langkah untuk installasinya : minikube
```bash
root@minikube:~# apt-get install apt-transport-https -y
root@minikube:~# curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
OK
root@minikube:~# echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" | tee -a /etc/apt/sources.list.d/kubernetes.list
root@minikube:~# apt update
root@minikube:~# apt -y install kubectl
root@minikube:~# wget https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 -O minikube
root@minikube:~# wget https://storage.googleapis.com/minikube/releases/latest/docker-machine-driver-kvm2
root@minikube:~# chmod 755 minikube docker-machine-driver-kvm2
root@minikube:~# mv minikube docker-machine-driver-kvm2 /usr/local/bin/
root@minikube:~# minikube version
minikube version: v0.30.0
root@minikube:~# kubectl version -o json
{
"clientVersion": {
"major": "1",
"minor": "12",
"gitVersion": "v1.12.1",
"gitCommit": "4ed3216f3ec431b140b1d899130a69fc671678f4",
"gitTreeState": "clean",
"buildDate": "2018-10-05T16:46:06Z",
"goVersion": "go1.10.4",
"compiler": "gc",
"platform": "linux/amd64"
}
}
# Menjalankan Minikube dengan driver kvm
root@minikube:~# minikube start --vm-driver kvm2
Starting local Kubernetes v1.10.0 cluster...
Starting VM...
Downloading Minikube ISO
170.78 MB / 170.78 MB [====================] 100.00% 0s
Getting VM IP address...
Moving files into cluster...
Downloading kubeadm v1.10.0
Downloading kubelet v1.10.0
Finished Downloading kubelet v1.10.0
Finished Downloading kubeadm v1.10.0
Setting up certs...
Connecting to cluster...
Setting up kubeconfig...
Starting cluster components...
Kubectl is now configured to use the cluster.
Loading cached images from config file.
# Menampilkan status minikube
root@minikube:~# minikube status
minikube: Running
cluster: Running
kubectl: Correctly Configured: pointing to minikube-vm at 192.168.39.30
root@minikube:~# minikube service list
|-------------|----------------------|--------------|
| NAMESPACE | NAME | URL |
|-------------|----------------------|--------------|
| default | kubernetes | No node port |
| kube-system | kube-dns | No node port |
| kube-system | kubernetes-dashboard | No node port |
|-------------|----------------------|--------------|
root@minikube:~# minikube docker-env
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.39.30:2376"
export DOCKER_CERT_PATH="/root/.minikube/certs"
export DOCKER_API_VERSION="1.35"
# Run this command to configure your shell:
# eval $(minikube docker-env)
root@minikube:~# kubectl cluster-info
Kubernetes master is running at https://192.168.39.30:8443
CoreDNS is running at https://192.168.39.30:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
root@minikube:~# kubectl get nodes
NAME STATUS ROLES AGE VERSION
minikube Ready master 1m v1.10.0
# Menampilkan Vm yang digunakan untuk minikube
root@minikube:~# virsh list
Id Name State
----------------------------------------------------
1 minikube running
# Akses ke console server/vm minikube
root@minikube:~# minikube ssh
_ _
_ _ ( ) ( )
___ ___ (_) ___ (_)| |/') _ _ | |_ __
/' _ ` _ `\| |/' _ `\| || , < ( ) ( )| '_`\ /'__`\
| ( ) ( ) || || ( ) || || |\`\ | (_) || |_) )( ___/
(_) (_) (_)(_)(_) (_)(_)(_) (_)`\___/'(_,__/'`\____)'
$ hostname
minikube
$ exit
# Untuk menghentikan Minikube
root@minikube:~# minikube stop
Stopping local Kubernetes cluster...
Machine stopped.
# Untuk menghapus minikube
root@minikube:~# minikube delete
Deleting local Kubernetes cluster...
Machine deleted.
# check pada kvm setelah kita hapus minikube
root@minikube:~# virsh list --all
Id Name State
----------------------------------------------------
```
Yaps, selesai sudah tutorial kali ini, sampai ketemu di tutorial berikutnya !
1. Install beberapa package
```bash root@kvm:~# apt-get install -y libguestfs-tools virt-top ```
2. Mendapatkan OS secara official dan membuat vm
```bash
# Menampilkan template OS yang ada
root@kvm:~# virt-builder -l
.....
.....
ubuntu-10.04 x86_64 Ubuntu 10.04 (Lucid)
ubuntu-12.04 x86_64 Ubuntu 12.04 (Precise)
ubuntu-14.04 x86_64 Ubuntu 14.04 (Trusty)
ubuntu-16.04 x86_64 Ubuntu 16.04 (Xenial)
ubuntu-18.04 x86_64 Ubuntu 18.04 (bionic)
opensuse-13.1 x86_64 openSUSE 13.1
opensuse-13.2 x86_64 openSUSE 13.2
opensuse-42.1 x86_64 openSUSE Leap 42.1
opensuse-tumbleweed x86_64 openSUSE Tumbleweed
# Membuat image dari template yang ada(contoh ubuntu-18.04
root@kvm:~# virt-builder ubuntu-18.04 --format qcow2 --size 20G -o ubuntu1804.qcow2 --root-password password
[ 3.7] Downloading: http://libguestfs.org/download/builder/ubuntu-18.04.xz
[ 74.0] Planning how to build this image
[ 74.0] Uncompressing
.....
.....
Output file: ubuntu1804.qcow2
Output size: 20.0G
Output format: qcow2
Total usable space: 19.6G
Free space: 18.1G (92%)
# Membuat vm dari image yang telah dibuat
root@kvm:~# virt-install \
--name ubuntu-18.04 \
--ram 4096 \
--disk path=/var/kvm/images/ubuntu1804.qcow2 \
--vcpus 2 \
--os-type linux \
--os-variant ubuntu18.04 \
--network bridge=br0 \
--graphics none \
--serial pty \
--console pty \
--boot hd \
--noreboot \
--import
```
3. Melihat direktori pada vm
```bash root@kvm:~# virt-ls -l -d ubuntu1804 /root total 20 drwx------ 2 0 0 4096 May 7 10:22 . drwxr-xr-x 22 0 0 4096 May 7 10:15 .. -rw------- 1 0 0 153 May 7 11:44 .bash_history -rw-r--r-- 1 0 0 570 Jan 31 2010 .bashrc -rw-r--r-- 1 0 0 140 Nov 19 2007 .profile ```
4. membaca file yang ada pada vm
```bash root@kvm:~# virt-cat -d ubuntu1804 /etc/passwd ```
5. mengedit file/konfigurasi yang ada pada VM
```bash root@kvm:~# virt-edit -d ubuntu1804 /etc/fstab ```
6. Melihat pemakaian disk pada vm
```bash root@kvm:~# virt-df -d ubuntu1804 Filesystem 1K-blocks Used Available Use% ubuntu1804:/dev/sda1 240972 33211 195320 14% ubuntu1804:/dev/debian-vg/root 29284444 958140 26815700 4% ```
7. mountting disk vm ke folder host os
```bash root@kvm:~# guestmount -d ubuntu1804 -i /mnt root@kvm:~# ll /mnt total 89 drwxr-xr-x 2 root root 4096 May 7 19:19 bin drwxr-xr-x 4 root root 1024 May 7 19:20 boot drwxr-xr-x 4 root root 4096 May 7 19:13 dev drwxr-xr-x 83 root root 4096 May 7 19:24 etc drwxr-xr-x 3 root root 4096 May 7 19:20 home ... ... ```
8. melihat status pada vm
```bash
root@kvm:~# virt-top
virt-top 21:58:43 - x86_64 4/4CPU 2801MHz 12158MB
3 domains, 1 active, 1 running, 0 sleeping, 0 paused, 2 inactive D:0 O:0 X:0
CPU: 0.0% Mem: 4096 MB (4096 MB by guests)
ID S RDRQ WRRQ RXBY TXBY %CPU %MEM TIME NAME
6 R 0.0 0.0 0:04.92 ubuntu1804
- (template)
- (win2k12R2)
```
Yaps, selesai sudah tutorial kita kali ini, sampai jumpa di tutorial berikutnya!
Cara kerja dari STP sendiri adalah melakukan blocking pada salah satu interface dengan begitu hanya akan digunakan satu jalur saja, dan looping dapat diatasi. Dan port yang di block tadi akan menjadi jalur cadangan, jika jalur utama mati atau tidak berfungsi. Spanning Tree Protocol bekerja di layer 2 OSI layer. STP biasa digunakan pada switch, router yang menjalankan mode bridge, serta mulitlayer swicth yang berfungsi sebagai switch.
Pada STP, terdapat istilah Root bridge dan non-Root bridge. Root Bridge merupakan switch yang semua portnya aktif/menyala. Sedangkan Non-Root Bridge adalah switch-switch selain Root Bridge. Jika pada kasus, kita memiliki 2 switch maka, yang menjadi non-Root Bridge adalah switch yang salah satu portnya mati, atau blocking. Pemilihan Root Bridge ini berdasarkan pada priority. Dan yang akan menjadi Root Bridge adalah switch dengan priority terendah. Apabila nilai priority dari beberapa switch memiliki nilai yang sama, maka pemilihan Root Bridge akan dilihat dari nilai MAC Address terendah. Switch yang memiliki nilai MAC Address paling kecil akan menjadi Root Bridge.
Pada STP juga dikenal beberapa port, seperti yang sempat kita singgung diatas. Beberapa jenis port tersebut antara lain :
- Designated Port, yaitu port yang digunakan untuk mengirim data (memiliki MAC address terkecil).
- Root Port, yaitu port pada switch yang terhubung ke Root Bridge.
- Blocking Port, yaitu port yang diblok sehingga menjadi tidak aktif dan tidak digunakan untuk mengirim data. Biasanya blocking port dipilih dari nilai MAC address terbesar, nilai port terbesar, atau port dengan bandwidth terkecil.
```python
SW0#show spanning-tree
VLAN0001
Spanning tree enabled protocol ieee
Root ID Priority 32769
Address 0006.2A52.7436
Cost 19
Port 2(FastEthernet0/2)
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Bridge ID Priority 32769 (priority 32768 sys-id-ext 1)
Address 0050.0FD4.0413
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Aging Time 20
Interface Role Sts Cost Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa0/2 Root FWD 19 128.2 P2p
Fa0/1 Desg FWD 19 128.1 P2p
SW0#
```
```python
SW1#show spanning-tree
VLAN0001
Spanning tree enabled protocol ieee
Root ID Priority 32769
Address 0006.2A52.7436
Cost 19
Port 2(FastEthernet0/2)
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Bridge ID Priority 32769 (priority 32768 sys-id-ext 1)
Address 0060.2F14.4813
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Aging Time 20
Interface Role Sts Cost Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa0/1 Altn BLK 19 128.1 P2p
Fa0/2 Root FWD 19 128.2 P2p
SW1#
```
```python
SW2#show spanning-tree
VLAN0001
Spanning tree enabled protocol ieee
Root ID Priority 32769
Address 0006.2A52.7436
This bridge is the root
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Bridge ID Priority 32769 (priority 32768 sys-id-ext 1)
Address 0006.2A52.7436
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Aging Time 20
Interface Role Sts Cost Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa0/2 Desg FWD 19 128.2 P2p
Fa0/1 Desg FWD 19 128.1 P2p
SW2#
```
Hello semua, Pada kesempatan kali ini kami akan share, tentang operasi dasar pada KVM, menggunakan command line interface(cli). berikut adalah beberapa operasi dasar yang biasa dilakukan :
1. Menjalankan virtual machine
```bash # Start Virtual Machine normal root@kvm:~# virsh start ubuntu1804 # start virtual machine dan connect ke console root@kvm:~# virsh start ubuntu1804 --console ```
2. Stop virtual machine
```bash # Stop Virtual Machine normal root@kvm:~# virsh shutdown ubuntu1804 # Stop Virtual Machine secara paksa root@kvm:~# virsh destroy ubuntu1804 ```
3. Set auto-start Pada Virtual machine
```bash # Enable auto-start, begitu Host Os nyala, VM akan ikutan nyala root@kvm:~# virsh autostart ubuntu1804 # Disable auto-start root@kvm:~# virsh autostart --disable ubuntu1804 ```
4. Menampilkan Daftar virtual machine
```bash # Menampilkan semua VM yang berjalan root@kvm:~# virsh list Id Name State ---------------------------------------- 2 ubuntu1804 running # Menampilkan semua vm, baik yang jalan atau tidak root@kvm:~# virsh list --all Id Name State ---------------------------------------- - ubuntu1804 runnning - template shut off - Win2k16 shut off ```
5. Berpindah ke console
```bash # konek ke console vm root@kvm:~# virsh console ubuntu1804 # keluar dari guest os(vm) kembali ke Host Os root@ubuntu:~# # Ctrl + ] key ```
6. Menampilkan informasi guest virtual machine
```bash root@kvm:~# virsh dumpxml ubuntu1804 ```
7. Konfigurasi network via xml
```bash root@kvm:~# virsh net-edit default root@kvm:~# virsh net-destroy default root@kvm:~# virsh net-start default ```
8. Menampilkan network dan ip address
```bash root@kvm:~# virsh net-list root@kvm:~# virsh net-info default root@kvm:~# virsh net-dhcp-leases default root@kvm:~# virsh domifaddr ubuntu1804 ```
9. Mengetahui perintah-perintah yang ada
```bash
root@kvm:~# virsh --help
virsh [options]... [command_string]
virsh [options]... command [args...]
options:
-c | --connect=URI hypervisor connection URI
-d | --debug=NUM debug level [0-4]
-e | --escape char set escape sequence for console
-h | --help this help
-k | --keepalive-interval=NUM
keepalive interval in seconds, 0 for disable
-K | --keepalive-count=NUM
number of possible missed keepalive messages
-l | --log=FILE output logging to file
-q | --quiet quiet mode
-r | --readonly connect readonly
-t | --timing print timing information
-v short version
-V long version
--version[=TYPE] version, TYPE is short or long (default short)
commands (non interactive mode):
Domain Management (help keyword 'domain')
attach-device attach device from an XML file
attach-disk attach disk device
attach-interface attach network interface
autostart autostart a domain
blkdeviotune Set or query a block device I/O tuning parameters.
blkiotune Get or set blkio parameters
blockcommit Start a block commit operation.
blockcopy Start a block copy operation.
blockjob Manage active block operations
blockpull Populate a disk from its backing image.
blockresize Resize block device of domain.
change-media Change media of CD or floppy drive
console connect to the guest console
cpu-baseline compute baseline CPU
cpu-compare compare host CPU with a CPU described by an XML file
cpu-stats show domain cpu statistics
create create a domain from an XML file
define define (but don't start) a domain from an XML file
desc show or set domain's description or title
destroy destroy (stop) a domain
detach-device detach device from an XML file
detach-disk detach disk device
detach-interface detach network interface
domdisplay domain display connection URI
domfsfreeze Freeze domain's mounted filesystems.
domfsthaw Thaw domain's mounted filesystems.
domfsinfo Get information of domain's mounted filesystems.
domfstrim Invoke fstrim on domain's mounted filesystems.
domhostname print the domain's hostname
domid convert a domain name or UUID to domain id
domif-setlink set link state of a virtual interface
domiftune get/set parameters of a virtual interface
domjobabort abort active domain job
domjobinfo domain job information
domname convert a domain id or UUID to domain name
domrename rename a domain
dompmsuspend suspend a domain gracefully using power management functions
dompmwakeup wakeup a domain from pmsuspended state
domuuid convert a domain name or id to domain UUID
domxml-from-native Convert native config to domain XML
domxml-to-native Convert domain XML to native config
dump dump the core of a domain to a file for analysis
dumpxml domain information in XML
edit edit XML configuration for a domain
event Domain Events
inject-nmi Inject NMI to the guest
iothreadinfo view domain IOThreads
iothreadpin control domain IOThread affinity
iothreadadd add an IOThread to the guest domain
iothreaddel delete an IOThread from the guest domain
send-key Send keycodes to the guest
send-process-signal Send signals to processes
lxc-enter-namespace LXC Guest Enter Namespace
managedsave managed save of a domain state
managedsave-remove Remove managed save of a domain
managedsave-edit edit XML for a domain's managed save state file
managedsave-dumpxml Domain information of managed save state file in XML
managedsave-define redefine the XML for a domain's managed save state file
memtune Get or set memory parameters
perf Get or set perf event
metadata show or set domain's custom XML metadata
migrate migrate domain to another host
migrate-setmaxdowntime set maximum tolerable downtime
migrate-getmaxdowntime get maximum tolerable downtime
migrate-compcache get/set compression cache size
migrate-setspeed Set the maximum migration bandwidth
migrate-getspeed Get the maximum migration bandwidth
migrate-postcopy Switch running migration from pre-copy to post-copy
numatune Get or set numa parameters
qemu-attach QEMU Attach
qemu-monitor-command QEMU Monitor Command
qemu-monitor-event QEMU Monitor Events
qemu-agent-command QEMU Guest Agent Command
reboot reboot a domain
reset reset a domain
restore restore a domain from a saved state in a file
resume resume a domain
save save a domain state to a file
save-image-define redefine the XML for a domain's saved state file
save-image-dumpxml saved state domain information in XML
save-image-edit edit XML for a domain's saved state file
schedinfo show/set scheduler parameters
screenshot take a screenshot of a current domain console and store it into a file
set-lifecycle-action change lifecycle actions
set-user-password set the user password inside the domain
setmaxmem change maximum memory limit
setmem change memory allocation
setvcpus change number of virtual CPUs
shutdown gracefully shutdown a domain
start start a (previously defined) inactive domain
suspend suspend a domain
ttyconsole tty console
undefine undefine a domain
update-device update device from an XML file
vcpucount domain vcpu counts
vcpuinfo detailed domain vcpu information
vcpupin control or query domain vcpu affinity
emulatorpin control or query domain emulator affinity
vncdisplay vnc display
guestvcpus query or modify state of vcpu in the guest (via agent)
setvcpu attach/detach vcpu or groups of threads
domblkthreshold set the threshold for block-threshold event for a given block device or it's backing chain element
Domain Monitoring (help keyword 'monitor')
domblkerror Show errors on block devices
domblkinfo domain block device size information
domblklist list all domain blocks
domblkstat get device block stats for a domain
domcontrol domain control interface state
domif-getlink get link state of a virtual interface
domifaddr Get network interfaces' addresses for a running domain
domiflist list all domain virtual interfaces
domifstat get network interface stats for a domain
dominfo domain information
dommemstat get memory statistics for a domain
domstate domain state
domstats get statistics about one or multiple domains
domtime domain time
list list domains
Host and Hypervisor (help keyword 'host')
allocpages Manipulate pages pool size
capabilities capabilities
cpu-models CPU models
domcapabilities domain capabilities
freecell NUMA free memory
freepages NUMA free pages
hostname print the hypervisor hostname
maxvcpus connection vcpu maximum
node-memory-tune Get or set node memory parameters
nodecpumap node cpu map
nodecpustats Prints cpu stats of the node.
nodeinfo node information
nodememstats Prints memory stats of the node.
nodesuspend suspend the host node for a given time duration
sysinfo print the hypervisor sysinfo
uri print the hypervisor canonical URI
version show version
Interface (help keyword 'interface')
iface-begin create a snapshot of current interfaces settings, which can be later committed (iface-commit) or restored (iface-rollback)
iface-bridge create a bridge device and attach an existing network device to it
iface-commit commit changes made since iface-begin and free restore point
iface-define define an inactive persistent physical host interface or modify an existing persistent one from an XML file
iface-destroy destroy a physical host interface (disable it / "if-down")
iface-dumpxml interface information in XML
iface-edit edit XML configuration for a physical host interface
iface-list list physical host interfaces
iface-mac convert an interface name to interface MAC address
iface-name convert an interface MAC address to interface name
iface-rollback rollback to previous saved configuration created via iface-begin
iface-start start a physical host interface (enable it / "if-up")
iface-unbridge undefine a bridge device after detaching its slave device
iface-undefine undefine a physical host interface (remove it from configuration)
Network Filter (help keyword 'filter')
nwfilter-define define or update a network filter from an XML file
nwfilter-dumpxml network filter information in XML
nwfilter-edit edit XML configuration for a network filter
nwfilter-list list network filters
nwfilter-undefine undefine a network filter
Networking (help keyword 'network')
net-autostart autostart a network
net-create create a network from an XML file
net-define define an inactive persistent virtual network or modify an existing persistent one from an XML file
net-destroy destroy (stop) a network
net-dhcp-leases print lease info for a given network
net-dumpxml network information in XML
net-edit edit XML configuration for a network
net-event Network Events
net-info network information
net-list list networks
net-name convert a network UUID to network name
net-start start a (previously defined) inactive network
net-undefine undefine a persistent network
net-update update parts of an existing network's configuration
net-uuid convert a network name to network UUID
Node Device (help keyword 'nodedev')
nodedev-create create a device defined by an XML file on the node
nodedev-destroy destroy (stop) a device on the node
nodedev-detach detach node device from its device driver
nodedev-dumpxml node device details in XML
nodedev-list enumerate devices on this host
nodedev-reattach reattach node device to its device driver
nodedev-reset reset node device
nodedev-event Node Device Events
Secret (help keyword 'secret')
secret-define define or modify a secret from an XML file
secret-dumpxml secret attributes in XML
secret-event Secret Events
secret-get-value Output a secret value
secret-list list secrets
secret-set-value set a secret value
secret-undefine undefine a secret
Snapshot (help keyword 'snapshot')
snapshot-create Create a snapshot from XML
snapshot-create-as Create a snapshot from a set of args
snapshot-current Get or set the current snapshot
snapshot-delete Delete a d[ 659.538623] serial8250: too much work for irq4
omain snapshot
snapshot-dumpxml Dump XML for a domain snapshot
snapshot-edit edit XML for a snapshot
snapshot-info snapshot information
snapshot-list List snapshots for a domain
snapshot-parent Get the name of the parent of a snapshot
snapshot-revert Revert a domain to a snapshot
Storage Pool (help keyword 'pool')
find-storage-pool-sources-as find potential storage pool sources
find-storage-pool-sources discover potential storage pool sources
pool-autostart autostart a pool
pool-build build a pool
pool-create-as create a pool from a set of args
pool-create create a pool from an XML file
pool-define-as define a pool from a set of args
pool-define define an inactive persistent storage pool or modify an existing persistent one from an XML file
pool-delete delete a pool
pool-destroy destroy (stop) a pool
pool-dumpxml pool information in XML
pool-edit edit XML configuration for a storage pool
pool-info storage pool information
pool-list list pools
pool-name convert a pool UUID to pool name
pool-refresh refresh a pool
pool-start start a (previously defined) inactive pool
pool-undefine undefine an inactive pool
pool-uuid convert a pool name to pool UUID
pool-event Storage Pool Events
Storage Volume (help keyword 'volume')
vol-clone clone a volume.
vol-create-as create a volume from a set of args
vol-create create a vol from an XML file
vol-create-from create a vol, using another volume as input
vol-delete delete a vol
vol-download download volume contents to a file
vol-dumpxml vol information in XML
vol-info storage vol information
vol-key returns the volume key for a given volume name or path
vol-list list vols
vol-name returns the volume name for a given volume key or path
vol-path returns the volume path for a given volume name or key
vol-pool returns the storage pool for a given volume key or path
vol-resize resize a vol
vol-upload upload file contents to a volume
vol-wipe wipe a vol
Virsh itself (help keyword 'virsh')
cd change the current directory
echo echo arguments
exit quit this interactive terminal
help print help
pwd print the current directory
quit quit this interactive terminal
connect (re)connect to hypervisor
(specify help group for details about the commands in the group)
(specify help command for details about the command)
```
Yaps, sampai di sini dulu, sampai jumpa di tutorial berikutnya !
Pada kesempatan kali ini, melanjutkan postingan sebelumnya yaitu tentang KVM, pada tutorial kali ini akan dibahas tentang bagaimana cara membuat virtual machine pada KVM melalui CLI. Berikut adalah langkah-langkahnya :
1. Membuat virtual machine dan install guest OS
```bash root@kvm:~# mkdir -p /var/kvm/images root@kvm:~# virt-install \ --name ubuntu1804 \ --ram 4096 \ --disk path=/var/kvm/images/ubuntu1804.img,size=30 \ --vcpus 2 \ --os-type linux \ --os-variant ubuntu18.04 \ --network bridge=br0 \ --graphics none \ --console pty,target_type=serial \ --location 'http://id.archive.ubuntu.com/ubuntu/dists/bionic/main/installer-amd64/' \ --extra-args 'console=ttyS0,115200n8 serial' # mematikan vm root@kvm:~# virsh shutdown ubuntu1804 # mounting disk guest os ke host os dan aktifkan service (optional) root@kvm:~# guestmount -d ubuntu1804 -i /mnt root@kvm:~# ln -s /mnt/lib/systemd/system/getty@.service /mnt/etc/systemd/system/getty.target.wants/getty@ttyS0.service root@kvm:~# umount /mnt root@kvm:~# virsh start ubuntu1804 --console ```
## Keterangan : | Parameter | penjelasan | |:--------------|----------------:| | --name | Nama dari VM yang akan dibuat | | --ram | Ukuran ram yang akan diberikan | | --disk path=xx size=xx | path= Lokasi disk , size= Ukuran disk yang akan dialokasikan | | --vcpus | virtual cpu yang diberikan | | --os-type | tipe dari sistem operasi | | --os-variant | variasi sistem operasi | | --network | tipe network yang diberikan | | --graphics | grafis yang diberikan | | --console | tipe konsole untuk remote guest os | | --location | lokasi installasi / folder sistem operasi yang akan diinstall | | --extra-args | parameter spesifik |
2. Masuk ke Guest OS dan kembali ke Host OS
```bash # pindah ke Guest OS root@kvm:~# virsh console ubuntu1804 # pindah ke host OS bionic@ubuntu:~$ # Ctrl + ] key ```
3. Kloning virtual machine
```bash root@kvm:~# virt-clone --original ubuntu1804 --name ubuntu1804_org --file /var/kvm/images/ubuntu1804_org.img # lokasi disk root@kvm:~# ll /var/kvm/images/ubuntu1804_org.img # Lokasi konfigurasi root@kvm:~# ll /etc/libvirt/qemu/ubuntu1804_org.xml ```Yaps, selesai sudah tutorial kali ini, sampai jumpa di tutorial berikutnya !
```bash root@kvm:~# apt-get install -y qemu-kvm libvirt-bin virtinst bridge-utils libosinfo-bin libguestfs-tools virt-top ```
```bash root@kvm:~# modprobe vhost_net root@kvm:~# lsmod | grep vhost vhost_net 20480 0 vhost 32768 1 vhost_net macvtap 20480 1 vhost_net root@kvm:~# echo vhost_net >> /etc/modules ```
```bash
root@kvm:~# vi /etc/netplan/01-netcfg.yaml
network:
version: 2
renderer: networkd
ethernets:
ens3:
dhcp4: no
# disable existing configuration for ethernet
#addresses: [10.20.20.30/24]
#gateway4: 10.20.20.1
#nameservers:
#addresses: [10.20.20.10]
dhcp6: no
# add configuration for bridge interface
bridges:
br0:
interfaces: [ens3]
dhcp4: no
addresses: [10.20.20.30/24]
gateway4: 10.20.20.1
nameservers:
addresses: [10.20.20.10]
parameters:
stp: false
dhcp6: no
root@kvm:~# reboot
root@kvm:~# ip addr
```
```bash root@dnsforward:~# apt-get install -y dnsmasq ```
```bash root@dnsforward:~# vi /etc/dnsmasq.conf domain-needed bogus-priv strict-order # contoh definisi dns query dan ip server=/sulaiman28.codes/10.20.20.10 expand-hosts domain=example.com root@dnsforward:~# systemctl restart dnsmasq ```
```bash root@dnsforward:~# vi /etc/hosts # menambahkan records 10.20.20.30 dnsforward.example.com dnsforward root@dnsforward:~# systemctl restart dnsmasq ```
```bash
root@client:~# vi /etc/netplan/01-netcfg.yaml
#change DNS server to DNSmasq server
nameservers:
addresses: [10.20.20.30]
root@client:~# netplan apply
root@client:~# systemd-resolve --status --no-pager | tail -7
Link 2 (ens3)
Current Scopes: DNS
LLMNR setting: yes
MulticastDNS setting: no
DNSSEC setting: no
DNSSEC supported: no
DNS Servers: 10.20.20.30
root@client:~# dig dnsforward.example.com.
root@client:~# dig -x 10.20.20.30
```
```bash root@dnsforward:~# vi /etc/dnsmasq.conf # range ip yang akan didistribusikan dhcp-range=10.20.20.150,10.20.20.200,12h # tambahkan gateway dhcp-option=option:router,10.20.20.1 # tambahkan NTP, DNS, server and subnetmask dhcp-option=option:ntp-server,10.20.20.10 dhcp-option=option:dns-server,10.20.20.10 dhcp-option=option:netmask,255.255.255.0 root@dnsforward:~# systemctl restart dnsmasq ```6. verifikasi pada client apakah mendapatkan ip address dari dhcp server
Yups, sudah selesai untuk tutorial pada kesempatan hari ini, sampai ketemu di tutorial berikutnya!
```bash root@alfaruq:~# apt-get install -y openssh-server root@alfaruq:~# vi /etc/ssh/sshd_config PermitRootLogin no root@alfaruq:~# systemctl restart ssh ```
```bash root@client:~# ssh ubuntu@serverssh.example.com The authenticity of host 'serverssh.example.com (10.20.20.50)' cant be established. ECDSA key fingerprint is SHA256:cFINZxChloNp9GjMFkplmg3bsING9me+ld9asR2Hj08. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'serverssh.example.com,10.20.20.50' (ECDSA) to the list of known hosts. ubuntu@serverssh.example.com password: Welcome to Ubuntu 18.04 LTS (GNU/Linux 4.15.0-20-generic x86_64) ..... ..... Last login: Tue Nov 3 14:38:33 2020 ubuntu@serverssh:~$ # diatas untuk Client linux, jika windows dapat menggunakan software seperti putty, # atau untuk windows 10 terbaru sudah support melalui cmd dengan command yang sama # Kita juga dapat eksekusi command secara remote ubuntu@sshclient:~$ ssh ubuntu@serverssh.example.com "echo 'Hallo, from client'" ```2. SSH File Transfer
```bash ubuntu@serverssh:~$ scp ./test.txt ubuntu@client.example.com:~/ ubuntu@10.0.0.30 password: test.txt 100% 10 0.0KB/s 00:00 # copy file dari client ke ssh server ubuntu@serverssh:~$ scp ubuntu@client.example.com:/home/ubuntu/test.txt ./test.txt ubuntu@10.0.0.30's password: test.txt 100% 10 0.0KB/s 00:00 ```Sedangkan berikut, ketika menggunakan SFTP
```bash # sftp [Option] [user@host] ubuntu@serverssh:~$ sftp ubuntu@client.example.com ubuntu@client.example.com password: Connected to client.example.com. sftp> # Menampilkan posisi folder dimana kita berada sftp> pwd Remote working directory: /home/ubuntu sftp> !pwd /home/ubuntu # Menampilkan daftar file yang ada sftp> ls -l drwxrwxr-x 2 ubuntu ubuntu 6 Apr 29 21:33 public_html -rw-rw-r-- 1 ubuntu ubuntu 10 Apr 28 22:53 test.txt sftp> !ls -l total 4 -rw-rw-r-- 1 ubuntu ubuntu 10 Jul 29 21:31 test.txt # pindah folder sftp> cd public_html sftp> pwd Remote working directory: /home/ubuntu/public_html # mengirimkan hanya beberapa file saja sftp> put test.txt ubuntu.txt Uploading test.txt to /home/ubuntu/ubuntu.txt test.txt 100% 10 0.0KB/s 00:00 sftp> ls -l drwxrwxr-x 2 ubuntu ubuntu 6 Apr 29 21:33 public_html -rw-rw-r-- 1 ubuntu ubuntu 10 Apr 29 21:39 ubuntu.txt -rw-rw-r-- 1 ubuntu ubuntu 10 Apr 28 22:53 test.txt # upload semua file txt yang ada pada server ke client sftp> put *.txt Uploading test.txt to /home/ubuntu/test.txt test.txt 100% 10 0.0KB/s 00:00 Uploading test2.txt to /home/ubuntu/test2.txt test2.txt 100% 0 0.0KB/s 00:00 sftp> ls -l drwxrwxr-x 2 ubuntu ubuntu 6 Apr 29 21:33 public_html -rw-rw-r-- 1 ubuntu ubuntu 10 Apr 29 21:39 ubuntu.txt -rw-rw-r-- 1 ubuntu ubuntu 10 Apr 29 21:45 test.txt -rw-rw-r-- 1 ubuntu ubuntu 10 Apr 29 21:46 test2.txt # download file dari client ke server sftp> get test.txt Fetching /home/ubuntu/test.txt to test.txt /home/ubuntu/test.txt 100% 10 0.0KB/s 00:00 sftp> get *.txt Fetching /home/ubuntu/ubuntu.txt to ubuntu.txt /home/ubuntu/ubuntu.txt 100% 10 0.0KB/s 00:00 Fetching /home/ubuntu/test.txt to test.txt /home/ubuntu/test.txt 100% 10 0.0KB/s 00:00 Fetching /home/ubuntu/test2.txt to test2.txt /home/ubuntu/test2.txt 100% 10 0.0KB/s 00:00 #buat folder di client sftp> mkdir testdir sftp> ls -l drwxrwxr-x 2 ubuntu ubuntu 6 Apr 29 21:33 public_html -rw-rw-r-- 1 ubuntu ubuntu 10 Apr 29 21:39 ubuntu.txt -rw-rw-r-- 1 ubuntu ubuntu 10 Apr 29 21:45 test.txt -rw-rw-r-- 1 ubuntu ubuntu 10 Apr 29 21:46 test2.txt drwxrwxr-x 2 ubuntu ubuntu 6 Apr 29 21:53 testdir # hapus folder pada client sftp> rmdir testdir rmdir ok, `testdir` removed sftp> ls -l drwxrwxr-x 2 ubuntu ubuntu 6 Apr 29 21:33 public_html -rw-rw-r-- 1 ubuntu ubuntu 10 Apr 29 21:39 ubuntu.txt -rw-rw-r-- 1 ubuntu ubuntu 10 Apr 29 21:45 test.txt -rw-rw-r-- 1 ubuntu ubuntu 10 Apr 29 21:46 test2.txt # hapus file pada client sftp> rm test2.txt Removing /home/ubuntu/test2.txt sftp> ls -l drwxrwxr-x 2 ubuntu ubuntu 6 Apr 29 21:33 public_html -rw-rw-r-- 1 ubuntu ubuntu 10 Apr 29 21:39 ubuntu.txt -rw-rw-r-- 1 ubuntu ubuntu 10 Apr 29 21:45 test.txt # Menjankan perintah pada client sftp> !cat /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin ... ... ubuntu:x:1001:1001::/home/ubuntu:/bin/bash # keluar dari sftp sftp> quit 221 Goodbye. ```3. SSH Key-pair Authentication
```bash ubuntu@serverssh:~$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/ubuntu/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/ubuntu/.ssh/id_rsa. Your public key has been saved in /home/ubuntu/.ssh/id_rsa.pub. The key fingerprint is: 30:ee:f0:47:38:9d:8a:24:5e:01:c8:13:df:15:40:b4 ubuntu@serverssh The keys randomart image is: ubuntu@serverssh:~$ mv ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys ubuntu@serverssh:~$ chmod 600 ~/.ssh/authorized_keys # untuk menambahkan agar lebih aman root@serverssh:~# vi /etc/ssh/sshd_config PasswordAuthentication no root@serverssh:~# systemctl restart ssh ```
```bash # Pada client ubuntu@client:~$ mkdir ~/.ssh ubuntu@client:~$ chmod 700 ~/.ssh # copy the secret key to the local ssh directory ubuntu@client:~$ scp ubuntu@10.20.20.50:/home/ubuntu/.ssh/id_rsa ~/.ssh/ ubuntu@10.20.20.50 password: id_rsa ubuntu@client:~$ ssh ubuntu@10.20.20.50 Enter passphrase for key '/home/ubuntu/.ssh/id_rsa': Last login: Sat Apr 28 20:30:53 2018 from client.example.com ubuntu@serverssh:~$ # just logined ```Yaps, selesai sudah, beberapa konfigurasi sederhana pada ssh server di ubuntu 18.04, sampai jumpa di tutorial berikutnya!
```bash root@alfaruq:~# apt-get install chrony -y ```2. Konfigurasi NTP server Chrony
```bash root@alfaruq:~# vi /etc/chrony/chrony.conf # Jangan lupa untuk atur timezone sesuai wilayah # List server bisa kita gunakan server default juga atau server yang dekat dengan wilayah kita server ntp.nict.jp iburst server ntp1.jst.mfeed.ad.jp iburst server ntp2.jst.mfeed.ad.jp iburst # atur range network clint yang akan menggunakan ntp server kita allow 10.0.0.0/24 ```3. Restart service Chrony pada server
```bash root@alfaruq:~# systemctl restart chrony ```4. Verifikasi
```bash root@alfaruq:~# chronyc sources 210 Number of sources = 3 MS Name/IP address Stratum Poll Reach LastRx Last sample =============================================================================== ^* ntp-a2.nict.go.jp 1 6 37 4 +21us[+1387us] +/- 9053us ^- ntp1.jst.mfeed.ad.jp 2 6 37 4 -1529us[-1529us] +/- 89ms ^- ntp2.jst.mfeed.ad.jp 2 6 37 3 -2436us[-2436us] +/- 89ms ```5. Konfiguasi pada client untuk konfigurasi Pada client linux, seperti berikut :
```bash root@alfaruq:~# apt-get install ntpdate -y root@alfaruq:~# ntpdate ntpserver.example.com 26 Apr 19:20:58 ntpdate[3221]: adjust time server 10.20.20.1 offset 0.000609 sec ```
Pada kesempatan ini, kami akan share bagaimana cara konfigurasi Alamat IP, pada Ubuntu 18.04. Untuk Ubuntu 18.04 ini sendiri dalam Networknya, sudah menggunakan netplan ini memungkinkan kita untuk mengkonfigurasinya dengan yaml file. Berikut Langkahnya :
1. Kita login ke dalam Ubuntu 18.04
2. Lalu konfigurasikan IP seperti berikut
```bash root@alfaruq:~# vi /etc/netplan/01-netcfg.yaml ```
Isi seperti berikut :
```bash
network:
version: 2
renderer: networkd
ethernets:
ens3:
dhcp4: no
# IP address/subnet mask
addresses: [10.0.0.30/24]
# default gateway
gateway4: 10.0.0.1
nameservers:
# dns
addresses: [10.0.0.10,10.0.0.11]
dhcp6: no
```
3. Implentasikan konfigurasi
```bash root@alfaruq:~# netplan apply root@alfaruq:~# ip addr 1: lo:mtu 65536 qdisc noqueue state UNKNOWN group default 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 2: ens3: mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 52:54:00:19:e8:09 brd ff:ff:ff:ff:ff:ff inet 10.0.0.30/24 brd 10.0.0.255 scope global ens3 valid_lft forever preferred_lft forever inet6 fe80::5054:ff:fe19:e809/64 scope link valid_lft forever preferred_lft forever ```
4. disable ipv6, jika tidak membutuhkan
```bash root@alfaruq:~# echo "net.ipv6.conf.all.disable_ipv6 = 1" >> /etc/sysctl.conf root@alfaruq:~# systcl -p net.ipv6.conf.all.disable_ipv6 = 1 root@alfaruq:~# ip addr 1: lo:mtu 65536 qdisc noqueue state UNKNOWN group default 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 2: ens3: mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 52:54:00:19:e8:09 brd ff:ff:ff:ff:ff:ff inet 10.0.0.30/24 brd 10.0.0.255 scope global ens3 valid_lft forever preferred_lft forever ```
Sekian dulu untuk postingan hari ini, sampai jumpa di tutorial berikutnya !








