在 FreeBSD 安裝 Samba4

參考文章:Samba 4.1 on FreeBSD 10.1 · GitHub
1. 搜尋可用的套件
# pkg search samba | grep ^samba
samba-nsupdate-9.8.6_1         nsupdate utility with GSS-TSIG support
samba-virusfilter-0.1.3_1      On-access anti-virus filter for Samba
samba36-3.6.25_3               Free SMB and CIFS client and server for Unix
samba36-libsmbclient-3.6.25_2  Shared lib from the samba package
samba36-nmblookup-3.6.25       NetBIOS Name lookup tool
samba36-smbclient-3.6.25       Samba “ftp-like” client
samba41-4.1.22_2               Free SMB/CIFS and AD/DC server and client for Unix
samba42-4.2.11                 Free SMB/CIFS and AD/DC server and client for Unix
samba43-4.3.8                  Free SMB/CIFS and AD/DC server and client for Unix

2. 直接安裝最新的版本
# pkg install samba43

************************************************************
Message from trousers-tddl-0.3.10_7:
To run tcsd automatically, add the following line to /etc/rc.conf

tcsd_enable=”YES”

You might want to edit /usr/local/etc/tcsd.conf to reflect your setup.

To use TPM, add your_account to ‘_tss’ group like following:

# pw groupadd _tss -m your_account
Message from cyrus-sasl-2.1.26_12:
You can use sasldb2 for authentication, to add users use:

        saslpasswd2 -c username

===============================================================================
Message from samba43-4.3.8:
===============================================================================

How to start: http://wiki.samba.org/index.php/Samba4/HOWTO

* Your configuration is: /usr/local/etc/smb4.conf

* All the relevant databases are under: /var/db/samba4

* All the logs are under: /var/log/samba4

* Provisioning script is: /usr/local/bin/samba-tool

For additional documentation check: http://wiki.samba.org/index.php/Samba4

Bug reports should go to the: https://bugzilla.samba.org/

===============================================================================[@more@]3. 建立 /usr/local/etc/smb4.conf
    設定檔是從 NAS4Free 取得,再稍做修改
# vim /usr/local/etc/smb4.conf
[global]
encrypt passwords = yes
netbios name = freebsd
workgroup = HOME
server string = FreeBSD Server
security = user
dns proxy = no
strict locking = no
read raw = yes
write raw = yes
oplocks = yes
max xmit = 65535
deadtime = 15
getwd cache = yes
unix charset = UTF-8
time server = yes
max log size = 100
logging = syslog
loglevel = 1
load printers = no
printing = bsd
printcap cache time = 0
printcap name = /dev/null
disable spoolss = yes
dos charset = CP950
smb passwd file = /var/etc/private/smbpasswd
private dir = /var/etc/private
passdb backend = tdbsam
idmap config * : backend = tdb
idmap config * : range = 10000-39999
aio read size = 1024
aio write size = 1024

[t850008]
comment = t850008
path = /home/t850008
writeable = yes
printable = no
hide dot files = yes
guest ok = no
inherit permissions = yes
inherit acls = yes

4. 測試設定檔是否正確
# /usr/local/bin/testparm
Load smb config files from /usr/local/etc/smb4.conf
Processing section “[t850008]”
Loaded services file OK.
Server role: ROLE_STANDALONE

Press enter to see a dump of your service definitions

# Global parameters
[global]
        dos charset = CP950
        workgroup = HOME
        server string = FreeBSD Server
        security = USER
        smb passwd file = /var/etc/private/smbpasswd
        private dir = /var/etc/private
        logging = syslog
        max log size = 100
        max xmit = 65535
        time server = Yes
        deadtime = 15
        load printers = No
        printcap cache time = 0
        printcap name = /dev/null
        disable spoolss = Yes
        dns proxy = No
        idmap config * : range = 10000-39999
        idmap config * : backend = tdb
        aio read size = 1024
        aio write size = 1024
        strict locking = No

[t850008]
        comment = t850008
        path = /home/t850008
        read only = No
        inherit permissions = Yes
        inherit acls = Yes

