Rocky Linux 安裝完成後…

變更hostname

# 設定新主機名稱
hostnamectl set-hostname 新的主機名稱
# 查詢新主機名稱
hostnamectl

安裝JDK(非必要,純個人需求)

# 更新所有已安裝的套件
dnf update
# 尋找並列出可安裝的版本
dnf search openjdk
# 安裝
dnf install java-11-openjdk  java-11-openjdk-devel
# 確認java可執行及其版本
java -version

安裝Tomcat (非必要,純個人需求)

# 新增tomcat程式使用帳號
useradd -m -U -d /opt/tomcat -s /bin/false tomcat
# 設定想要安裝的tomcat版本
VERSION=9.0.88
# 取得該tomcat版本的程式壓縮檔
wget https://dlcdn.apache.org/tomcat/tomcat-9/v${VERSION}/bin/apache-tomcat-${VERSION}.tar.gz
# 解壓縮
sudo tar -xf apache-tomcat-${VERSION}.tar.gz -C /opt/tomcat/
# 設定連結,若有新版本修改幅度最小
sudo ln -s /opt/tomcat/apache-tomcat-${VERSION} /opt/tomcat/latest
# 將tomcat目錄的所有權移給tomcat帳號
sudo chown -R tomcat:tomcat /opt/tomcat
# 變更tomcat目錄存取權
sudo chmod -R a+rx /opt/tomcat/

設定tomcat服務

新增並編輯服務設定檔

vi /etc/systemd/system/tomcat.service
[Unit]
Description=Apache Tomcat 9 Servlet container
Wants=network.target
After=network.target

[Service]
Type=forking

User=tomcat
Group=tomcat

Environment="JAVA_HOME=/usr/lib/jvm/jre"
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom"

Environment="CATALINA_BASE=/opt/tomcat/latest"
Environment="CATALINA_HOME=/opt/tomcat/latest"
Environment="CATALINA_PID=/opt/tomcat/latest/temp/tomcat.pid"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"

ExecStart=/opt/tomcat/latest/bin/startup.sh
ExecStop=/opt/tomcat/latest/bin/shutdown.sh
Restart=always

[Install]
WantedBy=multi-user.target

啟動tomcat服務

# 服務重新載入
systemctl daemon-reload
# 將服務設為開機啟動
systemctl enable tomcat --now
# 確認服務狀態
systemctl status tomcat

安裝Apache HTTP Server (非必要,純個人需求)

yum update
# 安裝套件
yum -y install httpd httpd-tools mod_ssl openssl
# 啟動服務
systemctl start httpd
# 查詢服務狀態
systemctl status httpd
在/etc/rc.local新增以下指令
# 讓chkconfig管理httpd
chkconfig --add httpd
# SELinux使用反向代理需要打開網路訪問權限
/usr/sbin/setsebool -P httpd_can_network_connect 1
  • 相關的安裝設定檔應在: /etc/httpd
  • Apache配置檔案: /etc/httpd/conf/httpd.conf
  • Apache模組路徑: /usr/sbin/apachectl
  • web目錄: /var/www/html

安裝CodiMD 2.5.3

  1. 下載CodiMD最新版

  2. 將壓縮檔上傳到 /opt 目錄下並解壓縮

    tar zxvf codimd-2.5.3.tar.gz
    
  3. 安裝 postgres 資料庫

    yum install postgresql-server postgresql-contrib
    postgresql-setup initdb
    systemctl start postgresql
    systemctl enable postgresql
    
    • 進入 PostgreSQL:sudo -u postgres psql

    • 變更密碼: \password //password

    • 查詢 Database:\l>

    • 建立 CodiMD的Database:CREATE DATABASE $codimdDB OWNER postgres;

    • 查詢 user:\du

    • quit:\q

  4. 將目錄改為codimd

    cd /opt/codimd
    # 建立設定檔並進行編輯
    cp config.json.example config.json
    # 執行設定
    bin/setup
    
  5. 匯入現有資料庫

    # 刪除資料庫
    dropdb  -W -U postgres -h localhost $codimdDB
    # 建立空的資料庫
    createdb -W -U postgres -h localhost $codimdDB
    # 匯入舊資料庫
    psql -W -U postgres -h localhost $codimdDB < 備份檔
    
  6. 安裝node套件

    # 以下參數是為解決 node.js 的版本問題,若沒有出現錯誤可以不設
    export NODE_OPTIONS=--openssl-legacy-provider
    # 把專案打包,服務設定檔也要設定
    npm run build
    # 設定此為正式環境
    export NODE_ENV=production
    # 啟動服務
    npm start