顯示具有 server 標籤的文章。 顯示所有文章
顯示具有 server 標籤的文章。 顯示所有文章

12月 02, 2024

開源遠端桌面閘道(Apache Guacamole)

Apache Guacamole

A clientless remote desktop gateway. It supports standard protocols like VNC, RDP, and SSH. We call it clientless because no plugins or client software are required. Guacamole is installed on a server, all you need to access your desktops is a web browser.

遠端桌面閘道(RD Gateway)支援 RDP 及 SSH 協定;使用者透過瀏覽器可直接存取遠端桌面,無需設定。

9月 18, 2024

自建 Uptime Kuma 監測平台

安裝 Node.js 與 PM2(Process Management)
# apt-get -y update
# apt-get install -y nodejs npm git
# npm install pm2 -g
# pm2 install pm2-logrotate
安裝 Uptime Kuma
# git clone https://github.com/louislam/uptime-kuma.git
# cd uptime-kuma
# npm run setup
# pm2 start server/server.js --name uptime-kuma
進行初次設定 http://localhost:3001

1月 04, 2024

常用 git 指令與自建 Gitea Server

在 Windows 環境下
  • git 個人設定值存放於 C:\Users\account\.gitconfig
  • ssh 個人公私錀存放於 C:\Users\account\.ssh\
如果要產生公私錀,可以透過 PowerShell 執行 ssh-keygen

初始資訊設定(作者名與郵件)與查看設定值:
git config --global user.name "Foo Bar"
git config --global user.email foo@bar.com

git config --global --list
git config --global --list --show-origin
git 上傳方式有 HTTPS 與 SSH 兩種:

1. 透過 HTTPS 傳輸相對簡單,直接將帳號密碼附在 URL 內即可,但因有密碼外露問題,所以 GitHub 採用 Personal access tokens 作為取代;這是一個短天期的通關碼(token),讓共同參與成員可以對源碼庫進行操作,首次上傳會出現提示要求輸入通關碼
2. 使用 SSH 應當是較為安全的管道,在原始碼上傳前,需預先部署公鑰在遠端伺服器(GitHub或Gitea),本地端推送(PULL)時則出示私鑰進行授權。所以記得使用 ssh-keygen 產生公私鑰放在家目錄 [.ssh] 資料夾。

[HTTPS]
git init
git checkout -b main                                   // 建立並切換到 main 分支
git add .                                              // 加入檔案到 staging
git commit -m "first commit"                           // 加到本地 repository
git remote add origin https://example.com/user/foo.git // git remote add [remote-name] [remote-url]
git push -u origin main                                // 推送本地分支(main)到遠端位址(origin)
[SSH]
git init
git checkout -b main
git add README.md
git commit -m "first commit"
git remote add origin git@github.com:user/foo.git      // 透過 SSH 上傳需佈建公鑰(id_rsa.pub)在遠端
git push -u origin main
[其他常用指令]
git log  // 列出提交歷史
git status  // 列出狀態
git remote -v  // 列出遠端位址
git remote set-url origin   // 更改遠端倉庫位址對應

12月 27, 2023

Oracle 雲端免費資源(Cloud Always Free)

Oracle Cloud 相較於 Google Cloud Platform(GCP) 除了同樣提供免費運算資源外,機房區域多了東京可以選擇,對於亞太區傳輸延遲顯得更有優勢。另外 Oracle Cloud 登入強制啟用 2FA(Oracle Mobile Authenticator) 認證!

The Home Region(家鄉區)
When you sign up for Oracle Cloud Infrastructure, Oracle creates a tenancy for you in one region. This is your home region. Your home region is where your IAM resources are defined. Your home region contains your account information and identity resources.It is not changeable after your tenancy is provisioned. (區域列表)
Always Free Resources
All Oracle Cloud Infrastructure accounts (whether free or paid) have a set of resources that are free of charge in the home region of the tenancy, for the life of the account. These resources display the Always Free label in the Console (for Ampere A1 Compute shapes, see Compute). (圖例)
Compute(免費運算節點只能在家鄉區建立!)
All tenancies get a set of Always Free resources in the Compute service for creating compute virtual machine (VM) instances. You must create the Always Free compute instances in your home region.
  • Micro instances (AMD processor): All tenancies get up to two Always Free VM instances using the VM.Standard.E2.1.Micro shape, which has an AMD processor.(節點規格, 流量計價)
  • Ampere A1 Compute instances (Arm processor): All tenancies get the first 3,000 OCPU hours and 18,000 GB hours per month for free for VM instances using the VM.Standard.A1.Flex shape, which has an Arm processor.
