IPv4 及 IPv6 的連線順序 – Windows 篇

Windows 平台也有這樣的問題,尤其是在連政府單位網頁時,常常有學校的行政人員向我反應連線速度非常緩慢,之前我的直覺就是,這應該是 IPv6 的問題,所以解決的方式有二個,一個是把 Windows 的 IPv6 關閉,另一個則是先用 nslookup 查出網站的 IP,然後再以 IP 連線。
關閉 IPv6

先查詢 IP

[@more@]解決方式:參考 使用 IPv6 DualStack 連線速度變慢 @ 黃昏的甘蔗 :: 隨意窩 Xuite日誌

1. 以系統管理者身份執行 命令提示字元,查詢連線順序
    netsh interface ipv6 show prefixpolicies
    IPv4 ::ffff:0:0/96 的順序是 35

這時候系統是以 IPv6 為優先,以 ping www.ilc.edu.tw 為例

2. 修改順序,讓 IPv4 優先,數字越大,優先性愈高
    netsh interface ipv6 set prefixpolicy ::ffff:0:0/96 60 4

這時候再 ping www.ilc.edu.tw 就是以 IPv4 為優先

改回來
netsh interface ipv6 set prefixpolicy ::ffff:0:0/96 35 4

IPv4 及 IPv6 的連線順序 – Linux 篇

因為上級的要求,所以學校的電腦絕大部都會設定有 IPv6,尤其是 Server 的部分。但這造成一個問題,就是電腦在網路連線時,常常會以 IPv6 為優先連線,如果對方有提供 IPv6 的相關資訊。
如:Debain / Ubuntu 更新時的 free.nchc.org.tw
# host free.nchc.org.tw
free.nchc.org.tw has address 211.73.64.9
free.nchc.org.tw has IPv6 address 2001:e10:3c00:8::e274

所以在做 apt-get update 連線時,會先以 IPv6 連線,等到 IPv6 無法連線時,再改以 IPv4 連線,但這一個過程中,已耗費了一些時間。
# apt-get update
0% [Connecting to free.nchc.org.tw (2001:e10:3c00:8::e274)]

….
Ign http://free.nchc.org.tw trusty/multiverse Translation-en_US
Ign http://free.nchc.org.tw trusty/restricted Translation-en_US
Ign http://free.nchc.org.tw trusty/universe Translation-en_US
Reading package lists… Done[@more@]解決方式:參考 使用 IPv6 DualStack 連線速度變慢 @ 黃昏的甘蔗 :: 隨意窩 Xuite日誌
在 Linux 中,以 Ubuntu 14.04.1 Server 為例
1. 備份設定檔 /etc/gai.conf
# cp /etc/gai.conf /etc/gai.conf.$(date +%F)

2. 修改 /etc/gai.conf
# vim /etc/gai.conf
加入下面的設定
label ::1/128       0
label ::/0          1
label 2002::/16     2
label ::/96         3
label ::ffff:0:0/96 4
precedence  ::ffff:0:0/96       60
precedence  ::1/128       50
precedence  ::/0          40
precedence  2002::/16     30
precedence ::/96          20

3. 進行測試,系統就會直接以 IPv4 連線,速度就會就多了!
# apt-get update
Ign http://free.nchc.org.tw trusty InRelease
Hit http://free.nchc.org.tw trusty-updates InRelease
Hit http://free.nchc.org.tw trusty-backports InRelease
Hit http://free.nchc.org.tw trusty-security InRelease
Hit http://free.nchc.org.tw trusty Release.gpg

客製化 CentOS 7.2-1511 x86 Server 安裝光碟

順手完成 CentOS 7.2-1511 x86 Server 安裝光碟
取消時間倒數,預設為 Install CentOS 7

預設只要三個步驟:分割硬碟、設定網路、設定 root 密碼。
客製化內容:
1. 預設安裝 Apache Web Server / PHP / MariaDB SQL Server,並啟動 Apache Web Server 及 MariaDB SQL Server
2. 新增一些 Apache Web Server 的安全性設定
3. MariaDB MySQL Server 修改成 UTF-8 的使用環境
4. 修改 php 設定,包含:上傳的檔案大小到 200M,時區改成 Asis/Taipei……等等。
5. 套件更新到 2016_01_01
6. 每天早上 6 點對時

crontab 工作排程的寫法

普通的用法
分 時 日 月 星期幾 命令
如:
# 每天早上 03:30 備份資料到 NAS
30 3 * * * /usr/local/bin/backuptonas > /dev/null 2>&1
# 每 5 分鐘檢查一次 Squid Proxy Server 的狀態
*/5 * * * * /usr/local/bin/check_squid > /dev/null 2>&1

