星期日, 1月 21, 2018

NextCloud and openSUSE Leap 42.3 小記

NextCloud and openSUSE in RPi3 workshop 101

OS:  openSUSE Leap 42.3 with Raspberry Pi 3
OS:  openSUSE Leap 42.3 in Azure

講師是 Gray

投影片

連接到 Raspberry Pi 3
參考台灣樹莓派的作法 https://www.raspberrypi.com.tw/tag/usb-to-ttl/  我使用 USB to TTL 線連接 console


然後在 Mac 上面
#screen   /dev/cu.usbserial  115200

就可以連線進 Raspberry Pi 3
利用 #yast  lan 設定網路連接, 準備測試

OS:  openSUSE Leap  42.3  in Azure

開啟 openSUSE Leap 42.3 VM in Azure
  • 網路安全性群組開啟 SSH 與 HTTP





Nextcloud 12 基本需求
  • PHP
    • 7.0 or 7.1 ( 不支援 7.2 )
  • Database
    • MYSQL / MariaDB 5.5 or PostgresSQL 9
  • Web Server
    • Apache 2.4 + mod_php or Nginx + php-fpm

安裝相關套件
# zypper  install  apache2  apache2-mod_php7  mariadb  php7-gd  php7-json  php7-fpm php7-mysql  php7-curl  php7-intl   php7-mcrypt  php7-zip  php7-mbstring  php7-zlib php7-openssl php7-fileinfo php7-posix

啟動 mysql 服務
# systemctl  start  mysql

設定開機啟動 mysql
# systemctl  enable  mysql
Created symlink from /etc/systemd/system/multi-user.target.wants/mysql.service to /usr/lib/systemd/system/mysql.service.

設定 mysql 管理者密碼
#mysqladmin  -u  root  password
New password:
Confirm new password:

登入 mysql 並建立 DB 與設定使用者帳密
# mysql  -u  root   -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 10.0.32-MariaDB SLE 12 SP1 package

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

MariaDB [(none)]> CREATE DATABASE nextcloudb;
MariaDB [(none)]> GRANT ALL ON nextcloudb.* TO ncuser@localhost
IDENTIFIED BY 'dbpass';

MariaDB [(none)]> Bye

  • ncuser --   登入帳號
  • Dbpass --  登入密碼


==== 設定 PHP ( optional ) ====

這邊有些設定會牽動日後的檔案上傳, 所以視情況調整, 尤其是 post_max_size :)

#vim  /etc/php7/apache2/php.ini
post_max_size = 50G
upload_max_filesize = 25G
max_file_uploads = 20
max_input_time = 3600
max_execution_time = 3600
session.gc_maxlifetime = 3600
memory_limit = 128M

========================

啟用相關 apache module
# a2enmod  php7

# a2enmod  rewrite

# a2enmod  headers

確認掛載的 module
# apachectl  -M

啟動 apache 服務
# systemctl   start  apache2.service

# systemctl   enable   apache2.service
Created symlink from /etc/systemd/system/httpd.service to /usr/lib/systemd/system/apache2.service.
Created symlink from /etc/systemd/system/apache.service to /usr/lib/systemd/system/apache2.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/apache2.service to /usr/lib/systemd/system/apache2.service.


==== 建立資料區( optional ) ====
這邊則是如果有外接式硬碟或是儲存空間會進惜調整

假設外接硬碟掛載在 /mnt/
# mkdir   /mnt/nextcloud_data
# chmod  770  /mnt/nextcloud_data
# chown  wwwrun  /mnt/nextcloud_data

=========================

