隱藏 Nginx Web Server 版本

Nginx Web Server 在找不到預設首頁時,會出現如下的圖

畫面上會出現使用的 Web Server 種類及版本[@more@]隱藏方式:CentOS 7.x
1. 先備份原設定檔
# cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.$(date +%F)

2. 在 nginx.conf  設定檔中加入 server_tokens off; 設定
# /bin/sed -i ‘/root         /usr/share/nginx/html;/a        server_tokens off;’ /etc/nginx/nginx.conf

3. 重新啟動 Nginx Web Server
# systemctl restart nginx

4. 就不會再出現版本號碼了,但還是會出現 Web Server 種類,想到的解決方式可能是把 404 網頁換掉

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

參考 [CentOS 7] 整合 Nginx、MariaDB、PHP 7 組成 LEMP Server ~ IT 技術家,整合完成 Nginx+MariaDB+PHP Server 安裝光碟。
光碟開機畫面,預設取消倒數

預設只要三個步驟:分割硬碟、設定網路、設定 root 密碼。
客製化內容:
1. 預設安裝 Nginx Web Server / PHP / MariaDB SQL Server,並啟動 Nginx Web Server 及 MariaDB SQL Server
2. 新增一些 Nginx Web Server 與 PHP 的連結設定
3. 修改 php 設定,包含:上傳的檔案大小到 200M,時區改成 Asis/Taipei……等等。
4. 套件更新到 2016-01-18
5. 套件更新伺服器改成頭城國小
6. 每天早上 6 點對時

修改 CentOS i386/arm 套件庫來源

因為有更新的需求,所以自行在學校 mirror 一份。
# du -hs /var/ftp/Linux/CentOS
97G     /var/ftp/Linux/CentOS

修改套件庫來源
1. 備份原檔
# cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.$(date +%F)[@more@]2. 修改 CentOS-Base.repo
# sed -i ‘s|^baseurl=http://mirror.centos.org/altarch|baseurl=ftp://140.111.74.109/Linux/CentOS/altarch|’ /etc/yum.repos.d/CentOS-Base.repo

3. 清除舊有及更新
# yum clean all;yum update

CentOS 6.x 套件自動更新

1. 安裝 yum-cron 套件
# yum install yum-cron

2. 備份設定檔 /etc/sysconfig/yum-cron
# cp /etc/sysconfig/yum-cron /etc/sysconfig/yum-cron.$(date +%F)

3. 修改設定檔 /etc/sysconfig/yum-cron
# sed -i “s|^MAILTO=|MAILTO= your@email.com|” /etc/sysconfig/yum-cron
# sed -i “s|^CHECK_ONLY=no|CHECK_ONLY=yes|” /etc/sysconfig/yum-cron[@more@]4. 設定開機時啟動
# chkconfig –level 35 yum-cron on

5. 啟動 yum-cron 服務
# service yum-cron start
正在啟用每晚的 yum 更新:                                  [  確定  ]

CentOS 7.x 套件自動更新

一般來說,個人比較不建議讓系統自動更新,因為在第一時間做套件更新,有時候會發生難以復原的災難,所以一般我的做法是讓系統去檢查是否有套件要做更新,如果有的話,利用 mail 通知,再由管理者決定是否要立即做更新。

1. 安裝 yum-cron 套件
# yum install yum-cron

2. 備份設定檔
# cp /etc/yum/yum-cron.conf /etc/yum/yum-cron.conf.$(date +%F)
# cp /etc/yum/yum-cron-hourly.conf /etc/yum/yum-cron-hourly.conf.$(date +%F)[@more@]3. 設定 mail 通知的對象
# sed -i “s|^email_to = root|email_to = your@email.com|” /etc/yum/yum-cron.conf