另外一些比較特別的用法,參考:實用 crontab 寫法 | Linux 技術手札
@reboot: 在每次開機時執行。
@yearly: 等同 0 0 1 1 * 寫法,即每年一月一日零時零分。
@annually: 與 @yearly 相同。
@monthly: 在每月一號零時零分執行。
@weekly: 在星期天零時零分執行。 Run once a week, “0 0 * * 0″.
@daily: 每天零時零分。
@midnight: 與 @daily 相同。
@hourly: 每小時零分執行。

在 Cubie Truck 上安裝 CentOS 7.2.1511 arm 版

本文章參考:Raspberry Pi 的基礎 – 安裝 CentOS 7 for ARM ~ IT 技術家
沒有使用原本 Cubie Truck 內建的 Nand 記憶體,改用 T-Flash 記憶卡。
登入帳號及密碼:root / centos

1. 登入之後,先修改密碼
# passwd
Changing password for user root.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.[@more@]

2. 查看內附的說明檔
# cat ~/README
== CentOS 7 userland ==

If you want to automatically resize your / partition, just type the following (as root user):
touch /.rootfs-repartition
systemctl reboot

3. 擴展 root 分割區
# touch /.rootfs-repartition

4. 重新啟動電腦
# systemctl reboot

原本的 T-Flash 記憶卡分割
# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        980M     0  980M   0% /dev
tmpfs          1005M     0 1005M   0% /dev/shm
tmpfs          1005M   17M  989M   2% /run
tmpfs          1005M     0 1005M   0% /sys/fs/cgroup
/dev/mmcblk0p3  2.0G  746M  1.1G  41% /
/dev/mmcblk0p1  283M  134M  134M  51% /boot
tmpfs           201M     0  201M   0% /run/user/0

擴展之後
# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        982M     0  982M   0% /dev
tmpfs          1007M     0 1007M   0% /dev/shm
tmpfs          1007M   17M  991M   2% /run
tmpfs          1007M     0 1007M   0% /sys/fs/cgroup
/dev/mmcblk0p3  6.3G  747M  5.3G  13% /
/dev/mmcblk0p1  283M  134M  134M  51% /boot
tmpfs           202M     0  202M   0% /run/user/0

5. 更新套件
# yum -y update

6. 安裝一些常用但缺少的套件
# yum install vim mlocate which bind-utils ntpdate

7. 設定時區及對時
原本的時區
# date
Thu Jan  1 08:23:09 CST 1970

把時區改成 Asia/Taipei
# /usr/bin/timedatectl set-timezone Asia/Taipei

更改之後
# date
Fri Jan  1 20:10:36 CST 2016

對時
# /usr/sbin/ntpdate -s time.stdtime.gov.tw
# /usr/sbin/hwclock -w

加入工作排程
# echo “0 6 * * * /usr/sbin/ntpdate -s time.stdtime.gov.tw > /dev/null 2>&1;/usr/sbin/hwclock -w > /dev/null 2>&1” >> /var/spool/cron/root

8. 設定語系
# /usr/bin/localectl set-locale LANG=en_US.utf8
檢查設定
# /usr/bin/localectl status
   System Locale: LANG=en_US.utf8
       VC Keymap: n/a
      X11 Layout: n/a

讓 Cacti 能正常顯示中文

OS:Debian 8.0 jessie
cacti:0.8.8b
安裝完 cacti 之後發現無法呈現中文,輸入中文之後,都會變成 ??

在網路上搜尋了一下,找到下面的文章:
在 Cacti 中顯示中文 | .K.T.’s Blog
電腦中心 | 讓cacti的圖正常出現中文[@more@]底下是設定的步驟:
1. 修改 /usr/share/cacti/site/lib/functions.php
# vim /usr/share/cacti/site/lib/functions.php
在 <?php 下方加入下面一行
setlocale(LC_CTYPE,”zh_TW.UTF-8″);

2. 安裝中文字形
# apt-get install ttf-wqy-microhei ttf-wqy-zenhei fonts-arphic-bkai00mp fonts-arphic-bsmi00lp

3. 加入字型的支援
# /usr/bin/fc-cache -v -f

做了以上的設定還是不行

4. 檢查 MySQL Server 的編碼設定
# /usr/bin/mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 124
Server version: 5.5.44-0+deb8u1 (Raspbian)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the current input statement.

mysql> show variables like ‘char%’;

如果發現有 latin1,代表資料庫編碼要做設定

5. 修改 MySQL Server 設定,加入以下的設定
# vim /etc/mysql/my.cnf
[client]
default-character-set=utf8