5. 修改 /etc/rc.conf 啟動設定檔
# vim /etc/rc.conf
加入下面這一行設定
samba_server_enable=”YES”

# echo ‘samba_server_enable=”YES”‘ >> /etc/rc.conf

6. 啟動 Samba Server
# /usr/local/etc/rc.d/samba_server start
Performing sanity check on Samba configuration: OK
Starting nmbd.
Starting smbd

7. 檢查 Samba Server 是否有正常啟動
# netstat -an | grep -E ‘137|138|139|445’
tcp4       0      0 *.139                  *.*                    LISTEN
tcp4       0      0 *.445                  *.*                    LISTEN
tcp6       0      0 *.139                  *.*                    LISTEN
tcp6       0      0 *.445                  *.*                    LISTEN
udp4       0      0 *.138                  *.*
udp4       0      0 *.137                  *.*

8. 設定使用者密碼
# /usr/local/bin/pdbedit -a t850008
new password:
retype new password:
Unix username:        t850008
NT username:
Account Flags:        [U          ]
User SID:             S-1-5-21-1407030253-4189778233-248147614-1000
Primary Group SID:    S-1-5-21-1407030253-4189778233-248147614-513
Full Name:            User &
Home Directory:       freebsdt850008
HomeDir Drive:
Logon Script:
Profile Path:         freebsdt850008profile
Domain:               FREEBSD
Account desc:
Workstations:
Munged dial:
Logon time:           0
Logoff time:          日, 00  1月 1900 00:00:00 CST
Kickoff time:         日, 00  1月 1900 00:00:00 CST
Password last set:    日, 26  6月 2016 09:59:39 CST
Password can change:  日, 26  6月 2016 09:59:39 CST
Password must change: never
Last bad password   : 0
Bad password count  : 0
Logon hours         : FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

在 FreeBSD 安裝 grive 同步檔案到 Google Drive

參考網頁:
Grive2 — YourcmcWiki
GitHub – vitalif/grive2: Google Drive client with support for new Drive REST API and partial sync

1.安裝所需套件
# pkg install git cmake boost-libs yajl libgcrypt pkgconf cppunit libbfd
[@more@]2. 下載 grive Source Code
# git clone https://github.com/vitalif/grive2

3. 進行編譯
# cd grive2
# mkdir build
# cd build
# cmake ..

4. 進行安裝
# make -j4
# make install
[ 73%] Built target grive
[ 79%] Built target btest
[ 96%] Built target unittest
[100%] Built target grive_executable
Install the project…
— Install configuration: “”
— Installing: /usr/local/bin/grive
— Set runtime path of “/usr/local/bin/grive” to “”
— Installing: /usr/local/share/man/man1/grive.1

解決 FreeBSD pkg 安裝軟體時出現的錯誤訊息

在 FreeBSD 使用 pkg 安裝 cmake 軟體時出現下面的錯訊息
Fetching cmake-3.5.0.txz: 100%    3 MiB   3.5MB/s    00:01
pkg: cached package cmake-3.5.0: size mismatch, fetching from remote
Fetching cmake-3.5.0.txz: 100%    3 MiB   3.5MB/s    00:01
pkg: cached package cmake-3.5.0: size mismatch, cannot continue[@more@]解決方式:
1. 刪除 /var/cache/pkg 目錄下所有檔案
# rm -rf /var/cache/pkg/*

2. 強制再更新一次套件庫
# pkg update -f

讓 FreeBSD 終端機可以輸入中文

原本的 FreeBSD 無法輸入中文

可以正常顯示中文

[@more@]解決方式:
1. shell 是 bash
修改 /etc/profile
# vim /etc/profile
加入下面三行
  export LC_CTYPE=en_US.ISO8859-1
  export LC_ALL=zh_TW.UTF-8
  export LANG=zh_TW.UTF-8

2. shell 是 csh
修改 /etc/csh.cshrc
# vim /etc/csh.cshrc
加入下面三行
  setenv LC_CTYPE en_US.ISO8859-1
  setenv LC_ALL zh_TW.UTF-8
  setenv LANG zh_TW.UTF-8