4. /etc/yum/yum-cron.conf 的其它設定
有下載或更新套件時通知管理者
# sed -i ‘s|^update_messages = no|update_messages = yes|’ /etc/yum/yum-cron.conf
是否自動下載套件的更新檔(個人設定 no)
# sed -i ‘s|^download_updates = no|download_updates = yes|’ /etc/yum/yum-cron.conf
是否自動安裝套件的更新檔(個人設定 no)
# sed -i ‘s|^apply_updates = no|apply_updates = yes|’ /etc/yum/yum-cron.conf
利用 email 通知管理者
# sed -i ‘s|^emit_via = stdio|emit_via = email|’ /etc/yum/yum-cron.conf

5. /etc/yum/yum-cron-hourly.conf 的設定
# sed -i “s|^email_to = root|email_to = your@email.com|” /etc/yum/yum-cron-hourly.conf
設定更新的類別
# sed -i ‘s|^update_cmd = default|update_cmd = security|’ /etc/yum/yum-cron-hourly.conf
# sed -i ‘s|^update_messages = no|update_messages = yes|’ /etc/yum/yum-cron-hourly.conf
# sed -i ‘s|^emit_via = stdio|emit_via = email|’ /etc/yum/yum-cron-hourly.conf

6. 重新啟動 yum-cron 服務
# systemctl restart yum-cron.service 

解決 CentOS 7.x arm Cubie Truck autofs 無法自動掛載目錄的問題

在 Cubie Truck CentOS 7.x arm 啟用 autofs 服務後,發現一直無法自動掛載 NAS 分享的 NFS 服務。
# cd /mnt/nasnfs/bk
-bash: cd: /mnt/nasnfs/bk: No such file or directory

檢查 autofs 開機後是否有啟動
# systemctl is-enabled autofs
enabled

檢查 autofs 是否有正確啟動
# systemctl status autofs
● autofs.service – Automounts filesystems on demand
   Loaded: loaded (/usr/lib/systemd/system/autofs.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2016-01-08 18:41:31 CST; 19min ago
 Main PID: 10463 (automount)
   CGroup: /system.slice/autofs.service
           mq10463 /usr/sbin/automount –pid-file /run/autofs.pid

Jan 08 18:41:30 bk systemd[1]: Starting Automounts filesystems on demand…
Jan 08 18:41:31 bk systemd[1]: Started Automounts filesystems on demand.[@more@]想要手動測試一下,所以尋找一下是否有 showmount 指令
# which showmount
/usr/bin/which: no showmount in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)

補安裝 nfs-utils 套件
# yum install nfs-utils

問題就解決了,原來是少安裝了 nfs-utils 套件!

解決 CentOS 7.x arm Cubie Truck 啟用 autofs 服務時出現的錯誤訊息

在 Cubie Truck CentOS 7.x arm 啟用 autofs 服務時出現下面的錯誤訊息:
# grep auto /var/log/messages
automount[9370]: lookup_read_master: lookup(nisplus): couldn’t locate nis+ table auto.master

檢查 autofs 執行狀態
# systemctl status autofs
● autofs.service – Automounts filesystems on demand
   Loaded: loaded (/usr/lib/systemd/system/autofs.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2016-01-08 17:25:19 CST; 6s ago
  Process: 9662 ExecStart=/usr/sbin/automount $OPTIONS –pid-file /run/autofs.pid (code=exited, status=0/SUCCESS)
 Main PID: 9664 (automount)
   CGroup: /system.slice/autofs.service
           mq9664 /usr/sbin/automount –pid-file /run/autofs.pid

Jan 08 17:25:19 bk systemd[1]: Starting Automounts filesystems on demand…
Jan 08 17:25:19 bk automount[9664]: lookup_read_master: lookup(nisplus): couldn’t locate nis+ table auto.master
Jan 08 17:25:19 bk systemd[1]: Started Automounts filesystems on demand.[@more@]解決方式:
參考文章:Linux : automount: lookup_read_master: couldn’t locate nis+ table auto.master | ITechLounge.net

1. 備份原檔
# cp /etc/auto.master /etc/auto.master.$(date +%F)

2. 將 /etc/auto.master 中的 +auto.master 前面的 + 移除
# sed -i ‘s/+auto.master/auto.master/’ /etc/auto.master

3. 重新啟動 autofs 服務
# systemctl restart autofs

客製化 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