[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
init-connect=’SET NAMES utf8′

[mysql]
default-character-set=utf8

6. 重新啟動 MySQL Server
# systemctl restart mysql

7. 重新檢查 MySQL Server 資料庫編碼
# /usr/bin/mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 124
Server version: 5.5.44-0+deb8u1 (Raspbian)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the current input statement.

mysql> show variables like ‘char%’;

8. 匯出原 cacti 資料庫
# /usr/bin/mysqldump -u root -p cacti > /root/cacti.sql –default-character-set=latin1

9. 將匯出檔案的 latin1 全部改成 utf8
# sed -i ‘s/latin1/utf8/’ /root/cacti.sql

10. 重新匯入
# /usr/bin/mysql -u root -p /root/cacti < cacti.sql –default-character-set=utf8

終於可以正常顯示中文了!

CentOS 7 arm 版本

在使用 Raspberry Pi / Banana Pi / CubieTurck 這些控制板時,覺得比較困擾的是,它支援的 Linux 大部分都是 Arch Linux / Debian / Ubuntu …等等,個人比較習慣的 CentOS 卻一直沒有釋出相對的版本。終於在 2015 年末 、2016 年初時,盼到了 CentOS 支援的版本。
CentOS 7 arm 版本下載路徑:
http://mirror.centos.org/altarch/7.2.1511/isos/armhfp/

看檔案名稱,似乎有支援的是 BananaPi / CubieTruck / Raspberry Pi 2

更詳細的介紹可以參考下列網站:
Raspberry Pi 的基礎 – 安裝 CentOS 7 for ARM ~ IT 技術家
CentOS 7 AMR版正式發布:支持樹莓派2/香蕉派/CubieTruck - 今日頭條

目前手上還有一塊閒置的 Banana Pi,有空的話再來仔細測試看看!

CentOS 7.x i386 版

在 CentOS 7.x Mirror 的站台上似乎只找到支援 x86_64 平台的版本,x86 的版本似乎不再支援,偶然在查詢的時候,發現了  CentOS 7.x 有支援 i386 的版本,這個版本是 CentOS AltArch 特別興趣小組 所建立及維護的其它平台,共有支援 i686、aarch64、armhp、ppc64、ppc64le 等版本。

CentOS 7.2.1511 i386 版本下載:
http://mirror.centos.org/altarch/7.2.1511/isos/i386/

安裝起來和 CentOS 7.2.1511 x86_64 版本並無太大的不同

會需要 i386 版本是因為有些舊的機器,因為受限於硬體,所以只能安裝 i386 的版本。

修改 Raspberry Pi Raspbian Jessie Lite 套件庫來源

Raspberry Pi Raspbian 套件庫的更新來源,是系統自動幫我們依回應速度決定要連線的鏡像站,有時候會連線到國外去,速度有些緩慢,這時如果直接指定國內的網站來源,速度會快一些。
本篇文章參考:Raspberry Pi 的基礎 – 系統設定的調教 ~ IT 技術家
1. 備份原設定檔
# cp /etc/apt/sources.list /etc/apt/sources.list.$(date +%F)[@more@]2. 修改套件庫來源
改成國家高速網路中心
# sed -i ‘s”http://mirrordirector.raspbian.org/raspbian/”http://free.nchc.org.tw/raspbian/raspbian/”‘ /etc/apt/sources.list
或 元智大學
# sed -i ‘s”http://mirrordirector.raspbian.org/raspbian/”http://ftp.cse.yzu.edu.tw/raspbian/raspbian/”‘ /etc/apt/sources.list

3. 清除原有的 Cache
# apt-get clean all

4. 更新套件庫來源
# apt-get update
Hit http://archive.raspberrypi.org jessie InRelease
Hit http://archive.raspberrypi.org jessie/main armhf Packages
Hit http://archive.raspberrypi.org jessie/ui armhf Packages
Ign http://archive.raspberrypi.org jessie/main Translation-en_GB
Ign http://archive.raspberrypi.org jessie/main Translation-en
Ign http://archive.raspberrypi.org jessie/ui Translation-en_GB
Ign http://archive.raspberrypi.org jessie/ui Translation-en
Get:1 http://free.nchc.org.tw jessie InRelease [15.0 kB]
Get:2 http://free.nchc.org.tw jessie/main armhf Packages [8,962 kB]
Get:3 http://free.nchc.org.tw jessie/contrib armhf Packages [37.5 kB]
Get:4 http://free.nchc.org.tw jessie/non-free armhf Packages [70.2 kB]
Get:5 http://free.nchc.org.tw jessie/rpi armhf Packages [1,356 B]
Ign http://free.nchc.org.tw jessie/contrib Translation-en_GB
Ign http://free.nchc.org.tw jessie/contrib Translation-en
Ign http://free.nchc.org.tw jessie/main Translation-en_GB
Ign http://free.nchc.org.tw jessie/main Translation-en
Ign http://free.nchc.org.tw jessie/non-free Translation-en_GB
Ign http://free.nchc.org.tw jessie/non-free Translation-en
Ign http://free.nchc.org.tw jessie/rpi Translation-en_GB
Ign http://free.nchc.org.tw jessie/rpi Translation-en
Fetched 9,086 kB in 2min 38s (57.5 kB/s)
Reading package lists… Done