3. 重新啟動電腦或登出後重新登入,即可生效!

FreeBSD 安裝 vim

FreeBSD 系統中預設有安裝 vi 及 ee,不過個人比較習慣使用 vim。
安裝 vim
# pkg installl vim
Updating FreeBSD repository catalogue…
FreeBSD repository is up-to-date.
All repositories are up-to-date.
The following 112 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
        vim: 7.4.1556
        libXt: 1.1.5,1
        中略……
The process will require 606 MiB more space.
118 MiB to be downloaded.

Proceed with this action? [y/N]: n

發現要安裝 vim ,共要下載 112 個套件、118 MiB 及使用 606 MiB 空間。[@more@]稍微看了一下,發現很多是和 X11 和 GTK 相關的套件,因為 vim 套件中包含了 gvim。

所以改裝 vim-lite
# pkg search vim-lite
vim-lite-7.4.1556              Improved version of the vi editor (lite package)
# pkg install vim-lite
Updating FreeBSD repository catalogue…
FreeBSD repository is up-to-date.
All repositories are up-to-date.
The following 1 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
        vim-lite: 7.4.1556

The process will require 22 MiB more space.
5 MiB to be downloaded.

Proceed with this action? [y/N]:y

讓 FreeBSD 的終端機也多彩多姿

使用習慣 Linux 的 bash,有些不太習慣 FreeBSD 的 csh。
# echo $SHELL
/bin/csh

