# DocuSky 架設程序 (移機) <!-- 標籤 --> ###### tags: `主機維護` <!-- 內文編輯更新資訊,若有更動此份文件內容,請務必更新此項資訊 --> > [name=Sih-Pin Lai, 賴思頻] > [time=Wed, Feb 3, 2021 4:59 PM] <!-- 筆記正文開始 --> **原始文件** * [DocuSky 移機 SOP](https://hackmd.io/@6vl-R1QtRl-LuttqpoUdVA/HJqYcwNJH) * [移機注意事項](https://hackmd.io/@6vl-R1QtRl-LuttqpoUdVA/Sykr9wVyB) * [在 Ubuntu16.04 建立 DocuSky](https://hackmd.io/@6vl-R1QtRl-LuttqpoUdVA/ryP1nPN1r) * [DocuSky VM README](https://hackmd.io/@6vl-R1QtRl-LuttqpoUdVA/H1vXnvNkB) # Windows :::warning **移機注意事項** * **作業前** * 與一梅姐討論移機時間 * 於 DocuSky 網站的最新消息**公告移機作業時間** * **主要作業**:[Step2](#Step-2-資料轉移)、[Step4](#Step-4-程式修改) * **作業後**:請教屹灵學長或莉雯學姊,將 docusky 的 domain name 指到新的機器上 ::: :::danger :warning: 小心 docusky 裡面路徑,C 槽和 D 槽的差別。 :warning: ::: :::info :computer: **執行環境 (計中正式機)** )(2021.02.01) **作業系統**:Windows Server 2016 Standard **硬體**: ![](https://i.imgur.com/4UMUfLS.png) **XAMPP for Windows**: ![](https://i.imgur.com/iul3NYu.png) ::: ## Step 1: 資料轉移 ### :one: 放上 DocuSky 檔案 (主要為 DocuSky/ ) ## Step 2: XAMPP 安裝與設定 ### :one: 以系統管理員身分**安裝 xampp** ### :two: 修改設定: XAMPP Control Panel > Apache > Config **httpd.conf** ```conf ## modify DocumentRoot "C:/xampp/htdocs" → DocumentRoot "C:/WebRoot" <Directory "C:/xampp/htdocs"> → <Directory "C:/WebRoot"> ``` **httpd-ssl.conf** ```conf ## modify DocumentRoot "C:/xampp/htdocs" → DocumentRoot "C:/WebRoot" ``` **php.ini** ```conf ## modify include_path=C:\xampp\php\PEAR → include_path=".;C:\xampp\php;C:\xampp\php\pear;C:\WebRoot;" openssl.cafile → openssl.cafile="C:\WebRoot\DocuSky\include\phpmailer\cacert.pem" ``` ### :three: 修改設定: XAMPP Control Panel > MySQL > Config **my.ini** ```conf ## modify max_allowed_packet = 256M (100000M) innodb_buffer_pool_size = 512M (12000M) ``` ### :four: 重啟 Apache (重新導向至 Doucsky 所在資料夾) ## Step 3: MySQL 設定 **資料表清單** :::spoiler - comments - data_file - db_schema_version - docusky_provider - doc_xml_format_name - job_queue - log_api_access - log_sys_action - log_user_action - news - open_database - open_db_corpus - open_db_corpus_datafile - open_db_corpus_doc_datafile_att - open_db_corpus_fa_spotlight - open_db_corpus_feature - open_db_refdata - open_document - open_document_feature - open_document_subdoc - open_document_user_notes - open_doc_closure - open_doc_corpus_group - open_doc_doc_link - open_doc_doc_similarity - open_doc_extension - open_doc_vertex - reg_web_tool - startup_package - sys_info_announcement - tool_file - tool_package - tool_package_file - user_database - user_db_corpus - user_db_corpus_datafile - user_db_corpus_doc_datafile_att - user_db_corpus_fa_spotlight - user_db_corpus_feature - user_db_refdata - user_db_sharing_scheme - user_document - user_document_feature - user_document_subdoc - user_document_user_notes - user_doc_closure - user_doc_doc_link - user_doc_doc_similarity - user_doc_extension - user_doc_vertex - user_favorite_reg_tool - user_friendship - user_friend_accessible_db - user_group - user_open_package_reg - user_profile ::: ### :one: 從舊系統轉出資料表:XAMPP Control Panel > Shell (2-3 hr) ```mysql /* 每張表獨立轉成一個檔案,table_name 為資料表名稱 */ mysqldump --hex-blob -u root -h 127.0.0.1 docusky <table_name> table_name.sql ``` ### :two: 將資料表匯入新系統:XAMPP Control Panel > Shell (9 hr) ```mysql /* 每張表獨立匯入,最大的表會需要 8 小時 */ mysql -u root -h 127.0.0.1 --default-character-set=utf8 docusky < table_name.sql ``` ### :three: 創建 MySQL 使用者帳密:XAMPP Control Panel > Shell ```mysql /* create account */ mysql -u root` CREATE USER 'thdl'@'localhost' IDENTIFIED BY 'thdl'; GRANT ALL PRIVILEGES ON *.* TO 'thdl'@'localhost' WITH GRANT OPTION; GRANT ALL PRIVILEGES ON `thdl\_%`.* TO 'thdl'@'localhost'; ``` ## Step 4: 程式修改 ### :one: C:\WebRoot\DocuSky\include\sphinxapi.php ```php // line 430 function SphinxClient() {} → function __construct() {} ``` ### :two: C:\WebRoot\DocuSky\include\phpmailer\PHPMailerAutoload.php ```php // line 45 function __autoload($classname) {} → function spl_autoload_register($classname) {} ``` ## Step 5: PHP 設定 ### :one: 修改 php.ini:XAMPP Control Panel > Apache > Config ```conf ## 處理 file_get_contents 的問題,ori: 128M memory_limit=512M (1024M) ## ori: 8M post_max_size=512M ## ori: 2M upload_max_filesize=128M ## uncomment,for Geo_Port & DocuGIS extension=tidy ``` ## Step 6: 網址設定 ### :one: 檢查每個頁面的 digital.ntu.edu ### :two: 新增 .htaccess 檔案:C:\WebRoot\ ```conf ## 更改所有進入此 server 的路徑到 docusky.org.tw RewriteEngine On RewriteCond %{HTTP_HOST} !^docusky.org.tw$ [NC] RewriteRule ^(.*)$ https://docusky.org.tw/$1 [L,R=301] ``` ## Step 7: 背景程式設定 * 需補上 windows 工作排程設定,否則不會執行建庫的動作 * 使用 windows 工作排程器設定每五分鐘執行 :::info 名稱:Invoke DocuSky background process 觸發程序:每五分鐘執行一次 ![](https://i.imgur.com/NxcldOG.png) 動作: ```bash C:\xampp\php\php.exe C:\WebRoot\DocuSky\background_offline_job_compuation.php 30 ``` ![](https://i.imgur.com/H1rYRlw.png) ::: ## Step 8: 建立 DocuSky 檢索索引表 * 建立 sphinx 的索引表 (需問杜博士詳細如何執行) * conf 檔內 searchd 加入 windows service # Linux :::info :computer: **執行環境** **作業系統**:Ubuntu 16.04 / [載點](https://www.ubuntu-tw.org/modules/tinyd0/) **VM 規格**: * 硬碟:> 200G * 記憶體:> 4G * 處理器數量:> 0 * 處理器核數:> 4 ::: ## Step 1: 安裝 XAMPP ### :one: 下載 xampp (php5) 安裝檔 ```bash ## download cd ~/Downloads wget https://www.apachefriends.org/xampp-files/5.6.38/xampp-linux-x64-5.6.38-0-installer.run ``` ### :two: 安裝程式 ```bash ## install sudo chmod +x xampp-linux-x64-5.6.38-0-installer.run sudo ./xampp-linux-x64-5.6.38-0-installer.run ``` ### :three: 啟動 xampp ```bash ## start sudo /opt/lampp/xampp start ``` ## Step 2: 重新導向 FTP 資料夾 ### :one: 修改 config ```bash ## open config file sudo vim /opt/lampp/etc/proftpd.conf ## modify <Directory /opt/lampp/htdocs/*> → <Directory /home/docusky/WebRoot/*> DefaultRoot /opt/lampp/htdocs → DefaultRoot /home/docusky/WebRoot ``` ### :two: 重啟 xampp ```bash ## restart sudo /opt/lampp/xampp restart ``` ### :three: 使用 Filezilla 傳送 Docusky 資料夾 * 帳密:Ubuntu 使用者帳密 * 協定:SFTP - SSH file Transfer Protocol ## Step 3: 開啟 phpmyadmin access remotely 功能 ### :one: 修改 config ```bash ## open config file sudo vim /opt/lampp/etc/extra/httpd-xampp.conf ## modify <Directory "/opt/lampp/phpmyadmin"> AllowOverride AuthConfig Limit # Require local 註解掉此行 Require all granted # 加入這一行 ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var </Directory> ``` ### :two: 重啟 xampp ```bash ## restart sudo /opt/lampp/xampp restart ``` ## Step 4: 設定 WebRoot 路徑 ### :one: 建立 WebRoot 資料夾 ```bash ## build webroot mkdir ~/WebRoot cd ~/WebRoot ## move DocuSky/ into directory mv <Path to DocuSky/> ``` ### :two: 建立 index.html **目的** 將網頁導向 DocuSky/ **指令** ```bash ## install vim (若有可跳過) sudo apt-get install vim -y ## create file index.html vim index.html ``` **內容** ```htmlembedded <html> <head> <meta http-equiv="refresh" content="0;url='DocuSky/index.html'"> </head> </html> ``` ### :three: 修改 XAMPP Apache Config **httpd.conf** ```bash ## open config file sudo vim /opt/lampp/etc/httpd.conf ## modify DocumentRoot "/opt/lampp/htdocs" → DocumentRoot "/home/docusky/WebRoot" <Directory "/opt/lampp/htdocs"> → <Directory "/home/docusky/WebRoot"> ``` **httpd-ssl.conf** ```bash ## open config file sudo vim /opt/lampp/etc/extra/httpd-ssl.conf ## modify DocumentRoot "/opt/lampp/htdocs" → DocumentRoot "/home/docusky/WebRoot" ``` **php.ini** ```bash ## open config file sudo vim /opt/lampp/etc/php.ini ## modify ;include_path = ".:/php/includes" → include_path = ".:/php/includes:/home/docusky/WebRoot" openssl.cafile → openssl.cafile = "/home/docusky/WebRoot/DocuSky/include/phpmailer/cacert.pem ``` **my.cnf** ```bash ## open config file sudo vim /opt/lampp/etc/my.cnf ## modify innodb_log_file_size=1M → innodb_log_file_size=30G max_allowed_packet=512M → max_allowed_packet=30G ``` :::success 在[匯入 sql 時](#-匯入-sql-檔-9-hr)會遇到檔案大小限制 ```bash ERROR 1118 (42000) at line 77: The size of BLOB/TEXT data inserted in one transaction is greater than 10% of redo log size. Increase the redo log size using innodb_log_file_size. ERROR 2006 (HY000) at line 77: MySQL server has gone away ``` ::: ### :four: 重啟 xampp ```bash ## restart sudo /opt/lampp/xampp restart ``` ## Step 5: 重建 DocuSky MySQL 資料庫 ### :one: 建立 thdl 使用者 ```mysql /* enter mysql shell */ sudo /opt/lampp/bin/mysql /* create account */ CREATE USER 'thdl'@'localhost' IDENTIFIED BY 'thdl'; GRANT ALL PRIVILEGES ON *.* TO 'thdl'@'localhost' WITH GRANT OPTION; GRANT ALL PRIVILEGES ON `thdl\_%`.* TO 'thdl'@'localhost'; ``` ### :two: 建立 DocuSky 資料庫 ```mysql /* enter mysql shell */ sudo /opt/lampp/bin/mysql /* create account */ CREATE DATABASE docusky; ``` ### :three: 於原 Windows Server 下載現有資料 (2-3 hr) ```mysql /* 1. open xampp control panel * * 2. open shell * * 3. dump (about 25G, compressed 2G) */ mysqldump --hex-blob -u root -h 127.0.0.1 docusky > docusky.sql ``` ### :four: 匯入 sql 檔 (9 hr) ```bash ## import sql sudo /opt/lampp/bin/mysql -u root -h localhost --default-character-set=utf8 -p docusky < ~/WebRoot/docusky.sql ## press enter (root has no password) (show) Enter password: (enter) ## upload progress check ## 可開啟 http://localhost/phpmyadmin 檢查是否正在上傳 ``` ## Step 6: 設定 DocuSky/ ### :one: 建立 index.html **目的** 將首頁導向 userLogin.php **指令** ```bash ## to dir cd ~/WebRoot/DocuSky/ ## create file index.html vim index.html ``` **內容** ```htmlembedded <html> <head> <meta http-equiv="refresh" content="0;url='userLogin.php'"> </head> </html> ``` ### :two: 確認檔案存在、資料夾非空 ``` DocuSky/ └ ip_config/ └ banned_ip.conf └ valid_ip.conf └ js/ └ js.ui/ └ fonts/ ``` ### :three: 測試進入 DocuSky 網站 (ERROR 疑難排解) #### :question: ```mkdir(): Permission denied``` 更改 DocuSky 權限,目前先以所有權設定成 root:root,與使用權全部開放(777) ```bash ## open authority sudo chown root:root -R ~/WebRoot/DocuSky sudo chmod -R 777 ~/WebRoot/DocuSky ``` #### :question: ```無法讀取 "docusky.USER_PROFILE"``` 讓 mysql 執行 query 時忽略大小寫 ```bash ## open config file sudo vim /opt/lampp/etc/my.cnf ## add under [mysqld] section lower_case_table_names = 1 ## restart xampp sudo /opt/lampp/xampp restart ``` #### :question: 系統會莫名創建或讀取WebApi資料夾 更改路徑名:webApi → WebApi ```bash ## open config file sudo vim ~/WebRoot/DocuSky/include/Config.php ## line 213 self::$web_path_prefix = 'WebApi'; → self::$web_path_prefix = 'webApi'; ``` # Virtual Machine ## Step 1: 下載並安裝 VMware [載點](https://www.vmware.com/products/workstation-pro/workstation-pro-evaluation.html) ## Step 2: 開啟 VM 檔案 **1. 開啟 Virtual Machine** ![](https://i.imgur.com/iRqvpN3.png) **2. 選取 DocuSky VM 檔案** ![](https://i.imgur.com/MXINGhB.png) **3. 啟動 VM** ::: info VMplayer 下面有兩個一樣名字的 VM,浩洋需要的那台的記憶體是 9.2GB,另外一台則是 8.3GB。 ::: ![](https://i.imgur.com/CjBEmvp.png) **4. 使用管理員帳密登入 Windows Server** ## Step 3: 啟動 XAMPP 1. 開啟 XAMPP 2. start "Apache" 3. start "MySQL" ## Step 4: 開啟瀏覽器即可使用 * url: [localhost/DocuSky/]() * 大部分資料已清空,只留下 admin 使用者 ![](https://i.imgur.com/IdtU2W2.jpg)