安裝 nextcloud
下載 NextCloud (https://nextcloud.com/install/ ) 這邊以 nextcloud 12.0.4 為例

解開 .zip 檔案
# unzip  nextcloud-*.zip


將解開的目錄複製到 apache2 根目錄
# cp  -r  nextcloud  /srv/www/htdocs/

修改擁有者為 wwwrun
# chown   -R   wwwrun  /srv/www/htdocs/nextcloud/

連接到 nextcloud
開啟 http://<server ip>/nextcloud

預設值是使用 SQLite, 所以要手動選擇


點選 儲存空間與資料庫
點選 MySQL/MariaDB
輸入 管理者帳號 / 密碼, MySQL 帳號 / 密碼, SQL db 名稱


點選完成設定

  • 預設的資料區路徑 /srv/www/htdocs/nextcloud/data

在 Client 的部份, 除了 PC 以外也可以使用 Android 與 iOS 程式連接


連結的位置可以點選左下角的設定
會出現 WebDAV 路徑, 用這個路徑來進行連線
基本上就是 https:// or http://<your_Server_IP>/nextcloud



資料區預設的路徑在 /srv/www/htdocs/nextcloud/data ,
存放的檔案會在/srv/www/htdocs/nextcloud/data/使用者帳號/files 目錄
所以如果使用者是 sakana, 就是 /srv/www/htdocs/nextcloud/data/sakana/files

狀況:
如果在系統內手動建立或複製檔案到 /srv/www/htdocs/nextcloud/data/sakana/files 不會出現在 nextcloud 內

# pwd
/srv/www/htdocs/nextcloud/data/sakana/files

# touch  test20180121.txt

# ls
Documents  Nextcloud Manual.pdf  Nextcloud.mp4  Photos  test20180121.txt


如果手動放檔案, 使用 occ 指令更新 nextcloud 內的檔案 list

# sudo  -u  wwwrun  php  /srv/www/htdocs/nextcloud/occ  files:scan  --all
The process control (PCNTL) extensions are required in case you want to interrupt long running commands - see http://php.net/manual/en/book.pcntl.php
Starting scan for user 1 out of 1 (sakana)

+---------+-------+--------------+
| Folders | Files | Elapsed time |
+---------+-------+--------------+
| 4       | 8     | 00:00:00     |
+---------+-------+--------------+



Reference:


感謝今天 Gray 的分享
讓我們可以給 Raspberry Pi 又多一個用法
在 Azure 上面測試也沒有問題


~ enjoy it

星期六, 1月 20, 2018

Kubernetes in Docker for Mac Beta小記

Kubernetes in Docker for Mac Beta小記

OS: Mac EI Capitan 10.11.6
Docker: 17.12.0-cd-mac45

這一次的 Docker for Mac 被提示有加入 Kubernetes, 所以就順手升級他了

首先觀察 about docker 來看這次的版本



接下來點選 工具列上 docker 圖案 -- >  Preferences



點選 Kubernetes 圖案 -- > 勾選 Enable Kubernetes

接下來會提示要安裝 Kubernetes cluster -- > 點選 Install



系統會進行 Cluster 的安裝



安裝完成之後就會告知, 右下角也會看到 Kubernetes is running -- > 點選 Close

嘗試於終端機進行 kubectl 操作

$ kubectl  get  pods
Unable to connect to the server: dial tcp: lookup openshift-master.chicago.openshift3roadshow.com on 192.168.0.1:53: no such host

$ kubectl  get   cluster-info
Unable to connect to the server: dial tcp: lookup openshift-master.chicago.openshift3roadshow.com on 192.168.0.1:53: no such host


觀察了一下, 發現之前在芝加哥的時候有參加 openshit3 的 roadshow, 設定還在, 產生的錯誤

$ cat   ~/.kube/config
apiVersion: v1
clusters:
- cluster:
   insecure-skip-tls-verify: true
   server: https://localhost:6443
 name: docker-for-desktop-cluster
- cluster:
   insecure-skip-tls-verify: true
   server: https://openshift-master.chicago.openshift3roadshow.com:8443
 name: openshift-master-chicago-openshift3roadshow-com:8443
contexts:
- context:
   cluster: docker-for-desktop-cluster
   user: docker-for-desktop
 name: docker-for-desktop

把現在的設定檔案備份起來
$ mv  ~/.kube/config   ~/.kube/config.bak

觀察資訊
$ ls  ~/.kube/
config.bak

嘗試看看可不可以用 kubectl  操作
$ kubectl  get  pods
The connection to the server localhost:8080 was refused - did you specify the right host or port?

接下來嘗試個大絕招 ~ 把 docker 關掉重新再開 :)

