Banana Pi 測試 – Gentoo Linux 安裝 logwatch 寄送系統記錄檔

安裝 logwatch
# emerge –ask logwatch

These are the packages that would be merged, in order:

Calculating dependencies… done!
[ebuild  N     ] dev-perl/Carp-Clan-6.40.0-r1  USE=”{-test}”
[ebuild  N     ] dev-perl/Sys-CPU-0.540.0-r1
[ebuild  N     ] dev-perl/Sys-MemInfo-0.910.0-r1
[ebuild  N     ] virtual/mailx-1
[ebuild  N     ] virtual/cron-0
[ebuild  N     ] dev-perl/DateManip-6.410.0  USE=”{-test}”
[ebuild  N     ] dev-perl/Tie-IxHash-1.230.0  USE=”{-test}”
[ebuild  N     ] dev-perl/Bit-Vector-7.200.0-r1
[ebuild  N     ] dev-perl/Date-Calc-6.300.0-r1
[ebuild  N     ] sys-apps/logwatch-7.4.0_p170-r1

Would you like to merge these packages? [Yes/No]y[@more@]1. 備份原設定檔 /usr/share/logwatch/default.conf/logwatch.conf
# cp /usr/share/logwatch/default.conf/logwatch.conf /usr/share/logwatch/default.conf/logwatch.conf.$(date +%F)

2. 進行修改
# sed -i ‘s/MailTo = root/MailTo = xxxx@gmail.com/’ /usr/share/logwatch/default.conf/logwatch.conf
# sed -i ‘s/MailFrom = Logwatch/MailFrom = Logwatch@nxi.test.ilc.edu.tw/’
/usr/share/logwatch/default.conf/logwatch.conf
# sed -i ‘s/Output = stdout/Output = mail/’
/usr/share/logwatch/default.conf/logwatch.conf
# sed -i ‘s/Detail = Low/Detail = Med/’
/usr/share/logwatch/default.conf/logwatch.conf

3. 執行 logwatch 測試是否能收到信件
# /usr/sbin/logwatch.pl

Banana Pi 測試 – Gentoo Linux 通知系統可升級的套件

列出系統可以升級的套件
# emerge -pv world | grep “[ebuild     U  ]” | awk ‘{print $4}’ | awk -F ‘/’ ‘{print $2}’
procps-3.3.9-r2

列出系統已安裝套件
# emerge -pv world | grep “[ebuild   R    ]” | awk ‘{print $4}’ | awk -F ‘/’ ‘{print $2}’ | head
xz-utils-5.0.8
bzip2-1.0.6-r6
gnuconfig-20140212
which-2.20-r1
baselayout-2.2
patch-2.6.1
os-headers-0
file-5.21
net-tools-1.60_p20130513023548
coreutils-8.21[@more@]利用 gmail 來寄信
1. 安裝 ssmtp 及 mailx
# emerge ssmtp mailx

2. 備份原設定檔 /etc/ssmtp/ssmtp.conf
# cp /etc/ssmtp/ssmtp.conf /etc/ssmtp/ssmtp.conf.$(date +%F)

3. 修改設定檔 /etc/ssmtp/ssmtp.conf
# vim /etc/ssmtp/ssmtp.conf
#root=postmaster

# The place where the mail goes. The actual machine name is required
# no MX records are consulted. Commonly mailhosts are named mail.domain.com
# The example will fit if you are in domain.com and you mailhub is so named.
mailhub=smtp.gmail.com:587
# Where will the mail seem to come from?
#rewriteDomain=y
# The full hostname
#hostname=root-chroot-copy
# 寄件者帳號
AuthUser=xxxx@gmail.com
# 寄件者密碼
AuthPass=xxxx
UseSTARTTLS=YES
FromLineOverride=yes #enables to use mail -r option

4. 更改檔案權限
# chmod 0600 /etc/ssmtp/ssmtp.conf

5. 建立 Script
# cat /usr/lcoal/bin/check-update
#!/bin/bash
emerge -pv world | grep “[ebuild     U  ]” | awk ‘{print $4}’ | awk -F ‘/’ ‘{print $2}’ > /tmp/$(date +%F)
if [ -s /tmp/$(date +%F) ] ;then
   mail -s “Gentoo Linux Updates Available” xxxx@gmail.com < /tmp/$(date +%F)
   rm -rf /tmp/$(date +%F)
else
   rm -rf /tmp/$(date +%F)
fi

6. 更改檔案執行權限
# chmod 700  /usr/lcoal/bin/check-update

7. 排程(每 3 小時執行一次)
# crontab -l
0 3 * * * /usr/lcoal/bin/check-update

Banana Pi 測試 – Gentoo Linux 安裝系統紀錄器

