Aaron Wu
    • 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
    • Engagement control
    • 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 Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control 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
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    --- title: '伺服器總論 | 建北電資網管傳承' image: https://hackmd.io/_uploads/rJpAHerNn.png --- :::info 本筆記由建電一三學術長吳亞倫製作 若有相關疑慮,可以寄信到 [aaronwu0218@gmail.com](mailto:aaronwu0218@gmail.com) 或是 Discord `AaW#2549` 詢問 ::: :::warning 本筆記當中所有的指令,皆是bash指令,代表其作用範圍為Linux或MacOS作用系統。 如果你是網管但還用windows,~~你很糟糕~~,請去灌linux或是使用wsl。 另外,所有指令當中,如果使用角括號`<>`圍起來的片段,例如`<USERNAME>`,代表這個東西你使用時要視情況自己替換。 ::: 伺服器,全稱網路伺服器,是一種在網路上提供服務的電腦。 以往,建電社辦內部有數台伺服器,運行著社網以及其他網路服務。不過由於建中內部現在不得架設任何網路伺服器,因此目前社辦皆已無相關設備。 ## 北資的伺服器 :::danger 伺服器的主管人為北一女**何雪溱老師**,如果針對伺服器有任何疑慮可以向老師詢問。 另外,如果希望針對裡面內容進行大幅度修改,請==務必向雪溱老師報備之後==才可以進行! 何雪溱老師聯絡方式: email : sjher@gapps.fg.tp.edu.tw ::: 目前,我們是跟北一女中借用了一台伺服器。該伺服器為一台運行在虛擬機上的 Ubuntu Server 20.04 LTS。 ![](https://hackmd.io/_uploads/r1SGl9dDn.png ) 這台伺服器由於是學長們自己維護的,因此,東西的穩定性無法到非常的完整。所以如果要進行任何操作務必要先在別的地方以虛擬機進行確認之後,再著手進行。 ### 現在伺服器有哪些東西 #### 營運中網路服務 以下所有服務皆是使用 docker 架設 1. ISCOJ - 精確地來說,是名稱為iscoj的一個[青島OJ系統](https://github.com/QingdaoU/OnlineJudge)。 - 檔案位置:`/OnlineJudgeDeploy/` - 詳細使用請見 [ISCOJ 伺服器端使用說明](/-lloL9MSTautzUUFW-5M2w) 2. CMS 比賽評測系統 (Contest Management System) - 分為 前台 (port 8888)、後台 (port 8889)、計分版 (port 8890)三大服務 - 檔案位置:`~/cms/`、`/cms_docker_postgresql_data/` 3. 幫python架設的另一個 CMS 比賽評測系統 - 因為一台 CMS 無法一次開設兩場比賽,~~所以我架了兩個~~ - 檔案位置:`~/cmspython/`、`/cms_python_docker_postgresql_data/` #### 未使用之網路服務 1. TIOJ:`~/tioj-new/` 2. OJDL:`~/ojdl2-docker/` 3. 其他在家目錄(`~`aka`/home/fgisc`)資料夾底下的東西 #### 吳亞倫調整過的設定 1. iscoj systemd service - `/etc/systemd/system/iscoj-docker-compose-app.service` 3. nginx 4. certbot 基本上,家目錄裡面的東西(除了cms),很多都是測試用途,可以嘗試看看 但是,根目錄(`/`)底下的資料夾,==不懂的人沒事不要上去亂動!== ### 網域 - 伺服器ip位址:`203.64.52.132` - 網址:`iscoj.fg.tp.edu.tw`、`fgiscoj.fg.tp.edu.tw` - 只有這兩個網址可以使用。因此,如果希望架設更多服務,必須要使用反向代理到subfolder底下。 ### 使用者名稱 使用者名稱為fgisc,可透過sudo具有root權限,請小心使用。 密碼將放置在另外一個檔案教給網管。 ### 連線 - 請使用 ssh 指令進行連線 - 指令:`ssh fgisc@203.64.52.132` - windows 使用者可以去下載 putty - `scp`指令:將檔案複製上去伺服器/複製回來你的電腦 - 教學:https://blog.gtwang.org/linux/linux-scp-command-tutorial-examples/ ### PORT 端口 > 通訊埠(英語:port),又稱為連接埠、端口、協定埠(protocol port)在電腦網路中是一種經由軟體建立的服務,在一個電腦作業系統中扮演通訊的端點(endpoint)。每個通訊埠都會與主機的IP位址及通訊協定關聯。通訊埠以16位元數字來表示,這被稱為通訊埠編號(port number)。 > --- 維基百科 簡單來說,在電腦當中,所有的`服務`都會佔用一到多個端口。 例如,網際網路服務(http)預設的端口是`80`,而`https`是`443`、`ssh`是`22`,小佛用的telnet是`23`。 在我們的伺服器當中,以下port是對外開啟的: - 22: ssh - 80: http - 443: https - 8888、8889、8890: CMS系統 另外可能還有一些別的port,但我沒用過也不確定。 如果你們希望開啟其他的port作為測試用途,例如`8000`,可以請雪臻老師幫忙。 在所有AaW建立過的網際網路服務當中,使用到了以下port: - 平常啟用 - 80:對外所有http - 443:對外所有https - 8000:青島oj的http - 1443:青島oj的https - 8888:CMS 使用者比賽頁面 - 8889:CMS admin - 8890:CMS ranking - 平常未啟用: - 8788/8789/8790:python cms - tioj: 4000 - ojdl: 聽說架起來會在80 port但我沒成功架設過 - translation: 9000,一樣沒成功用過 ![](https://hackmd.io/_uploads/H1DLHjFPh.png) ### nginx 與 反向代理 (reverse proxy) 因為伺服器當中對外開放的port有點少,原本只有80和443。當初我為了要架設cms,所以特地去學反向代理。 在我們伺服器當中,我用了nginx作為反向代理的server。那nginx這個東西蠻強大的,也很複雜,我這裡無法細講太多,有興趣的可以自己再去搜尋。 nginx 配置文件皆位於`/etc/nginx/`資料夾底下。 1. 主配置文件為`/etc/nginx/nginx.conf` 2. ISCOJ與CMS配置文件: - `/etc/nginx/conf.d/iscoj.conf` - 內容解說位於下一段 #### 我的nginx配置文件寫了什麼? ```nginx= ## 上游設定 upstream oj { server 0.0.0.0:1443; keepalive 16; } upstream cms { server 0.0.0.0:8888; keepalive 16; # 以這邊為例 # 底下配置文件當中寫的 https://cms/ 會代理到 port 8888 } upstream cms-admin { server 0.0.0.0:8889; keepalive 8; } upstream cms-rank { server 0.0.0.0:8890; keepalive 8; } upstream cmspython { server 0.0.0.0:8788; keepalive 16; } upstream cmspython-admin { server 0.0.0.0:8789; keepalive 8; } upstream cmspython-rank { server 0.0.0.0:8790; keepalive 8; } # Default server configuration # server { # SSL configuration # listen 443 ssl default_server; listen [::]:443 ssl default_server; # 憑證與金鑰的路徑 ssl_certificate /etc/letsencrypt/live/iscoj.fg.tp.edu.tw/fullchain.pem; # managed by Certbot ssl_certificate_key /etc/letsencrypt/live/iscoj.fg.tp.edu.tw/privkey.pem; # managed by Certbot # Note: You should disable gzip for SSL traffic. # See: https://bugs.debian.org/773332 # # Read up on ssl_ciphers to ensure a secure configuration. # See: https://bugs.debian.org/765782 # # Self signed certs generated by the ssl-cert package # Don't use them in a production server! # # include snippets/snakeoil.conf; root /var/www/html; # 不太重要,因為我們所有東西都是反向代理 # Add index.php to the list if you are using PHP # index index.html index.htm index.nginx-debian.html; server_name iscoj.fg.tp.edu.tw fgiscoj.fg.tp.edu.tw; ## 反向代理區段 # iscoj location / { proxy_pass https://oj/; # 把 IP、Protocol 等 header 都一起送給反向代理的 server proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto; } # 沒有加斜線的要轉址成有斜線,才能正確的反向代理到subfolder location = /cms { return 302 /cms/; } # 反向代理的程式 location /cms/ { proxy_pass http://cms/; } location = /cms/admin { return 302 /cms/admin/; } location /cms/admin/ { proxy_pass http://cms-admin/; } location = /cms/ranking { return 302 /cms/ranking/; } location /cms/ranking/ { proxy_pass http://cms-rank/; proxy_buffering off; } location = /cmspython { return 302 /cmspython/; } location /cmspython/ { proxy_pass http://cmspython/; } location = /cmspython/admin { return 302 /cmspython/admin/; } location /cmspython/admin/ { proxy_pass http://cmspython-admin/; } location = /cmspython/ranking { return 302 /cmspython/ranking/; } location /cmspython/ranking/ { proxy_pass http://cmspython-rank/; proxy_buffering off; } #上機考 得題 location /cms/<ANS> { return 302 https://hackmd.io/_uploads/rJMJQzcNn.png; } location /cms/96 { return 302 https://hackmd.io/@QYi6gllvSum0RZrW3jaysg/Sy75nf9Vn; } location /cms/96/ { return 302 https://hackmd.io/@QYi6gllvSum0RZrW3jaysg/Sy75nf9Vn; } location /cms/<96>/ { return 302 https://hackmd.io/@QYi6gllvSum0RZrW3jaysg/Sy75nf9Vn; } } server { if ($host = iscoj.fg.tp.edu.tw) { return 301 https://$host$request_uri; } # managed by Certbot if ($host = fgiscoj.fg.tp.edu.tw) { return 301 https://$host$request_uri; } # managed by Certbot listen 80 default_server; listen [::]:80 default_server; server_name iscoj.fg.tp.edu.tw fgiscoj.fg.tp.edu.tw; return 404; # managed by Certbot } ``` 如果你們希望更動nginx的配置文件,可以,但請記得要小心&先備份原本的設定檔。 注意,最好不要更動或刪除到我已經配置完的文件。 更動完設定之後,可以用以下指令讓nginx重新啟動: `systemctl restart nginx` ### systemctl 系統服務 這有點複雜,反正就是如果你寫好一個文件指令交給 systemctl (其實應該說交給systemd),他會讓你的程式在電腦背景以“服務”形式在運作。 基本上我額外設定的服務有: 1. nginx 2. certbot自動更新 3. iscoj的開機自動啟用,在iscoj區段會有詳細介紹 #### systemctl 常用指令: > 記得大部分都要sudo,所以請小心使用 - `ststemctl start <SERVICE_NAME>.service` - 啟動`<SERVICE_NAME>` 這個服務,例如`ststemctl start nginx.service` - `ststemctl stop <SERVICE_NAME>.service`:停止這個服務 - `ststemctl restart <SERVICE_NAME>.service`:重啟這個服務 - 其他的自己google,但理論上你只會用到這幾個 #### 自行設定服務 一般來說,在systemctl裡面的服務都是你安裝某個應用程式之後,系統自動建立的。 不過呢,有些時候我們會希望建立自己的服務,例如iscoj那個。 這時候你可以參考這幾篇教學文章來進行。 - https://blog.gtwang.org/linux/linux-create-systemd-service-unit-for-python-echo-server-tutorial-examples/ - https://unix.stackexchange.com/questions/236084/how-do-i-create-a-service-for-a-shell-script-so-i-can-start-and-stop-it-like-a-d - https://medium.com/@benmorel/creating-a-linux-service-with-systemd-611b5c8b91d6 ### [ISCOJ]() ### [CMS]() ### SSL 安全認證 所謂的SSL安全認證,代表這個網站可以被CA認證,擁有https加密連線。原本SSL的認證文件都是透過雪臻老師協助申請取得,但後來雪臻老師提供了一個自動申請憑證的方式:certbot機器人。 #### certbot 老師當初給我的教學是apache版本的,[文件連結](https://www.dropbox.com/s/2yuf427ay7eybh8/%E4%BC%BA%E6%9C%8D%E5%99%A8%E5%AE%89%E8%A3%9D%20SSL%20%E6%86%91%E8%A8%BC%28Ubuntu%29.txt?dl=0) 我自己目前是看這一篇教學設定的: https://blog.hellojcc.tw/setup-https-with-letsencrypt-on-nginx/ 理論上現在設定應該是好的,也有自動四個月更新憑證的設定 但因為我設定完到現在也還不到四個月所以我不確定效果如何。 所以如果到時候憑證有過期可以再跟我聯絡。(理論上會過期的那時候我已經考完學測了) #### 目前檔案路徑 憑證位於`/etc/letsencrypt/live/iscoj.fg.tp.edu.tw`目錄底下,需有root權限才可以瀏覽。 `fullchain.pem`為公鑰,`privkey.pem`是私鑰 ## 如何取得其他伺服器 如果經費可行,推薦你們可以再去找台 VPS 伺服器,拿來練習各種伺服器技巧。也可以用來提供學弟妹練習架設具有後端的網站。 現在網路上的伺服器供應商主要有提供虛擬主機以及 VPS 伺服器兩種不同的商品。其中虛擬主機一般是給你一個panel,不會給你 ssh 權限以及 root 權限。而 VPS 則會給你整台虛擬機伺服器的管理權限。 蘇怡恩當初在有學長姐的那個大FB群公布社網時,有一些學長姐主動來聯繫我,表示願意提供電腦設備或是讓我們租線上VPS來使用。 這邊給大家這位學長的聯絡方式: :::info 建電百四學術長 丁安立 學長 DC: `在在 - 存在先於本質#2035` > 可以幫你們租 VPS,可以幫你們代付只有信用卡能買的東西,可以買些你們需要用來學習的電腦之類的。 > 一年五萬以內那種量級我應該都直接付了 ::: :::info 建電19th 詹依寰 學長 EMAIL: `yihuan.chan@gmail.com` 目前我們 ckefgisc.org 和 ckeisc.org ==網域==的所有人是這一位學長,有事可以聯絡他。 :::

    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