Idle Compute Instances(閒置的節點會被收回)
Idle Always Free compute instances may be reclaimed by Oracle. Oracle will deem virtual machine and bare metal compute instances as idle if, during a 7-day period, the following are true:
  • CPU utilization for the 95th percentile is less than 20%
  • Network utilization is less than 20%
  • Memory utilization is less than 20% (applies to A1 shapes only)

10月 29, 2014

匯入「100萬筆」記錄至 MySQL 資料庫

手上的樣本檔有150萬筆資料量,檔案(csv格式)大小約100MB,用 phpMyAdmin 匯入當然是失敗!硬著頭皮看有什麼指令可用...

(1) 因為安全考量 MySQL 預設關閉從檔案匯入資料,所以先調整 my.ini 設定檔:
[mysql]
local-infile=1
[mysqld]
local-infile=1
(2) 建立資料庫(parkDB)後,再建立表格(parkTable)存放記錄:
'第一欄位序號(SN)作為主鍵並具遞增性質
CREATE TABLE parkTable
( SN integer AUTO_INCREMENT PRIMARY KEY ,
  PARK_DATE varchar(10), PARK_TIME varchar(10),
  CAR_NO varchar(10), BRAND varchar(20),
  COLOR varchar(20) );
(3) 從檔案匯入資料庫
# mysql -u root -p
mysql> use parkDB
mysql> LOAD DATA LOCAL INFILE 'SOURCE.csv' INTO TABLE parkTable
    -> FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n'
    -> (PARK_DATE, PARK_TIME, CAR_NO, BRAND, COLOR);