Gentoo Linux 提供許多個系統記錄器的選擇。分別為 sysklogd,它是一個傳統的系統記錄伺服器,syslog-ng ,是一個進階的系統記錄器。
# emerge -s syslog-ng
Searching…
[ Results for search key : syslog-ng ]
[ Applications found : 1 ]

*  app-admin/syslog-ng
      Latest version available: 3.4.8
      Latest version installed: [ Not Installed ]
      Size of files: 3,095 kB
      Homepage:      http://www.balabit.com/network-security/syslog-ng
      Description:   syslog replacement with advanced filtering features
      License:       GPL-2+ LGPL-2.1+

# emerge -s sysklogd
Searching…
[ Results for search key : sysklogd ]
[ Applications found : 1 ]

*  app-admin/sysklogd
      Latest version available: 1.5.1
      Latest version installed: [ Not Installed ]
      Size of files: 112 kB
      Homepage:      http://www.infodrom.org/projects/sysklogd/
      Description:   Standard log daemons
      License:       BSD
[@more@]
安裝系統紀錄器 sysklogd
# emerge sysklogd

啟動 sysklogd
# /etc/init.d/sysklogd start

開機時啟動
# rc-update add sysklogd default

或安裝 syslog-ng 系統紀錄器
# emerge syslog-ng

啟動 sysklogd
# /etc/init.d/syslog-ng start

開機時啟動
# rc-update add syslog-ng default

安裝紀錄檔置換程式
# emerge logrotate

Banaana Pi – Gentoo Linux 套件庫訊息

在做套件更新或安裝時,有時會出現類似下面的訊息
* IMPORTANT: 8 news items need reading for repository ‘gentoo’.
 * Use eselect news to read news items.

在網路上搜尋了一下,在下面的網址找到了解答
Gentoo Taiwan 討論區 • 檢視主題 – 安裝PHP 問題[@more@]
列出這 8 項的項次
# eselect news list
News items:
  [1]      2012-05-21  Portage config-protect-if-modified default
  [2]      2012-11-06  PYTHON_TARGETS deployment
  [3]      2013-06-07  Portage preserve-libs default
  [4]      2013-08-23  Language of messages in emerge logs and output
  [5]      2013-09-27  Separate /usr on Linux requires initramfs
  [6]      2014-06-15  GCC 4.8.3 defaults to -fstack-protector
  [7]      2014-10-26  GCC 4.7 Introduced the New C++11 ABI
  [8]      2014-11-07  Upgrade to udev >= 217 or eudev >= 2.1

列出第一項
# eselect news read 1
2012-05-21-portage-config-protect-if-modified
  Title                     Portage config-protect-if-modified default
  Author                    Zac Medico <zmedico@gentoo.org>
  Posted                    2012-05-21
  Revision                  1

Beginning with sys-apps/portage-2.1.10.61, FEATURES=config-protect-if-modified
is enabled by default. This causes the CONFIG_PROTECT behavior to be skipped
for files that have not been modified since they were installed.

If you would like to disable this behavior by default, then set
FEATURES=”-config-protect-if-modified” in make.conf. See the make.conf(5) man
page for more information about this feature.

列出全部的前 15 行
# eselect news read new | head -15
2012-05-21-portage-config-protect-if-modified
  Title                     Portage config-protect-if-modified default
  Author                    Zac Medico <zmedico@gentoo.org>
  Posted                    2012-05-21
  Revision                  1

Beginning with sys-apps/portage-2.1.10.61, FEATURES=config-protect-if-modified
is enabled by default. This causes the CONFIG_PROTECT behavior to be skipped
for files that have not been modified since they were installed.

If you would like to disable this behavior by default, then set
FEATURES=”-config-protect-if-modified” in make.conf. See the make.conf(5) man
page for more information about this feature.

Banana Pi 測試 – bpi2015-lxde

好久不見的洪博所 Build 的 Banana Pi Image
開機登入畫面
[@more@]1. 桌面環境

2. 安裝的套件
影音

教育

系統工具

網際網路

美工繪圖

辦公

遊戲

附屬應用程式

偏好設定

其它:

使用之後的感想:
優點:
1. 執行速度非常快
2. 該有的軟體幾乎都有了,也有一些是專為教育推廣使用,如:OX 書庫、OX 教學工具、OX 數位測驗庫…等。
3. 螢幕顯示的字體有稍為加大,方便視力不太方便的使用者

個人認為可以改進的地方:
1. 這個 Image 應該是用來做為 demo 使用,因為套件無法做後續更新
    /etc/yum.repos.d 中沒有任何設定

2. 套件及軟體的版本稍舊
    Firefox 17.0.1 版本及 Fedora release 17(Beefy Wiracle)

並無內建安裝任何的外掛程式