更改方式
1. 安裝 bash
# pkg install bash[@more@]2. 更改使用者使用的 shell
# chsh
#Changing user information for root.
Login: root
Password:
Uid [#]: 0
Gid [# or name]: 0
Change [month day year]:
Expire [month day year]:
Class:
Home directory: /root
Shell: /bin/csh
Full Name: Charlie &
Office Location:
Office Phone:
Home Phone:
Other information:

Shell: /bin/csh
改成
Shell: /usr/local/bin/bash

3. 安裝 gnuls
# pkg install gnuls

4. 修改 /etc/profile 設定檔
# vi /etc/profile
加入下面一行
alias ls=”gnuls –color=auto –show-control-chars -F”


alias ls=”ls -xCFG”

二個在顏色的效果上有一點小差異(個人比較習慣使用上一個)!

存檔後,重新執行
# source /etc/profile 或重新登出登入即可生效

5. 原本的畫面

修改之後的畫面

FreeBSD 使用 pkg 作套件管理

FreeBSD 可以使用 pkg 和 ports 來安裝套件。其中 pkg 指令的功能和 RedHat/CentOS Linux 中的 yum 和 Debian/Ubuntu Linux 中的 apt 及 ArchLinux 中的 pacman 功能類似。
搜尋套件
# pkg search bash | grep ^bash
bash-4.3.42_1                  The GNU Project’s Bourne Again SHell
bash-completion-2.1_6,1        Programmable completion library for Bash
bash-static-4.3.42_1           The GNU Project’s Bourne Again SHell
bashc-3.2.33.0_1               GNU bash shell extended with visual two-panel file browser[@more@]
查詢套件資訊
# pkg info bash

安裝套件
# pkg install bash

查詢套件安裝的版本
# pkg version | grep bash
bash-4.3.42_1                      =

移除套件
# pkg delete bash

自動移除系統中用不到的套件
# pkg autoremove

更新系統中已安裝的套件
# pkg upgrade

更新套件庫
# pkg update

清除暫存區的舊套件
# pkg clean

查詢系統中安裝的套件
# pkg info
# pkg version

套件安裝的版本
# pkg version -v
bash-4.3.42_1                      =   up-to-date with port
gettext-runtime-0.19.7             >   succeeds port (port has 0.19.6)
gnuls-8.22                         =   up-to-date with port
indexinfo-0.2.4                    =   up-to-date with port
pkg-1.7.2                          >   succeeds port (port has 1.6.2)
vim-lite-7.4.1556                  >   succeeds port (port has 7.4.979)

查詢套件安裝的位置
# pkg info -l gnuls
gnuls-8.22:
        /usr/local/bin/dir
        /usr/local/bin/dircolors
        /usr/local/bin/gnuls
        /usr/local/bin/vdir
        /usr/local/man/man1/dir.1.gz
        /usr/local/man/man1/dircolors.1.gz
        /usr/local/man/man1/gnuls.1.gz
        /usr/local/man/man1/vdir.1.gz

查詢套件的相依性
# pkg info -d bash
bash-4.3.42_1:
        indexinfo-0.2.4
        gettext-runtime-0.19.7

檔案所屬套件
# pkg which /usr/local/bin/bash
/usr/local/bin/bash was installed by package bash-4.3.42_1

更多的 pkg 功能
# pkg help

解決 FreeBSD pkg 指令無法搜尋到套件的問題

在 FreeBSD 系統使用 pkg 搜尋要安裝的套件時,出現
# pkg search bash
pkg: No packages available to install matching bash available in the repositories

# pkg search bash
完全無任何訊息

也已經把套件庫更新到最新
# pkg update
Updating FreeBSD repository catalogue…
FreeBSD repository is up-to-date.
All repositories are up-to-date.[@more@]解決方式 刪除 /var/db/pkg/repo-*
# rm -rf /var/db/pkg/repo-FreeBSD.sqlite

重新套件套件庫
# pkg update
Updating FreeBSD repository catalogue…
Fetching meta.txz: 100%    944 B   0.9kB/s    00:01
Fetching packagesite.txz: 100%    5 MiB   5.6MB/s    00:01
Processing entries: 100%
FreeBSD repository update completed. 25089 packages processed.

這時候就正常了!
# pkg search bash
bash-4.3.42_1                  The GNU Project’s Bourne Again SHell
bash-completion-2.1_6,1        Programmable completion library for Bash
bash-static-4.3.42_1           The GNU Project’s Bourne Again SHell
bashc-3.2.33.0_1               GNU bash shell extended with visual two-panel file browser
checkbashisms-2.15.10          Check for the presence of bashisms
erlang-mochiweb-basho-2.9.0p2  Erlang library for building lightweight HTTP servers (Basho fork)
mybashburn-1.0.2_4             Ncurses CD burning bash script
p5-Bash-Completion-0.008_1     Extensible system to provide bash completion
p5-Term-Bash-Completion-Generator-0.02.8 Generate bash completion scripts

FreeBSD 10.3 安裝

距離上一次好好使用 FreeBSD 系統已經有八、九年了,這一段時間 FreeBSD 的變化也很大,有種從 CentOS 6.x 跳到 CentOS 7.x 的感覺,很多東西都變了,最近在使用 FreeNAS 和 NAS4Free,就感覺到很生疏,所以利用時間再重新安裝 FreeBSD 來使用看看。

FreeBSD  安裝網站:https://www.freebsd.org/
目前最新版本是 10.3 版
台灣 FreeBSD 下載網站:
ftp://ftp.tw.freebsd.org/pub/FreeBSD/releases/ISO-IMAGES/10.3/

1. 光碟開機畫面
[@more@]2. 選擇 Install 進行安裝

3. 鍵盤型式選擇

4. 主機名稱

5. 預設安裝元件

6. 硬碟分割

7. 整個硬碟

8. 採用 GUID 型式硬碟分割區

9. 硬碟分割狀態

10. 選擇 Commit 確認

11. 元件檢查

12. 進行安裝

13. 設定 root 管理者密碼

14. 系統偵測到的網路卡

15. 設定 IPv4

16. 使用 DHCP Server 自動取得 IP

17. 不設定 IPv6

18. DNS Server 設定

19. 不使用 UTC 時間

20. 選擇 5 Asia

21. 選擇 42 Taiwan

22. 使用 CST 時間

23. 預設啟動的系統服務

24. 新增 root 之外的使用者

25. 新增使用者

26. 不再新增其它使用者

27. 退出安裝系統

28. 不再切換到 shell 作其它設定

29. 重新啟動系統

30. 開機畫面

31. 登入系統