參數相關說明:
  • 從檔案 SOURCE.csv 匯入資料到表格(parkTable)
  • 欄位區分是以逗號(,)來作識別。例如資料 A,B,C 看作三欄。
  • 每欄資料是用雙引號(")圍起來。例如資料 "XYZ-123"。
  • 換行符號是 "\n"
  • 匯入資料對應欄位為 (PARK_DATE, PARK_TIME ...)
(4) 資料量很大時,為加快查詢請記得建立索引。
'索引欄位 CAR_NO
CREATE INDEX idx_CAR_NO ON parkTable (CAR_NO);

8月 26, 2014

設定 Uniform Server 環境參數

Uniform Server Zero(UniServerZ) 是Windows環境下的 WAMP 組合,系統在設計上將所有組態檔安置在 \UniServerZ\home\us_config\ 目錄下。欲更改 Apache 所用連接埠與目錄見:us_user.ini 設定檔
[USER]
AP_PORT=8080
AP_SSL_PORT=8081
US_SERVERNAME=localhost
US_ROOTF_WWW=./www
US_ROOTF_SSL=./ssl
另個與存取相關的是:/www/.htaccess 中 Order Deny,Allow 範圍,記得把用戶IP位址加入。
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
Allow from "Client_IP"
若要調整 PHP 其他環境參數,見控制面板 [PHP]-[Edit Basic Configuration]
  • Display Errors:顯示除錯訊息
  • Memory
  • Post Size
  • Upload Size
若要啟用或停用內建模組則是 [PHP Modules Enable/Disable]
  • php_xdebug:除錯模組

5月 01, 2014

linux-dash 主機狀態看板

linux-dash : 在 GitHub 上的鏈結
A drop-in, low-overhead monitoring web dashboard for a linux machine.
(php 語言寫成,用來取得主機資訊)
  • A beautiful web-based dashboard for monitoring server info
  • Live, on-demand monitoring of RAM, Load, Uptime, Disk Allocation, Users and many more system stats
  • Click and drag to re-arrange widgets
需求環境:
  1. Linux (Debian, Ubuntu)
  2. php5-json
  3. Nginx / Apache2 / Lighttpd

3月 04, 2014

設定 BIND9 伺服器

BIND9 有點吃記憶體,如果要跑在小型機器上的話,最好改用其他替他方案(如:NSD, Name Server Daemon),稍微講一下 BIND 裝好之後要設定的部份。這邊假設:委派 sub.domain.net 網域給 dns.domain.net 解析。

1. 在 named.conf.options 中加入全域設定
options {
  forwarders {
    8.8.8.8;
  };
  recursion no;
  version "[SECURED]";
};
2. 在 named.conf.local 加入代管 Zone 名稱
zone "sub.domain.net" in {
  type master;
  file "/etc/bind/db.sub.domain.net";
};
3. 新增 Zone 檔案 (即:db.sub.domain.net)
$TTL 604800
@    IN  SOA   dns.domain.net. root.localhost. (
     2014030301   ; Serial
     1200         ; Refresh
     7200         ; Retry
     2419200      ; Expire
     86400 )      ; Negative Cache TTL
;  
@     IN  NS    dns.domain.net.
@     IN  MX    10  mail
@     IN  A     [ IP of sub.domain.net ]
dns   IN  A     [ IP of dns.domian.net ]
mail  IN  A     [ IP of Mail Server ]
4. 重新載入 BIND 服務

1月 02, 2014

[MySQL] Can't create database 'performance_schema'

在執行完 MySQL upgrade 後就炸掉了...
/etc/mysql/debian-start[4802]: ERROR 1007 (HY000) at line 160: Can't create database 'performance_schema'; database exists
修正方式 :
# rm -rf /var/lib/mysql/performance_schema
# mysql_upgrade -u root -p

11月 19, 2013

MySQL 效能分析調教工具

MySQL 效能調教工具:
- MySQLTuner (使用 perl 寫的分析工具,2011)
- MySQL Performance Tuning Primer Script (2011)

9月 08, 2013

run OpenWebMail on Debian 7


# apt-get install build-essential

# cpan HTML::Template

# wget http://openwebmail.acatysmoof.com/download/current/openwebmail-current.tar.gz

# touch /var/log/openwebmail.log

# chown root:mail /var/log/openwebmail.log

# tar -zxvf openwebmail-current.tar.gz

# vim cgi-bin/openwebmail/etc/openwebmail.conf

    ow_cgidir               /var/www/cgi-bin/openwebmail
    ow_cgiurl               /cgi-bin/openwebmail
    ow_htmldir              /var/www/openwebmail
    ow_htmlurl              /openwebmail
  
# cp cgi-bin/openwebmail/etc/defaults/auth_unix.conf  cgi-bin/openwebmail/etc/

# vim cgi-bin/openwebmail/etc/auth_unix.conf
  
    passwdfile_plaintext    /etc/passwd
    passwdfile_encrypted    /etc/shadow
    passwdmkdb              none
  
# cp cgi-bin/openwebmail/etc/defaults/dbm.conf  cgi-bin/openwebmail/etc/

# vim cgi-bin/openwebmail/etc/dbm.conf

    dbm_ext           .pag
    dbmopen_ext       none
    dbmopen_haslock   no
  
# mv cgi-bin/openwebmail/ /var/www/cgi-bin/
# mv data/openwebmail/ /var/www/

# cd /var/www/cgi-bin/openwebmail/
# chmod 4755 ./misc/tools/wrapsuid/wrapsuid.pl
# ./misc/tools/wrapsuid/wrapsuid.pl /var/www/cgi-bin/openwebmail/openwebmail*.pl
# chmod 600 ./misc/tools/wrapsuid/wrapsuid.pl
# chmod 4755 openwebmail*.pl
# ./openwebmail-tool.pl --init

8月 21, 2013

PHP 本身內建的 Web Server

PHP 從 5.4 版起就內建了簡易型的 web server:
Built-in web server
As of PHP 5.4.0, the CLI SAPI provides a built-in web server. This web server is designed for developmental purposes only, and should not be used in production.
啟動的方式是這樣:
(1)監聽來自任何介面的請求:php -S  0.0.0.0:80 -t <DOCUMENT_ROOT>
(2)監聽來自本機的請求:php -S  localhost:80 -t <DOCUMENT_ROOT>
至於 php 執行檔的取得應該相當容易,由官方網站下載或第三方封裝好的架站機。

為求容量精簡,特地找了一個由 Uniform Server 包裝好的版本:UniServerMicro,整個壓縮檔不到 10MB。經過測試 DokuWiki 可以該環境正常運作。

如果要讓 php 內建的 web server 在開機後在「背景」執行,可以透過下列手法達成:

建立 run_PHP.bat 內容:
php.exe -S 0.0.0.0:80 -t C:\www_root
建立 run_PHP.vbs 內容:
Set WinScriptHost = CreateObject("WScript.Shell")
WinScriptHost.Run Chr(34) & "run_PHP.bat" & Chr(34), 0
Set WinScriptHost = Nothing
在開機時啟動上面的 vbs 即可。

8月 08, 2013

LimeSurvey 線上問卷系統

線上問卷系統 (PHP環境)
LimeSurvey (formerly PHPSurveyor) is a free and open source on-line survey application written in PHP based on a MySQL, PostgreSQL or MSSQL database, distributed under the GNU General Public License.
幾個系統的運作邏輯要清楚:
  1. 問卷產生程序:「建立問卷→建立題組→建立題目」這是最基本的構成,最後才能啟用問卷蒐集資料。
  2. 問卷啟用時,系統會詢問是否切換成「封閉型問卷」,所謂封閉型問卷是指 Non-Anonymous Survey:受訪者需使用邀請代碼(token)通關後才能開始作答,意味要先行寄發邀請代碼給受訪者。這點務必留意。 
使用上大致沒什麼問題,除了一點…統計圖表是亂碼!直條圖、圓餅圖、折線圖內的中文字全都是□□□。因為系統沒有中文字型。

翻一下 fonts/fireflysung - Chinese.ttf.txt 這個檔案:
For package size reasons the Firefly Sung font to show Chinese characters in the statistics graphs is not included with LimeSurvey. Please download it from...
下載中文字型,改一下 /application/config/config-defaults.php 檔案:
$config['chartfontfile']='fireflysung.ttf';    //原值是auto
 然後如果圖表的字太小
$config['chartfontsize'] =12;   // 原值是10
 最後記得清掉 /tmp 目錄下的 png 快取圖檔。

10月 02, 2012

專案管理(或協同平台)軟體

幾個專案管理軟體(或協同作業平台),可以丟在網路上跑:

1. Collabtive
加強版的 TODO,多人協作、提供檔案上傳

2. ProjectPier
待評

3. phpCollab
可用來作為 bug/ticket trace 系統

4. DotProject
較適合用來作為專案進度管理系統

5. PHProjekt
基本上就是群組軟體(Groupware)系統,功能強大無所不包(40MB),兼具專案管理、團隊溝通等功能。

6. Simple Groupware
群組軟體

8月 19, 2012

Screen: No more PTY's. Sorry could not find a PTY

今天在設定一台 VPS 時碰到的狀況,一般用戶無法正常執行 screen 套件,錯誤訊息是:
No more PTY's. Sorry could not find a PTY.
解法:
(1) 先確認只有一般用戶會碰到這個狀況,而 root 沒這個問題。
(2) 檢查一下 pty* 檔案的權限
$ ls -l /dev/ptmx
crw-rw-rw- 1 root tty 5, 2 Jul 31 07:35 /dev/ptmx
$ ls -l /dev/pty*
crw-rw-rw- 1 root tty 2, 0 Jul 31 01:19 /dev/ptyp0
一般用戶應都能寫入,所以並非 device 檔的毛病。
(3) 這邊跟 Setuid 的運作原理有關
# chmod u=rwxs,g=rx,o=rx /usr/lib/pt_chown
# chown root:root /usr/lib/pt_chown

7月 27, 2012

Nginx 與 spawn-fcgi 的設定

設定 .php 的解析方式

這邊記得要用 Unix domain socket 的模式,比較不會有 "502 Bad Gateway" 錯誤產生。

# vim /sites-enabled/default
server {
 charset utf-8;
 location ~ \.php$ 
 {
  try_files $uri $uri/ =404;
  fastcgi_index index.php;
  include /etc/nginx/fastcgi_params;
  fastcgi_pass unix:/tmp/php-cgi.socket;
 #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  fastcgi_param SCRIPT_FILENAME /var/www/$fastcgi_script_name;
 }
}

使用 spawn-fcgi 來管理 php-cgi 數目

spawn-fcgi 已經成為獨立套件,在 Debian 中可以透過 apt 來安裝。
# sudo apt-get install spawn-fcgi

丟個 script 到 /etc/init.d/ 目錄下,讓 php-fcgi 開機時就能自己啟動。
# vim /etc/init.d/php-fastcgi
# chmod +x php-fastcgi
# update-rc.d -f php-fastcgi defaults 2

內容如下:
#!/bin/bash
### BEGIN INIT INFO
# Provides:          php-fastcgi
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      1
# Short-Description: Run the PHP FastCGI
# Description:       PHP FastCGI environment for Nginx web server
#
### END INIT INFO

CHILDREN=1
PHP5=/usr/bin/php5-cgi
SOCKET=/tmp/php-cgi.socket
PIDFILE=/var/run/php-cgi.pid

USER=www-data
GROUP=www-data
SPAWN=/usr/bin/spawn-fcgi

OPT="-s $SOCKET -P $PIDFILE -f $PHP5  \ 
     -u $USER -g $GROUP -C $CHILDREN"

do_start() {
  start-stop-daemon --start --quiet --exec $SPAWN -- $OPT
}
do_stop() {
  start-stop-daemon --stop  --quiet --pidfile $PIDFILE
}
do_restart() {
  start-stop-daemon --stop  --quiet --pidfile $PIDFILE
  sleep 1
  start-stop-daemon --start --quiet --exec $SPAWN -- $OPT
}

case "$1" in
  start)
    do_start;;
  stop)
    do_stop;;
  restart)
    do_restart;;
  *)
    echo "Usage: php-fastcgi {start|stop|restart}" ;;
esac

5月 19, 2012

懶人架站機 (XAMPP , Uniform Server)

在 Windows 平台上的懶人架站機 (Apache+MySQL+PHP):

(1) XAMPP (Version 1.7.7)
Apache 2.2.21 / MySQL 5.5.16 / PHP 5.3.8
- 先執行 setup_xampp.bat 
- 再進入操控面板 xampp-control.exe
(2) Uniform Server (Version 8.5.4)
Apache 2.4.2 / MySQL 5.5.24 / PHP 5.4.3
- 執行 Start_as_program.exe
[注意]
1.新版需使用 VC11 函式庫 (最低系統要求是 Windows 7 / Windows Server 2008 以上),系統錯誤提示為「不是正確 Win32 應用程式」
2.執行 php.exe 時若出現「系統無法執行指定的程式」表示未安裝 VC9 Libraries:
Visual C++ 2008 Redistributable Package (x86)

5月 18, 2012

不用資料庫也能跑的 PHP 軟體

使用 PHP 語言,搭配 SQLite 或者跟本不需要資料庫:

1. 論壇:FluxBB
2. 網誌:FlatPressBliteTypechoChyrp
3. Wiki:DokuWiki

3月 18, 2012

Exim4 與 SquirrelMail 設定


設定 Exim4


​# apt-get install dovecot-common dovecot-imapd dovecot-pop3d