3. 網際網路中的 gftp 建議改成 FileZilla,另外增加 Chromium 瀏覽器
4. 好久不見的 oxim 輸入法架構的行列輸入法,目前比較多人使用的應該是行列30,行列40使用的人應該比較少。

整體來說是一個值得期待的版本!

Banana Pi 測試 – Gentoo Linux 設定開機執行的服務

增加服務
語法:
# rc-update add scriptname runlevels
範例:
# rc-update add vixie-cron default
 * service vixie-cron added to runlevel default

刪除服務
語法:
# rc-update del scriptname runlevels
# rc-update del scriptname
範例:
# rc-update del dhcpd default
 * service dhcpd removed from runlevel default

runlevels 可以是 boot / default ….
[@more@]
列出可用的 Script 和運行層級
# rc-update show
             bootmisc | boot
                devfs |                       sysinit
                dmesg |                       sysinit
                 fsck | boot
             hostname | boot
              keymaps | boot
            killprocs |              shutdown
    kmod-static-nodes |                       sysinit
                local |      default
           localmount | boot
             loopback | boot
              modules | boot
             mount-ro |              shutdown
                 mtab | boot
             net.eth0 |      default
             netmount |      default
           ntp-client |      default
               procfs | boot
                 root | boot
            savecache |              shutdown
                 sshd |      default
                 swap | boot
            swapfiles | boot
              swclock | boot
               sysctl | boot
                sysfs |                       sysinit
         termencoding | boot
         tmpfiles.dev |                       sysinit
       tmpfiles.setup | boot
                 udev |                       sysinit
           udev-mount |                       sysinit
              urandom | boot

# rc-status
Runlevel: default
 net.eth0                                                                                             [  started  ]
 ntp-client                                                                                           [  started  ]
 sshd                                                                                                 [  started  ]
 netmount                                                                                             [  started  ]
 local                                                                                                [  started  ]
Dynamic Runlevel: hotplugged
Dynamic Runlevel: needed
Dynamic Runlevel: manual

Banana Pi 測試 – Gentoo Linux 的 rc.local

一般在 Linux 中,都有一個可以在開機後執行一些程式的設定檔,一般來說都叫做 rc.local,可能是位在 /etc 或 /etc/rc.d 的目錄之下,但也有一些 Linux 在新的版本中,逐漸捨棄這項功能,如果要使用這樣的功能,還要特別去設定。
在 Gentoo Linux 中,這一個設定檔,叫 local.start,位在 /etc/local.d 目錄之下
# vim /etc/local.d/local.start
#!/bin/bash
if [ -e /etc/firewall.server ] ;then
echo “Starting Firewall…”
   sh /etc/firewall.server
fi

設定檔案執行權限
# chmod 700 /etc/local.d/local.start

Banana Pi 測試 – Gentoo Linux 工作排程

cron 工作排程也不是內建就有安裝,須要另外安裝
# crontab -l
-bash: crontab: command not found

安裝
# emerge vixie-cron

# emerge fcron

# emerge cronie
[@more@]
列出工作排程
# crontab -l
# crontab -u bananapi -l

加入工作排程
# crontab -e
# crontab -u bananapi -e

移除工作排程
# crontab -r
# crontab -u bananapi -r

Banana Pi 測試 – Gentoo Linux 擴充 /root 分割區

原本的使用狀況
# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       3.4G  1.7G  1.5G  53% /
devtmpfs        438M     0  438M   0% /dev
tmpfs            88M  284K   88M   1% /run
shm             438M     0  438M   0% /dev/shm
cgroup_root      10M     0   10M   0% /sys/fs/cgroup

使用 fdisk 做磁碟分割
# fdisk /dev/mmcblk0
[@more@]刪除第二個分割區,並重建第二個分割區

重新啟動電腦
# reboot

使用 resize2fs 擴大分割區的大小
# resize2fs /dev/mmcblk0p2
resize2fs 1.42.10 (18-May-2014)
Filesystem at /dev/mmcblk0p2 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/mmcblk0p2 is now 1923584 blocks long.

擴充之後的磁碟空間
# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       7.2G  1.7G  5.2G  25% /
devtmpfs        438M     0  438M   0% /dev
tmpfs            88M  284K   88M   1% /run
shm             438M     0  438M   0% /dev/shm
cgroup_root      10M     0   10M   0% /sys/fs/cgroup

Banana Pi 測試 – Gentoo Linux iptables 防火牆

Gentoo Linux 果然非常精簡,連 iptables 都沒有內建安裝
# iptables -L -n
-bash: iptables: command not found

安裝 iptables
# emerge iptables

設定開機時啟動
# rc-update add iptables default
 * service iptables added to runlevel default[@more@]
將目前的防火牆規則儲存起來
# /sbin/iptables-save > /var/lib/iptables/rules-save

# rc-service iptables save