蔡卓倫
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Python ETL 交接 === ###### tags: `【bmwlab】` ETL --- - 絕對位置 - 執行檔:/home/collaborator/ems/json/raw_data_etl - 執行檔(code):/home/collaborator/ems/json/raw_data_etl.py - 目的: 把傳入得json檔案解析,send to mongoDB - json file location(sent by 北水): /home/collaborator/ems/json/ - CLI: > `pyinstaller -F raw_data_etl.py` - note: need to change line notify - crontab: - goal: set run schedule - schedule: ![](https://i.imgur.com/UFGFzzx.png) - `15 1`: 1:15am (they send data from 1. and 13.) - `* * *` : every day - ` cd /home/collaborator/ems/json && ./raw_data_etl`: cd to directory and run file - `--num 1`: each thread run 1 file - `--dstPath /home/bmwlab/drinking_station_ETL/write_to_DB_over/`: processed json file location - `--SendMsg 1`: 1 to send msg, 0 not send - token path: /home/collaborator/ems/json/LineNotifyToken.txt - CLI: - 查看: `sudo crontab -l` - edit: `sudo crontab -e` 北水處接收資料的server設定 --- ## 廠商需求 :::warning 需要防火牆開啟 140.118.122.118 兩個對外 port port 10688/UDP 接收資料 --> 他們進去後會弄一個小小的網頁做為查看端口是否開啟 port 3306/TCP 資料維護用 --> 要作為MySQL的端口使用 ::: ### 開啟兩個對外 port > $ sudo iptables -I INPUT -p udp --dport 10688 -j ACCEPT > $ sudo iptables -I INPUT -p tcp --dport 3306 -j ACCEPT 查看端口是否開放 > $ sudo iptables -L -n ![](https://i.imgur.com/Kx4S5Az.png) - port 10688 小小的網頁(需要連接其他外網) ![](https://i.imgur.com/B7ou5Jn.png) ## MySQL ### 安裝 MySQL 分別為伺服端、客戶端以及開發中一些MySQL資料庫的函式庫 > $ sudo apt-get install mysql-server > $ sudo apt install mysql-client > $ sudo apt install libmysqlclient-dev ### 測試資料庫是否安裝成功 安裝netstat > $ sudo apt-get install net-tools netstat 的功用是顯示通訊協定統計資料以及目前的TCP/IP 網路連線,所以我們要使用它來查看已安裝好的 MySQL 是否有連線監聽。 透過 netstat 指令來查看 MySQL 是否安裝成功 > $ sudo netstat -tap | grep mysql ### 另外建立一個透過密碼驗證登入的使用者 >$ sudo mysql * 透過 CREATE 語法建立使用者 localhost 是指定這個使用者可以登入的來源只有本機; % 則是指所有來源皆可 (這邊帳密問Ren) > CREATE USER 'user_name'@'localhost' IDENTIFIED BY 'password'; > CREATE USER 'user_name'@'%' IDENTIFIED BY 'password'; * 透過 SELECT 語法確認使用者已經成功被建立: > SELECT user, authentication_string, plugin, host FROM mysql.user WHERE user = 'user_name'; ![](https://i.imgur.com/S8umOQL.png) ### 設置 MySQL 允許遠端訪問 編輯 mysqld.cnf > $ sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf 將 `bind-address = 127.0.0.1` 註解起來 設定好對外連接的port (此port須為TCP) 完成後鍵盤輸入 :wq 儲存並退出 vim ![](https://i.imgur.com/2sMp8F8.png) * 嘗試登入 >$ mysql -u user_name -p * 執行授權命令 在 MySQL 環境下執行授權命令(授權給遠程任何電腦登錄資料庫) 由於要直接給予全部操作的權限,所以是 ALL privileges ,如果不需要全部操作的權限、例如只需要查詢或插入資料,則可以改成對應的 SELECT 、INSERT 等,而 WordPress 是給予權限的資料庫名稱,改為 * 則可以給予使用者所有資料庫的權限 >GRANT ALL PRIVILEGES ON *.* TO 'user_name'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION; * 更新設定 >flush privileges; * 退出 MySQL 服務 >exit * 重啟 MySQL 完成並生效所有的設定 >service mysql restart ### 為廠商建立DB > CREATE DATABASE mdph; 只針對該DB給予廠商權限 > GRANT ALL PRIVILEGES ON WordPress.* TO 'user_name'@'localhost'; 查看所有DB > SHOW DATABASES; ![](https://i.imgur.com/vzzfBL6.png) ### 用他們的帳戶登入MySQL且直連為他們創建的DB >$ mysql -u ems -p mdph 四周間九支水表的程式運行紀錄 --- [四周間九支水表的程式運行紀錄](https://hackmd.io/@RenJhang/HJ1ygsnYK) 直飲台 DS API Document --- [直飲台 DS API Document](https://hackmd.io/U1pTK7nkSGGxctDbUPFUGw) Drinking Station Question: --- https://hackmd.io/@RenJhang/rywgHIE6d DS 此計畫合作相關人員資料 --- ## 北水處 黃先生 ![](https://i.imgur.com/fFeYjIr.png =400x200) ## 弓銓 李經理 ![](https://i.imgur.com/EdSs4TG.jpg =400x200) ## 弓銓 楊先生 ![](https://i.imgur.com/gVM0wAE.jpg =400x200) Deploy DrinkingStation API process --- ## Master Node <font color="#f00">**寫程式要放上pod的人從這裡開始看**</font> **First of All: Have a docker hub account !** ### Step 1 : Use the command to build the bin file - Login the server >$ `cd /home/smartcampus/yaml/drinking_station/` - 如果有舊的執行檔,把舊的執行檔刪掉,再build一次,生出新的執行檔 >$ rm drinking_station - build (這個執行檔的名稱會依據所屬資料夾的名稱進行命名) >$ `go build -tags netgo --ldflags '-extldflags "-lm -lstdc++ -static"'` ### Step 1 : Dockerfile (只有第一次要包Image的時候要建) * 用 alpine 的 Go 語言 Image 來編譯出執行檔 * 7799 is the port of the pod * Because mongo db is build on the pod, **"mongo-0.mongo.mongo.svc.cluster.local:27017"** is the pod URL. * golang code 裡面讀的環境變數是docker file裡面的環境變數 * 解決時差問題 * 把執行檔xinxing加到這個路徑,這個路徑是docker的路徑 * ENTRYPOINT: Define the default command that will be executed when the container is running. * EXPOSE 指 container 對外的port,在與外界溝通時使用。還是7799,轉成5409則是另外再轉的 <font color="#f00">這邊所有的`xinxing_analysis`同時指的是包成的執行檔以及路徑</font> ``` FROM golang:alpine ENV EXPORTER_PORT ":7799" ENV MONGO_URL "mongo-0.mongo.mongo.svc.cluster.local:27017" ENV MONGO_URL2 "mongo-1.mongo.mongo.svc.cluster.local:27017" ENV MONGO_URL3 "mongo-2.mongo.mongo.svc.cluster.local:27017" ENV DATABASE "admin" ENV USERNAME "admin" ENV PASSWORD "bmwee8097218" RUN apk --no-cache add tzdata && \ ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ echo "Asia/Shanghai" > /etc/timezone ADD drinking_station /usr/bin/drinking_station ENTRYPOINT ["drinking_station"] EXPOSE $EXPORTER_PORT ``` **Build image** drinking_station是取的image的名子,直接把舊的蓋掉就可以了 >$ sudo docker build -t drinking_station_api . **Tag image** 把他做tag,取名子為renxjhang/drinking_station_api 用來傳到個人的docker hub (用push) 要抓下來用的話則要pull 新的版本就加一: v1改成v2 ...這樣 >$ sudo docker tag drinking_station_api renxjhang/drinking_station_api:v1 >$ sudo docker images **Push到docker hub** - 登出 docker目前的帳號 >$ sudo docker logout - 登入自己的帳號 >$ sudo docker login - 把Image Push到自己的docker hub(ex. "xiehuangjun/"是黃鈞的repository) >$ sudo docker push renxjhang/drinking_station_api:v1 - 如果你建的Image檔不在Server裡,就跟黃鈞說要怎麼pull你的Image檔就好,如果有在server裡就把像面途中橘色框框的東西告訴黃鈞就好 ex. `renxjhang/drinking_station_api:v1` <font color="#f00">※所有Image要跑都要把Image Push到docker hub上才能跑</font> <font color="#f00">**寫程式要放上pod的人做到這裡**</font> 直飲台 Drinking station 設計用圖 --- https://hackmd.io/@RenJhang/Bk6K55E9_ Meeting Minute --- [Meeting Minute](https://hackmd.io/@RenJhang/HJSE6-ZYO) 更多資料 --- [直飲台 DS API Document](https://hackmd.io/U1pTK7nkSGGxctDbUPFUGw) [Drinking Station Question](https://hackmd.io/@RenJhang/rywgHIE6d) [此計畫合作相關人員](https://hackmd.io/@RenJhang/rkUwI0Ybt) [Deploy DrinkingStation API process](https://hackmd.io/@RenJhang/BJkuCFDkF) [北水處接收資料的server設定](https://hackmd.io/BpCfvJkNSy-nKIVB7VqKmA) [直飲台 Drinking station 設計用圖](https://hackmd.io/@RenJhang/Bk6K55E9_)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully