前幾天租了 Digitalocean, 五年沒寫 Blog, 雖然都在 Twitter, Facebook 上、雖然有 Tumblr, WordPress.com 可用,但還是想租台機器自己來玩一下,不過實在太久沒自己 hosting 很多東西都忘了,這篇要寫一些租了 VPS 之後做的一些微調設定筆記。
建立虛擬記憶體
由於這台 VPS 只是開來跑 Blog 而已,所以建立的 droplet 選最便宜方案 512 MB RAM,得先開個 swap 做保險。
sudo swapon -s
# 先檢查有無存在的 swap
sudo dd if=/dev/zero of=/swapfile bs=1M count=1024
# 割 swap
sudo chown root:root /swapfile
sudo chmod 0600 /swapfile
# 權限確保
sudo mkswap /swapfile
# 把 /swap 這個檔案格式化為 swap 的檔案格式
sudo swapon /swapfile
# 啟動 /swap
sudo vi /etc/fstab
# 寫進下面這段進 /etc/fstab 每次啟動時都掛載 swap
/swapfile none swap sw 0 0
echo 10 | sudo tee /proc/sys/vm/swappiness
echo vm.swappiness = 10 | sudo tee -a /etc/sysctl.conf
用 logrotate 定期切割 Apache log 檔
這 blog 是建立在 vhost 上,然後 log 又獨立到個別的子目錄下,所以需要額外去設定。
sudo vi /etc/logrotate.conf
# WordPress
/你/的/目/錄/logs/*.log {
daily
missingok
rotate 7
size 1M
dateext
compress
delaycompress
notifempty
copytruncate
sharedscripts
postrotate
/etc/init.d/apache2 reload > /dev/null
endscript
}
daily 每天整理,其他還有 weekly, monthly, yearly
missingok 允許 log 檔不存在
rotate 7 保留 7 次的分割
size 1M 大小超過 1M 就執行分割,單位可以是 1024, 100k, 4M, 1G
dateext 用日期來建立分割檔名,而非流水號
compress 壓縮分割,預設用 gzip
delaycompress 延後壓縮直到下一次 rotate
notifempty 如果 log 是空的就不執行
copytruncate 以複製清空的方式分割 log,這樣可以用不到 postrotate 設定
prerotate/endscript 分割前要執行的指令
postrotate/endscript 分割後要執行的指令
最後來測試是否設定正確,記得執行後這指令要去 log 目錄檢查一下。
sudo logrotate -f /etc/logrotate.conf
# WordPress
/你/的/目/錄/logs/*.log {
daily
missingok
rotate 7
size 1M
dateext
compress
delaycompress
notifempty
copytruncate
sharedscripts
postrotate
/etc/init.d/apache2 reload > /dev/null
endscript
}
參考學長 othree 的設定
sudo apt-get install expect
vi ptt.sh
chmod +x ptt.sh
#!/usr/bin/expect
# 設定 timeout 時間,以秒為單位。
set timeout 20
# 啟動
spawn ssh bbsu@ptt.cc
# 將 my_id 與 my_password 分別置換成您的帳號與密碼。
set ID 帳號
set PASSWD 密碼
# 當輸出 guest,便輸入帳號與密碼,超過時限則直接離開,以及輸入完後跳到「請按任意鍵」畫面時自動 enter 進入。
expect "guest" { send "$ID\r$PASSWD\r" } timeout { exit }
expect "任意鍵" { send "\r" } timeout { exit }
#把畫面轉交給使用者控制,並每隔三百秒送出 " "
interact timeout 300 { send " " }
exit
irssi 設定
sudo vi .irssi/config
servers = (
{
address = "irc.freenode.net";
chatnet = "Freenode";
port = "6667";
use_ssl = "no";
ssl_verify = "no";
autoconnect = "yes";
},
{
address = "irc.debian.org";
chatnet = "Debian";
port = "6667";
use_ssl = "no";
ssl_verify = "no";
autoconnect = "yes";
},
);
chatnets = {
Freenode = {
type = "IRC";
nick = “MLChen";
autosendcmd = "/^msg nickserv identify 暱稱密碼; wait 2000";
};
Debian = {
type = "IRC";
nick = "MLChen";
autosendcmd = "/^msg nickserv identify 暱稱密碼; wait 2000";
};
channels = (
{ name = "#bsdchat"; chatnet = "Freenode"; autojoin = "yes"; },
{ name = "#osxchat"; chatnet = "Freenode"; autojoin = "yes"; },
{ name = "#osdc.tw"; chatnet = "Freenode"; autojoin = "yes"; },
{ name = "#coscup"; chatnet = "Freenode"; autojoin = "yes"; },
{ name = "#hitcon"; chatnet = "Freenode"; autojoin = "yes"; },
{ name = "#tossug"; chatnet = "Freenode"; autojoin = "yes"; },
{ name = "#ubuntu-tw"; chatnet = "Freenode"; autojoin = "yes"; },
{ name = "#happydesigner"; chatnet = "Freenode"; autojoin = "yes"; },
{ name = "#dot"; chatnet = "Debian"; autojoin = "yes"; },
{ name = "#ruby-tw"; chatnet = "Freenode"; autojoin = "yes"; },
{ name = "#python.tw"; chatnet = "Freenode"; autojoin = "yes"; },
{ name = "#g0v.tw"; chatnet = "Freenode"; autojoin = "yes"; },
);
settings = {
core = {
real_name = "Meng-Lien Chen";
user_name = "MLChen";
nick = "MLChen";
};
"fe-text" = { actlist_sort = "refnum"; };
type = "IRC";
};
};
settings = {
core = { real_name = "MLChen"; user_name = "mlchen"; nick = "mlchen"; };
"fe-text" = { actlist_sort = "refnum"; };
"fe-common/core" = {
theme = "default";
beep_when_window_active = "yes";
beep_when_away = "yes";
beep_msg_level = "MSGS NOTICES DCC DCCMSGS HILIGH";
bell_beeps = "yes";
};
};
IRC Client 改用 Weechat
看到 ijliao 長輩推薦改用 weechat, 剛剛有空時馬上裝來玩,以及參考他這篇介紹和官網指引。
sudo vi .weechat/irc.conf
[server]
freenode.addresses = "chat.freenode.net/6697"
freenode.nicks = "MLChen"
freenode.username = "MLChen"
freenode.realname = "Meng-Lien Chen"
freenode.command = "/msg nickserv identify 密碼"
freenode.autojoin = "#bsdchat,#osxchat,#osdc.tw,#coscup,#hitcon,#tossug,#ubuntu-tw,#happydesigner,#ruby-tw,#python.tw,#g0v.tw"
debian.addresses = "irc.debian.org/6667"
debian.nicks = "MLChen"
debian.username = "MLChen"
debian.realname = "Meng-Lien Chen"
debian.command = "/msg nickserv identify 密碼"
debian.autojoin = "#dot
把 join/part/quit 訊息關掉
/filter add irc_smart * irc_smart_filter *
更改 Ubuntu 系統時間
$ sudo tzselect
# 選擇所在時區
$ sudo cp /usr/share/zoneinfo/Asia/Taipei /etc/localtime
# 更換時區檔
$ sudo ntpdate time.stdtime.gov.tw
# 對時
$ sudo hwclock -w
# 將時間寫入 BIOS
$ sudo crontab -e
@daily /usr/sbin/ntpdate time.stdtime.gov.tw > /dev/null
# 將對時動作寫進 crontab 每天做一次
停用 WordPress 文章版本控制以及自動儲存。
有微強迫症的我依舊還是遇到 08 年第一次復台問題,一樣的作法去編輯 wp-config.php 停用 Revisions 文章版本控制跟停用 Autosave 自動儲存。
define('WP_POST_REVISIONS', false );
define('AUTOSAVE_INTERVAL', 86400 );
// AUTOSAVE 修改成一天的時間做為變相的不自動存。
但不知道為什麼沒 work, 所以只好暫時找了外掛安裝:Super Switch
WordPress 迴響不顯示自己的留言及 trackback
sudo vi 路/徑/wp-includes/default-widgets.php
搜尋 $comments = get_comments, 並加入這段最後 type, user_id 那兩段 code:
$comments = get_comments( apply_filters( 'widget_comments_args', array(
'number' => $number,
'status' => 'approve',
'post_status' => 'publish'
'type' => 'comment',
'user_id' => 0
) ) );
隨時補記。
別用 irssi 了, 快改用 weechat 吧~~
馬上跟流行了,感謝長輩。