一、packages 安装
pkg_add -v filename.tgz 扩展名是 tgz
所有安装过的软件都会出现在 /var/db/pkg 的目录中。
pkg_delete filename 删除软件
pkg_info filename.tgz 查看这个软件的信息。
pkg_tree 可以让我了解每一套软件之间的关系,不过要先安装!
cd /usr/ports/sysutils/pkg_tree
make install clean
pkg_tree | more 来查看各软件之间的关系。
用 packages 安装的软件,不能马上执行,要马上能执行要先执行 rehash 或注销后再重新登入即可执行。
二、ports
把在 a 系统上面可以正常运作的程序,修正成 b 系统上也能正常执行的工作,称为 port。
抓 port.tar.gz 档案回来,放在 /usr 下解压缩
要安装哪一种软件就切换到它分类的目录中,如要安装 proftpd ,目录就在 /usr/ports/ftp/profptd 中,执行 make install 即可,它除了安装 proftpd 外,还会把缺的档案也一起抓回来安装,安装完后可执行 make clean 把安装编译过程中产生的一个档案清除。
寻找需要安装的 port
在 /usr/ports 使用 make search key="ncftp" | less
反安装软件,只要在该软件的目录中执行 make deinstall 即可。
一些不常用的 make 方式
make fetch 抓回所需的原始档
make fetch-list 显示安装所需的档案
make all install 抓回原始档、编译且安装
make reinstall 若先前发生意外中断,重新尝试安装。
如果安装完新的软件之后,如果使用的 shell 是 csh 或 tcsh ,我们可能必须执行 rehash 来重建 hash table ,才能执行安装好的软件。
freebsd 安装 mysql、php、apache
在 /etc/group 加入 mysql:*:100:
执行 vipw 加入一行
mysql:*:100:100::0:0:mysql user:/usr/local/mysql:/sbin/nologin
tar -xvzf mysql-3.23.52.tar.gz
cd mysql-3.23.52
./configure --prefix=/usr/local/mysql --with-charset=big5 --with-low-memory --with-named-thread-libs=-lc_r
make;make install
script/mysql_install_db
chown -r mysql:msqyl /usr/local/mysql
cd /usr/local/mysql/share/mysql
./mysql.server.start
/usr/local/mysql/bin/mysqladmin -u root -password 'xxxx';
grant all privileges on dbname.* to username@localhost identified by 'password';
grant all privileges on *.* to username@localhost identified by 'password';
flush privileges;
在 /etc/rc.local 加入一行
/usr/local/mysql/share/mysql/mysql.server start
备分数据库
/usr/local/mysql/bin/mysqldump -u root -p dbname > dbname.sql 备份
/usr/local/mysql/bin/mysql -u root -p dbname < dbname.sql 还原 之前可能要先把数据库建好
更改使用者密码
/usr/local/mysql/bin/mysqladmin -u root -p password newpassword
二、安装 php、apache
apache_1.3.27.tar.gz
mod_fastcgi_2.2.12.tar.gz
php-4.2.3.tar.gz
gd-1.84.tar.gz
zlib-1.1.4.tar.gz
t1lib-1.3.1.tgz
freetype2-2.0.6.tgz
jpeg-6b_1.tgz
png-1.2.1.tgz
先解压缩 apache 并做一次 apache 的组态
tar -xvzf apache-1.3.27.tar.gz
./configure --prefix=/usr/local/apache
cd ..
tar -xvzf zlib-1.1.4.tar.gz
cd zlib-1.1.4
make all install
cd ..
pkg_add -v jpeg-6b_1.tgz
pkg_add -v png-1.2.1.tgz
pkg_add -v t1lib-1,3,1,tgz
pkg_add -v freetype2-2.0.6.tgz
tar -xvzf gd-1.8.4.tar.gz
cd gd-1.8.4
make install
cd ..
安装 php
tar -xvzf php-4.2.3.tar.gz
cd php-4.2.3
./configure --with-mysql=/usr/local/mysql --with-apache=../apache-1.3.27 --enable-track-vars --with-gd=/usr/local --enable-gd-native-ttf --with-t1lib --with-jpeg-dir=/usr/local --with-png-dir --with-freetype-dir --with-zlib-dir
make;make install
cp php.ini-dist /usr/local/lib/php.ini
cd ..
安装 apache
cd apache_1.3.27/src/modules
tar -xvzf ../../../mod_fastcgi-2.2.12.tar.gz
mv mod_fastcgi-2.2.12 fastcgi
cd ../../
./configure --prefix=/usr/local/apache --enable-shared=max --activate-module=src/modules/php4/libphp4.a --activate-module=src/modules/fastcgi/libfastcgi.a --enable-suexec --suexec-caller=nobody --suexec-docroot=/usr/local/apache/htdocs --suexec-userdir=www --suexec-logfile=/usr/local/apache/logs/suexec_log --suexec-uidmin=10 --suexec-gidmin=10
make;make install
加入对 php4 的支持
在 /usr/local/apache/conf/httpd.conf 加入二行
addtype application/x-httpd-php .php .phtml .php3
addtype application/x-httpd-php-source .phps
让 apache 在开机时能够启动
在 /etc/rc.local 加入 /usr/local/apache/bin/apachectl start
在 /etc/newsyslog.conf 加入二行以压缩备份 apache log 档
/var/log/apache_access_log 644 7 * $w0d1 z
/var/log/apache_error_log 644 7 * $w0d2 z
安装 proftpd
make sure you have the following lines in your pam configuration file
so that proftpd's pam module can authenticate users correctly.
ftpd auth required pam_unix.so try_first_pass
ftpd account required pam_unix.so try_first_pass
ftpd session required pam_permit.so
###
===> generating temporary packing list
===> compressing manual pages for proftpd-1.2.6
===> registering installation for proftpd-1.2.6
===> security note:
this port has installed the following startup scripts which may cause
network services to be started at boot time.
/usr/local/etc/rc.d/proftpd.sh.sample
安装 snmp
if you want to invoke snmpd from startup, put these lines into
/etc/rc.conf.
net_snmpd_enable="yes"
net_snmpd_flags=""
**** you can specify make variables as:
net_snmp_sys_contact="kuriyama@freebsd.org"
net_snmp_sys_location="tokyo, japan"
default_snmp_version=3
net_snmp_logfile=/var/log/snmpd.log
net_snmp_persistentdir=/var/net-snmp
to define default values (or overwriting defaults). at least
setting first two variables, you will not be prompted during
configuration process. or you can set
batch="yes"
to make to avoid interactive configuration.===> compressing manual pages for net-snmp-5.0.6
===> running ldconfig
/sbin/ldconfig -m /usr/local/lib
===> registering installation for net-snmp-5.0.6
===> security note:
this port has installed the following startup scripts which may cause
network services to be started at boot time.
/usr/local/etc/rc.d/snmpd.sh
安装 nat
修改 /etc/rc.conf
一块网络卡 ifconfig_rl0_alias0="inet 192.168.1.1 netmask 255.255.255.0"
二块网络卡 ifconfig_rl1="inet 192.168.1.1 netmask 255.255.255.0"
加入下列五行
gateway_enable="yes"
firewall_enable="yes"
firewall_type="open"
natd_interface="rl0"
natd_enable="yes"
freebsd 指令集
cp -p 档案拷贝过去还是维持原来的权限
避免 /bin 及 /sbin 等重要执行档遭到修改,可以为这些档案设定禁止修改的 schg flag
chflags schg /bin/*
chflags schg /sbin/*
设定了 schg ,还要将 kernel security level 调高到 1 以上,这样连 root 都不可以移除 flags 。
kernel security level
freebsd 中有所谓的 security level ,它掌控了系统核心的行为运作。只有 root 可以使用指令提高 security level ,但不能降低它。如果要降低它,必须在 rc.conf 中设定,并重新开机。
security level 代表的意义:
-1:永远不安全模式。这是默认值。如果为 -1 ,它将永远以 level 0 的模式执行。
0 :不安全模式。使用者或 root 可以使用 chflags 来移除「不可更动」及「只能附加」的 flags。所有的装置只能依其权限来存取。
1:安全模式。不可以移除「不可更动」及「只能附加」的 flags 。不可以手动加载或移除 lkm ,使用 /dev/mem /dev/kmem 只能只读,且不能 newfs 已挂上的档案系统。
2:高度安全模式。除了和安全模式同样的限制外,不管硬盘是否挂上,都不可以 newfs。另外,kernel time 的改变限制在一秒内,如果超过,会记录 "time adjust-ment clamped to +1 second".
3:网络安全模式。除了和安全模式同样的限制外,还有 ip 封包过滤的规则,而且不可以调整 dummynet 的设定。
可以利用 sysctl 来显示或设定 security level
sysctl kern.securelevel
将 security level 设为 1
sysctl -w kernel.securelevel=1
当我们将 security level 设为 1 以上时,我们会发现没有办法安装新的 kernel ,因为不能移除 schg flag ,也没有办法使用 big5con 、 x window 等软件。如果 freebsd 只作 server ,就可以把 security level 的值调高一点。
在开机时设定 security level ,可以在 /etc/rc.conf 中加入以下二行设定
#是否启动 security level
kern_securelevel_enable="yes"
# level 从 -1 到 3
kern_securelevel="1"
只能用 root 使用指令提高 security level,但不能降低,如果要降低,必须在 /etc/rc.conf 中设定,重新开机才会生效。
限制使用者邮件容量就是将使用者的邮件从 /var/mail 中搬移到使用者的目录中,再对使用者目录做磁盘配额的限制。
cd /var/mail
mkdir /home/username/mail
mv /var/mail/username /home/username/mail
ln -s /home/username/mail username
限制 crontab 和 at 的使用
在 /var/cron 目录中编辑 allow 的文字文件,里面的人才可以使用 cron
deny 的文字文件,里面的人不可以使用 cron
at 也是一样的设定。
停止 sendmail 在 /etc/rc.conf 中加入 sendmail_enable="no"
使用 sysctl 来设定当外部机器要使用我们没有提供的服务时运记录下来,例如有人尝试扫我们的 port ,或者我们没有开放 telnet ,在 /var/log/message 中便会记录下来。
#sysctl -w net.inet.tcp.log_in_vain=1
#sysctl -w net.inet.udp.log_in_vain=1
这二行加入 /etc/rc.local 中 或是在 /etc/sysctl.conf 加入下面二行
net.inet.tcp.log_in_vain=1
net.inet.udp.log_in_vain=1
在 /etc/rc.conf 加入一行停止 inted 服务
inetd_enable="no"
为了防止一些 dos (deny of service) ,建议最好把 icmp 重导向 ( redirect ) 的封包丢弃,可以在 /etc/rc.conf 中加入以下的设定:
# yes 表示丢弃 icmp redirect 封包
icmp_drop_redirect="yes"
# yes 表示将丢弃的封包记录下来
icmp_log_redirect="yes
sshd 预设并未将使用者登入的数据记录下来,可以利用修改 /etc/syslog.conf 来记录,找到 seccrity 的项目,将它修改成下面这样:
security.*;auth.info /var/log/security
如此一来,当使用者利用 ssh 登入时,便会记录在 /var/log/security 中。
netstat -a | grep listen
sysctl -a 可以列出目前 kernel 状态值的设定
列出空间使用最多的前 5 位
du -s /home/* | sort -m | head -5
freebsd 有一种特别的权限控制,称之为「flags」,这些 flags 的设定可以让我们用来保护特殊的档案。可以用 ls -ol 来加以观看。
nodump | 档案不可以被 dump,只有档案拥有者和 root 可以设定 |
sappnd | 档案只可以往后附加,不能删除,只有 root 可以设定 |
schg | 档案不可以被更动,连 root 都不能删除,只有 root 可以设定 |
uappnd | 档案只可以往后附加,不能删除,档案拥有者和 root 才可以设定 |
uchg | 档案不可以被更动,档案拥有者和 root 才可以设定 |
您可能感兴趣的文章:
如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!
网友评论