FREEBSD系統是一種非常 UNIX、非常 Free、非常 BSD -- UNIX 的操作系統,因為它過UNIX化,太過專業化了,教很多新手無從下手學習本文的目的是使新手可以根據此文章的步驟和方法,架設一台專業,高效,安全的FREEBSD出來,並且可以立即投入實際運用,故文章中對運用及命令的使用多於理論化的知識點的描述,如果您不明白命令有何作用,建議您查查相關資料.
本文假設已經架設好或者新安裝了一台FREEBSD系統主機. 本文中引用了很多FREEBSD官方站數據及網上數據,還有更多的是自己在實際工作中的經驗,當然,裡面的參數並不一定完全適合您,所以請您在使用時,盡可能根據您的實際需要調整一些參數,使您的SERVER的性能完全的發揮出來.本文只是一個總的線索,如果我要拆開來一個一個詳細解釋,我想會花更多的篇幅來寫的,因為我忙著04年1月的自考,只寫了實際中的運作情況,請各位朋友見諒.
升級源碼樹
安裝cvsup
進入:/usr/ports/net/cvsup
make clean
make deinstall
make install
make clean
即可
升級系統源碼樹及ports
更新/usr/share/examples/cvsup目錄下stand-cvsup和ports-cvsup文件,並執行cvsup –g –L2 standard-supfile和cvsup –g –L2 ports-cvsup兩個文件,升級ports樹﹔
重新編譯內核
優化編譯環境
CPUTYPE=i686
CFLAGS= -O3 -pipe
COPTFLAGS= -O3 -pipe
升級操作系統
進入/usr/src
執行make world
整個過程很久,需要2小時左右.
升級配置文件
執行mergemaster升級配置文件,在此過程中,需要按i以便系統執行升級﹔
重新編譯內核
到/sys/i386/conf裡面,cp GENERIC onlinecq,再vi onlinecq優化內核,注意加入下面的內容
#disable ctrl+alt+delete
options SC_DISABLE_REBOOT
#quota limit
options QUOTA
#ipfw support
options IPFIREWALL
options DUMMYNET
options HZ=3000
options IPDIVERT
options IPFIREWALL_VERBOSE
options IPFIREWALL_VERBOSE_LIMIT=100
options IPSTEALTH
options TCP_DROP_SYNFIN
options IPFIREWALL_DEFAULT_TO_ACCEPT
options ICMP_BANDLIM
options ACCEPT_FILTER_DATA
options ACCEPT_FILTER_HTTP
#ipfilter support
#options IPFILTER
#options IPFILTER_LOG
#options IPFILTER_DEFAULT_BLOCK
再執行:
/usr/sbin/config onlinecq
cd ../../compile/onlinecq
make depend
make
make install
重新啟動服務器
到此為止,服務器操作系統及內核升級成功
reboot
優化FREEBSD
檢查升級情況, 使用ssh進入系統,使用uname –a 可以查到是否升級成功﹔
打開防火牆
#enable_quotas="YES"
#check_quotas="YES"
firewall_enable="YES"
firewall_script="/etc/rc.firewall"
firewall_type="/etc/ipfw.rules" #create it!
firewall_quiet="NO"
firewall_logging_enable="YES"
log_in_vain="NO"
tcp_drop_synfin="NO"
tcp_restrict_rst="YES"
icmp_drop_redirect="YES"
優化內核參數
kern.ipc.maxsockbuf=2097152
kern.maxfilesperproc=32768
kern.maxfiles=65536
net.inet.tcp.recvspace=32768
net.inet.udp.maxdgram=57344
net.inet.icmp.drop_redirect=1
net.inet.icmp.log_redirect=0
net.inet.ip.redirect=0
net.inet6.ip6.redirect=0
net.inet.icmp.icmplim=100
net.inet.tcp.always_keepalive=0
net.inet.tcp.delayed_ack=0
net.inet.tcp.log_in_vain=0
net.inet.udp.log_in_vain=0
net.inet.tcp.blackhole=2
net.inet.udp.blackhole=1
net.local.stream.recvspace=32768
net.inet.ip.fastforwarding=1
vfs.vmiodirenable=1
安裝防火牆
安裝數據庫MYSQL
安裝mysql40-server和mysql40-client
進入/usr/ports/databases/mysql40-server
執行:
make clean
make deinstall
make WITH_OPENSSL=yes WITH_LINUXTHREADS=yes BUILD_OPTIMIZED=yes install
或者使用下面可參考的編譯參數:BUILD_STATIC=yes
編譯成靜態執行版本
make clean
更改mysql的root密碼:
mysqladmin –uroot –p password 123456
[client]
#password = your_password
port = 3306
[mysqld]
skip-innodb
skip-locking
skip-networking
set-variable = port=3306
set-variable = back_log=50
set-variable = connect_timeout=3
set-variable = key_buffer=128M
set-variable = max_connections=1000
set-variable = max_allowed_packet=1M
set-variable = net_buffer_length=8K
set-variable = wait_timeout=3
set-variable = read_buffer_size=1M
set-variable = sort_buffer_size=1M
set-variable = table_cache=256
set-variable = myisam_sort_buffer_size=32M
set-variable = log_slow_queries=/var/log/log_slow_queries.log
#log-bin
server-id = 1
[mysqldump]
quick
set-variable = max_allowed_packet=16M
[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates
[isamchk]
set-variable = key_buffer=20M
set-variable = sort_buffer=20M
set-variable = read_buffer=2M
set-variable = write_buffer=2M
[myisamchk]
set-variable = key_buffer=20M
set-variable = sort_buffer=20M
set-variable = read_buffer=2M
set-variable = write_buffer=2M
[mysqlhotcopy]
interactive-timeout
安裝phpmyadmin
注意,此步驟需要在apache和php之後再執行
進入/usr/ports/databases/phpmyadmin
執行:
make clean
make deinstall
make install
make clean
新建立一個system的數據庫備用.
安裝FTP服務器
安裝ftp軟件(使用pure-ftpd/)
進入/usr/ports/ftp/pufe-ftpd
執行:
make clean
make deinstall
make WITH_MYSQL=1 install
或者使用下面可參考的編譯參數:WITH_LANG=simplified-chinese
使用簡體中文語言包
make clean
配置pure-ftpd,主要需要做以下的工作:
NoAnonymous yes
# Mandatory : user to bind the server as.
MYSQLUser demo
# Mandatory : user password. You must have a password.
MYSQLPassword demo
# Mandatory : database to open.
MYSQLDatabase demo
再進入使用mysql –uroot –p123456 進入mysql的文本方式﹔
使用如下命令建立新表:
use system;
DROP TABLE IF EXISTS users;
CREATE TABLE users (
User varchar(16) NOT NULL default '',
status enum('0','1') NOT NULL default '0',
Password varchar(64) NOT NULL default '',
Uid varchar(11) NOT NULL default '-1',
Gid varchar(11) NOT NULL default '-1',
Dir varchar(128) NOT NULL default '',
ULBandwidth smallint(5) NOT NULL default '0',
DLBandwidth smallint(5) NOT NULL default '0',
comment tinytext NOT NULL,
ipaccess varchar(15) NOT NULL default '*',
QuotaSize smallint(5) NOT NULL default '0',
QuotaFiles int(11) NOT NULL default 0,
PRIMARY KEY (User),
UNIQUE KEY User (User)
) TYPE=MyISAM;
安裝pureftpd_php_manager
下載pureftpd_php_manager.zip
解壓並放到指定的目錄裡面,比如:
/usr/local/www/data
chmod –R 755 /usr/local/www/data/pureftpd_php_manager
再加入一個普通用戶和一個群組,以供ftp使用:
pw groupadd ftpusers
pw useradd ftpuser –g ftpusers –s /sbin/nologin
記住他們的uid和gid號,備用!
更改裡面的如下行:
$DefaultUser = "ftpuser"; # Default User Logon^M
$DefaultPass = ""; # Default User Password^M
$DefaultUid = "1002"; # Default User ID ( must be a re
al user acct )^M
$DefaultGid = "1001"; # Default Group ID ( must be a r
eal group acct )^M
$DefaultDir = "/home"; # Default User Dir ( use
/./ at the end to chroot )^M
$DefaultUL = "0"; # Default Upload Throttl
e ( 0 disables it )^M
$DefaultDL = "0"; # Default Download Throt
tle ( 0 disables it )^M
$Defaultip = "*"; # Default IP restriction
s ( * = any IP )^M
$DefaultQS = "200"; # Default Quota Size ( 0 disable
s it )^M
$Defaultcmt = ""; # Default Comment for us
er^M
^M
// UA^M
$DefaultQF = "0"; # Default Quota Files ( 0 disabl