重新啟動 docker 之後再次觀察  ~/.kube
$ ls   ~/.kube/
config     config.bak

觀察  ~/.kube/config
$ cat   ~/.kube/config
apiVersion: v1
clusters:
- cluster:
   insecure-skip-tls-verify: true
   server: https://localhost:6443
 name: docker-for-desktop-cluster
contexts:
- context:
   cluster: docker-for-desktop-cluster
   user: docker-for-desktop
 name: docker-for-desktop
current-context: docker-for-desktop
kind: Config
preferences: {}
users:
- name: docker-for-desktop
 user:
   client-certificate-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUNTRENDQVRDZ0F3SUJBZ0lJRlF0M1dpQm41VXN3RFFZSktvWklodmNOQVFFTEJRQXdGVEVUTUJFR0ExVUUKQXhNS2EzVmlaWEp1WlhSbGN6QWVGdzB4T0RBeE1qQXdPREk0TkRoYUZ3MHhPVEF4TWpBd09ESTRORGhhTURNeApGREFTQmdOVkJBb1RDMFJ2WTJ0bGNpQkpibU11TVJzd0dRWURWUVFERXhKa2IyTnJaWEl0Wm05eUxXUmxjMnQwCmIzQXdnWjh3RFFZSktvWklodmNOQVFFQkJRQURnWTBBTUlHSkFvR0JBUEQ1U2FtcEF0ZnN2T3FSUWhlekNrOTcKSVQ4eTk3aDlYUmx5UUV1RUI4T3c5RGw4dlJPRTFPZUXXXXXXXXXXXXXXXXzJnYml3OG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kxXQjZOc2x4WFFsZ3dCVldDRDVBV1JLWHhZb2FuWm5sMi90QmFZR0paaW83MS9wWHJSYlNwV2pyK2J5V0U5ckYKVGNEMDZjekg2SXBGdjZkVE9NREhyblRTc2FzSkpVNUhsWHhxMUtGY2VYNnVNZ2tKQWtFQTlhWUprMFFDQWlwUwp2Yng4cVlCRWtBNFZERkNkRUpoRlhIa2orYVI1bGhYMU9IQXRaSmRnMnBXTWxxNjVvUndXYVBqU25jZlhTMFJJCmk0OERSQVJYRndKQkFQc2cwZ0wrQ3pVZ01TZXV2ejdxei9OWHFIMkd3d3VtWStQTE1TbzlvSHpsUUN5MitqcXAKSnMzbTIrRFM4L3BXYWVBTzRIZ3pwWGREZzRMOFBXdWwzcXNDUUd4SGZBRUdBVHlqRzBXM1I5d1BSaW1aaTMyYQpLeUdkZlRWOTBIWENJalllQjdHUkFQRk9LTXN4RUg5N0ZTZ0hFWG5EOUZMSVBBWlpXd0RwVVM4eUdwRUNRSElIClB4VDR3YUlIMGdvUXdPb1N1UVhub2F3Tnl2YTVRTllvWjFTazB3Q2pIL2F0eHdWbjFTVGRWSzNMVzlrcDc3MDcKUkJXUWJldXZqa0dsdzBYajlTMENRRExpMUV0THJaU3pFT2pJMHBuUS9FdUxrWDk3SnpoVGZibk9RZmdvSlUzTgp6MWsvY2MvUmppM2plSW5HeHltOXNPZlpMbU1rU2ZoSk9ScktxWGdaZk1VPQotLS0tLUVORCBSU0EgUFJJVkFURSBLRVktLS0tLQo=

這邊有看到是在 port  6443 listen