# vim /etc/dovecot/dovecot.conf 加入
protocols = imap imaps pop3 pop3s
# vim /etc/exim4/update-exim4.conf.conf
dc_eximconfig_configtype='internet'
# 接收 user@mail.server.net 的信件
dc_other_hostnames='mail.server.net'
# 接受各方連線
dc_local_interfaces='0.0.0.0'
dc_readhost=''
dc_relay_domains=''
dc_minimaldns='false'
dc_relay_nets=''
dc_smarthost=''
CFILEMODE='644'
dc_use_split_config='false'
dc_hide_mailname=''
dc_mailname_in_oh='true'
dc_localdelivery='mail_spool'
# exim4 -bt user (檢測郵件派送路徑)
R: system_aliases for user@mail.server.net
R: userforward for user@mail.server.net
R: procmail for user@mail.server.net
R: maildrop for user@mail.server.net
R: lowuid_aliases for user@mail.server.net (UID 1000)
R: local_user for user@mail.server.net
user@mail.server.net
router = local_user, transport = mail_spool


設定 SquirrelMail


1. 至 SquirrelMail 網站下載最新版

2. 在 SquirrelMail Configuration - Languages 下面(控制信件內容)
Default Language : zh_TW
Default Charset : UTF-8
3. 在 functions/i18n.php 下面改成 (控制信件列表)
$languages['zh_TW']['NAME'] = 'Chinese Trad';
$languages['zh_TW']['CHARSET'] = 'big5';
$languages['zh_TW']['LOCALE'] = array('zh_TW.UTF-8', 'zh_TW.big5');
$languages['tw']['ALIAS'] = 'zh_TW';

12月 25, 2010

lighttpd rewrite rule for wordpress 3

新版的 Wordpress 3 架構,讓原有的 rewrite rule 無法正常運作。所以要改成下列:
$HTTP["host"] == "www.site.com" {
url.rewrite-final = (

# Exclude some directories from rewriting
"^/(wp-admin|wp-includes|wp-content|gallery2)/(.*)" => "$0",

# Exclude .php files at root from rewriting
"^/(.*.php)" => "$0",
"^/sitemap.xml" => "$0" ,

# Handle permalinks and feeds
"^/(.*)$" => "/index.php/$1"
)
}