在 Mac 上面觀察一下
$ netstat  -an  -p  tcp | grep LIST
tcp6       0      0  ::1.6443               *.*                    LISTEN     
tcp4       0      0  *.6443                 *.*                    LISTEN     
tcp4       0      0  127.0.0.1.17603        *.*                    LISTEN     
tcp4       0      0  127.0.0.1.17600        *.*                    LISTEN     
tcp4       0      0  *.17500                *.*                    LISTEN     
tcp6       0      0  *.17500                *.*                    LISTEN     
tcp4       0      0  127.0.0.1.44320        *.*                    LISTEN     

再次嘗試操作
$ kubectl   get   pods
No resources found.

$ kubectl  get  nodes
NAME                 STATUS    ROLES     AGE       VERSION
docker-for-desktop   Ready     master    40m       v1.8.2

$ kubectl   get  deployment
No resources found.

$ kubectl   get   svc
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   42m

接下來觀察  docker 這邊

首先會看到因為裝了 kubernetes, 所以多了很多 docker images
$ docker   images
REPOSITORY                                               TAG                 IMAGE ID            CREATED             SIZE
docker/kube-compose-controller                           v0.1.2              6480f70f7ac6        2 months ago        37.9MB
opensuse                                                 latest              c98336369400        2 months ago        108MB
sakanaacr.azurecr.io/opensuse                            latest              c98336369400        2 months ago        108MB
gcr.io/google_containers/kube-apiserver-amd64            v1.8.2              6278a1092d08        2 months ago        194MB
gcr.io/google_containers/kube-controller-manager-amd64   v1.8.2              5eabb0eae58b        2 months ago        129MB
gcr.io/google_containers/kube-scheduler-amd64            v1.8.2              b48970f8473e        2 months ago        54.9MB
gcr.io/google_containers/kube-proxy-amd64                v1.8.2              88e2c85d3d02        2 months ago        93.1MB
gcr.io/google_containers/k8s-dns-sidecar-amd64           1.14.5              fed89e8b4248        3 months ago        41.8MB
gcr.io/google_containers/k8s-dns-kube-dns-amd64          1.14.5              512cd7425a73        3 months ago        49.4MB
gcr.io/google_containers/k8s-dns-dnsmasq-nanny-amd64     1.14.5              459944ce8cc4        3 months ago        41.4MB
gcr.io/google_containers/etcd-amd64                      3.0.17              243830dae7dd        11 months ago       169MB
gcr.io/google_containers/pause-amd64                     3.0                 99e59f495ffa        20 months ago       747kB

透過 docker  version 觀察目前的 Orchestrator 為 kubernetes

$ docker  version
Client:
Version: 17.12-kube_beta
API version: 1.35
Go version: go1.9.2
Git commit: ca0c9dbcb219048a1a61fbf82a2e69f1b9795023
Built: Fri Dec 15 10:20:47 2017
OS/Arch: darwin/amd64
Orchestrator: kubernetes

Server:
Engine:
 Version: 17.12.0-ce
 API version: 1.35 (minimum version 1.12)
 Go version: go1.9.2
 Git commit: c97c6d6
 Built: Wed Dec 27 20:12:29 2017
 OS/Arch: linux/amd64
 Experimental: true

參考 “3 Minutes to Single Node Kubernetes cluster on Docker for Mac Platform” [1]

建立一個 webdemo.yml

觀察一下他的內容
$ cat   webdome.yml
apiVersion: v1
kind: Pod
metadata:
 name: collabweb
spec:
 containers:
 - name: webnix
   image: ajeetraina/webdemo
   ports:
     - containerPort: 8080

先觀察資訊
$ kubectl  get  pods
No resources found.

利用 webdemo.yml 建立 pod
$ kubectl   create  -f  webdemo.yml
pod "collabweb" created

$ kubectl  get  pods
NAME        READY     STATUS              RESTARTS   AGE
collabweb   0/1       ContainerCreating   0          1m

需要一點時間下載, 再次觀察
$ kubectl   get   pods
NAME        READY     STATUS    RESTARTS   AGE
collabweb   1/1       Running   0          6m

觀察相關資訊
$ kubectl  describe  pod  collabweb

Name:         collabweb
Namespace:    default
Node:         docker-for-desktop/192.168.65.3
Start Time:   Sat, 20 Jan 2018 18:08:33 +0800
Labels:       <none>
Annotations:  <none>
Status:       Running
IP:           10.1.0.6
Containers:
 webnix:
   Container ID:   docker://f193117c966b2c89fcb12e6ca81f135f20cc3dfe5ccf53c1b9873301d9648101
   Image:          ajeetraina/webdemo
   Image ID:       docker-pullable://ajeetraina/webdemo@sha256:5fddb01a372b02ec2d49465a920eda0f864b9b71ac75032fcbeeba028764bcd8
   Port:           8080/TCP
   State:          Running
     Started:      Sat, 20 Jan 2018 18:13:09 +0800
   Ready:          True
   Restart Count:  0
   Environment:    <none>
   Mounts:
     /var/run/secrets/kubernetes.io/serviceaccount from default-token-dwzlr (ro)
Conditions:
 Type           Status
 Initialized    True
 Ready          True
 PodScheduled   True
Volumes:
 default-token-dwzlr:
   Type:        Secret (a volume populated by a Secret)
   SecretName:  default-token-dwzlr
   Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.alpha.kubernetes.io/notReady:NoExecute for 300s
                node.alpha.kubernetes.io/unreachable:NoExecute for 300s
Events:
 Type    Reason                 Age   From                         Message
 ----    ------                 ----  ----                         -------
 Normal  Scheduled              7m    default-scheduler            Successfully assigned collabweb to docker-for-desktop
 Normal  SuccessfulMountVolume  7m    kubelet, docker-for-desktop  MountVolume.SetUp succeeded for volume "default-token-dwzlr"
 Normal  Pulling                7m    kubelet, docker-for-desktop  pulling image "ajeetraina/webdemo"
 Normal  Pulled                 3m    kubelet, docker-for-desktop  Successfully pulled image "ajeetraina/webdemo"
 Normal  Created                3m    kubelet, docker-for-desktop  Created container
 Normal  Started                3m    kubelet, docker-for-desktop  Started container


按照網頁上面的做法, 但是卻得不到 deployment, 已經留言還有 twitter 詢問了
$ kubectl  get  deployment  -o  wide
No resources found.

姑且使用 kubectl  run 來試試看
$ kubectl  run  webdemo  --image=ajeetraina/webdemo  --port=8080
deployment "webdemo" created

再次觀察
$ kubectl  get  deployment  -o  wide
NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE       CONTAINERS   IMAGES               SELECTOR
webdemo   1         1         1            1           1m        webdemo      ajeetraina/webdemo   run=webdemo

在 expose 之前先觀察 services
$ kubectl  get  services
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   3h

進行 expose
$ kubectl  expose  deployment  webdemo  --port=8080  --type=NodePort
service "webdemo" exposed

再次觀察
$ kubectl  get  services
NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
kubernetes   ClusterIP   10.96.0.1        <none>        443/TCP          3h
webdemo      NodePort    10.103.123.186   <none>        8080:30797/TCP   51s

進行相關測試
可以用 curl 或是開啟瀏覽器, 按照上面給的 port 來連線, 例如我這次是 :30797/TCP 就是 localhost:30797



最後來刪除 deployment

先觀察資訊
$ kubectl  get  deployment
NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
webdemo   1         1         1            1           11m

使用 kubectl delete 刪除
$ kubectl   delete  deployment  webdemo
deployment "webdemo" deleted

$ kubectl  get  deployment
No resources found.

$ kubectl  delete  pod  collabweb
pod "collabweb" deleted

搞定 :)
接下來可以在 Mac 進行 kubectl 練習了

Reference


~ enjoy it