您的位置:首页 > 其它

FreeBSD6.2架设之服务器系统升级

2008-01-02 14:52 387 查看
简介
  本文目标
  Step 1安装软件包
  Step 2使用Axel加速你的下载
  Step 3升级Ports-tree
  Step 4升级Src
  Step 5管理已安装的软件包

 简介
  
  系统安装完成后,最好经常连接官方或镜像服务器。进行系统补丁升级和Ports更新。以增加系统安全性,并且能够安装到比较新版本的软件。
  
  本文目标
  
  通过对本文的学习,您可以知道如何安装软件包,更新Ports-tree,更新系统源代码,管理已安装的软件包。
  · FreeBSD下安装软件包的几种方法。
  · FreeBSD下的下载程序。
  · 升级Ports-tree。
  · 更新FreeBSD的源代码。
  · 卸载已安装的程序,更新已安装的程序。
  
  Step 1 FreeBSD下安装软件包.
  · pkg_add方式安装软件包。
  · Ports方式安装软件包。
  · 源代码方式安装软件包。
  跟随下面步骤进行远程软件包的安装.FreeBSD下可以使用多种方法安装软件包,即可以使用pkg_add方式安装,也可以使用Ports方式安装,还可以下程序源码进行编译安装。不同的安装方式有不向的特点,有的省时间、快速;有点定制性高可以根据自己需要进行选择。
  pkg_add方式安装
  pkg_add方式安装方法1、用户预先下载编译好的需要进行安装的软件包,一般是*.tbz 和*.tgz格式的软件包。直接使用pkg_add+软件包名称,安装即可。可以使用-v参数显示安装过程。源程序可以从各大FTP站点(比如)或各发行光盘中找到。
  pkg_add+软件包名称安装。此处以安装lsof-4.79D.tbz为例
  下载并显示lsof-4.79D.tbz软件包
  Shell:
  cd /root
  fetch -v ftp://ftp.freebsd.org/pub/FreeBSD/ports/packages/sysutils/lsof-4.79D.tbz
  ls
  .cshrc .k5login .profile
  .history .login lsof-4.79D.tbz
  进行安装pkg_add -v lsof-4.79D.tbz (参数-v显示安装过程信息),安装完成可以输入rehash刷新。
  Shell:
  cd /root
  pkg_add -v lsof-4.79D.tbz
  pkg_add方式安装方法2、用户不需要下载软件包,直接在安装时输入pkg_add -r和软件包的名称,系统将自动查找并下载、安装软件包(参数-r的作用是,使系统自动决定软件包的版本,格式并进行下载软件安装)。用户设定PACKAGESITE这个环境变量,选择距离最近的FTP服务器,可以加速下载安装过程。在上一篇的用户shell中PACKAGESITE这个环境变量,此处不再设定。
  pkg_add -r+软件包名称安装(系统自动解决依赖关系)。此处以安装wget为例
  不需要指定版本及格式,直接输入安装命令pkg_add -r wget即可。系统会自动连接服务器进行下载,并且自动解决依赖关系。
  Shell:
  cd /root
  pkg_add -r wget
  Fetching ftp://ftp.cn.freebsd.org/pub/FreeBSD/ports/i386/packages-6.2-release/Latest/wget.tbz... Done.
  Fetching ftp://ftp.cn.freebsd.org/pub/FreeBSD/ports/i386/packages-6.2-release/All/libiconv-1.9.2_2.tbz... Done.
  Fetching ftp://ftp.cn.freebsd.org/pub/FreeBSD/ports/i386/packages-6.2-release/All/gettext-0.14.5_2.tbz... Done.
  rehash
  显示安装完的程序位置
  Shell:
  whereis wget
  wget: /usr/local/bin/wget /usr/local/man/man1/wget.1.gz /usr/ports/ftp/wget
  使用Ports方式安装软件包
  Ports中进入软件包名称安装目录,执行make install clean进行安装(系统自动解决依赖关系) 此处以fastest_cvsup为例进行安装
  查找fastest_cvsup在Ports中的具体位置
  Shell:
  cd /usr/ports/
  make search key=fastest_cvsup
  Port: fastest_cvsup-0.2.9_4
  Path: /usr/ports/sysutils/fastest_cvsup
  Info: Finds fastest CVSup server
  Maint: nivo+kw+ports.bfa274@is-root.com
  B-deps: perl-5.8.8
  R-deps: perl-5.8.8
  WWW: http://fastest-cvsup.sourceforge.net/
  进入fastest_cvsup所在的Ports中的目录,执行make install clean进行安装,安装后执行rehash命令刷新;
  Shell:
  cd /usr/ports/sysutils/fastest_cvsup/
  make install clean
  rehash
  
  注:安装过程中出现配置选项,可以根据需要进行选择。
  Options for fastest_cvsup 0.2.9_4
  [X] R OUNDTRIP Build with round-trip patch
  在Ports中安装软件时,可以有以下几个参数。
  make showconfig(用来查看可以有哪些配置选项)
  Shell:
  cd /usr/ports/sysutils/fastest_cvsup/
  make showconfig
  ===> The following configuration options are available for fastest_cvsup-0.2.9_4:
  ROUNDTRIP=on "Build with round-trip patch"
  ===> Use 'make config' to modify these settings
  make config(用来进行配置选项)
  Shell:
  cd /usr/ports/sysutils/fastest_cvsup/
  make config
  
  Options for fastest_cvsup 0.2.9_4
  [X] R OUNDTRIP Build with round-trip patch
  make clean(用来进行清除安装后的临时文件)
  Shell:
  cd /usr/ports/sysutils/fastest_cvsup/
  make clean
  安装完成后,可以查看安装完的提示信息。或者使用whereis 软件名来查找到具体的安装位置
  Shell:
  whereis fastest_cvsup
  fastest_cvsup: /usr/local/bin/fastest_cvsup /usr/ports/sysutils/fastest_cvsup
  Ports安装命令总结
  make install :安裝所选定的Port
  make deinstall :移除已安裝的Port
  make reinstall :移除之后再安裝一次
  make clean :安裝完毕后移除make 資料夾下的档案
  make distclean :移除安裝后的原始档案,以节省磁碟空间
  make rmconfig :移除之前安裝过程中选项的設定
  使用源代码进行安装程序
  以Apache22为例(假设安装路径为/usr/local/apache22)
  下载Apache22的talball可以使用wget在FreeBSD下载,也可以在Win下载完成再传到FreeBSD机器上。
  Shell:
  wget http://apache.mirror.phpchina.com/httpd/httpd-2.2.6.tar.gz
  --11:56:40-- http://apache.mirror.phpchina.com/httpd/httpd-2.2.6.tar.gz
  => `httpd-2.2.6.tar.gz'
  Resolving apache.mirror.phpchina.com... 60.195.249.77
  Connecting to apache.mirror.phpchina.com|60.195.249.77|:80... connected.
  HTTP request sent, awaiting response... 200 OK
  Length: 6,028,951 (5.7M) [application/x-gzip]
  
  100%[====================================>] 6,028,951 366.54K/s ETA 00:00
  
  11:56:48 (403.81 KB/s) - `httpd-2.2.6.tar.gz' saved [6028951/6028951]
  ls
  httpd-2.2.6.tar.gz
  解包并指定安装路径,进行配置,安装
  Shell:
  tar -zxvf httpd-2.2.6.tar.gz
  x httpd-2.2.6/test/test_select.c
  x httpd-2.2.6/test/time-sem.c
  x httpd-2.2.6/test/zb.c
  x httpd-2.2.6/VERSIONING
  ls
  httpd-2.2.6.tar.gz
  httpd-2.2.6 lsof-4.79D.tbz
  cd httpd-2.2.6
  ./configure --prefix=/usr/local/apache22 --enable-so --enable-ssl
  make
  make install
  --prefix : 設定Apache httpd 安裝路径
  --enable-so : 告訴Apache 启动so 模組, 让Apache 能够载入shared modules(例如PHP)
  启动Apache22进行测试
  Shell:
  /usr/local/apache22/bin/apachectl start
  如果出现:
  [Wed Nov 21 13:15:50 2007] [warn] (2)No such file or directory: Failed to enable the 'httpready' Accept Filter
  kldload accf_http
  /usr/local/apache22/bin/apachectl restart
  浏览器打开http://youipaddress
  显示:
  It works!
  好了,Apache22安装成功了。
  
  Step 2 FreeBSD下的下载程序.
  FreeBSD中安装下载程序axelwget:
  安装axel程序
  可以使用任意方法安装,如pkg_add或者Ports方式安装。这里使用pkg_add -r axel命令安装
  Shell:
  pkg_add -r axel
  Fetching ftp://ftp.cn.freebsd.org/pub/FreeBSD/ports/i386/packages-6.2-release/Latest/axel.tbz... Done.
  rehash
  查看安装程序存放位置
  Shell:
  whereis axel
  axel: /usr/local/bin/axel /usr/local/man/man1/axel.1.gz /usr/ports/ftp/axel
  axel程序的使用,axel+要下载的文件的url
  Shell:
  axel ftp://ftp.freebsd.org/pub/FreeBSD/ports/packages/chinese/zh-scim-fcitx-3.1.1.tbz
  Initializing download: ftp://ftp.freebsd.org/pub/FreeBSD/ports/packages/chinese/zh-scim-fcitx-3.1.1.tbz
  File size: 1403252 bytes
  Opening output file zh-scim-fcitx-3.1.1.tbz
  Starting download
  
  [ 0%] .......... .......... .......... .......... .......... [ 18.0KB/s]
  安装wget程序
  使用Ports方式安装,查找到wget所在目录,进入目录,执行make install clean安装
  Shell:
  cd /usr/ports/
  make search name=wget
  cd /usr/ports/ftp/wget
  make install clean
  使用方式和axel基本一样。wget+下载的程序名称的url
  Shell:
  cd /root/
  wget ftp://ftp.freebsd.org/pub/FreeBSD/ports/packages/chinese/zh-scim-fcitx-3.1.1.tbz
  
  Step 3 升级Ports-tree.
  
  修改/etc/make.conf,通过axel加速下载: 修改/etc/make.conf,通过axel加速下载,并在编译文件时去除X11相关文件。
  备份/etc/make.conf到/root/make.conf.bak
  Shell:
  cp /etc/make.conf /root/make.conf.bak
  
  修改/etc/make.conf添加axel支持,并添加镜像FTP下载站点
  Shell:
  vi /etc/make.conf
  
  Editor:
  FETCH_CMD=axel
  FETCH_BEFORE_ARGS= -n 10 -a
  FETCH_AFTER_ARGS=
  DISABLE_SIZE=yes
  
  MASTER_SITE_OVERRIDE?=\
  http://ports.hshh.org/${DIST_SUBDIR}/\
  ftp://ftp.tw.freebsd.org/pub/FreeBSD/ports/distfiles/${DIST_SUBDIR}/\
  ftp://ftp.jp.freebsd.org/pub/FreeBSD/ports/distfiles/${DIST_SUBDIR}/\
  ftp://ftp.freeBSDchina.org/pub/FreeBSD/ports/distfiles/${DIST_SUBDIR}/
  ftp://ftp.twaren.net/BSD/FreeBSD/distfiles/${DIST_SUBDIR}/
  ftp://ftp2.tw.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR}/
  ftp://ftp3.tw.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR}/
  ftp://ftp7.tw.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR}/
  ftp://ftp12.tw.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR}/
  ftp://ftp8.tw.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR}/
  ftp://ftp9.tw.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR}/
  ftp://ftp11.tw.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR}/
  ftp://ftp5.tw.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR}/
  ftp://ftp4.tw.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR}/
  ftp://ftp10.tw.freebsd.org/pub/FreeBSD/distfiles/${DIST_SUBDIR}/
  ftp://ftp.freebsd.org/pub/FreeBSD/ports/distfiles/${DIST_SUBDIR}/
  MASTER_SITE_OVERRIDE?=${MASTER_SITE_BACKUP}
  WITHOUT_X11=yes
  
  安装cvsup-without-gui
  使用pkg_add -r cvsup-without-gui命令安装。
  Shell:
  pkg_add -r cvsup-without-gui
  rehash
  
  创建/root/scripts目录,创建ports-update.sh文件
  创建/root/scripts目录
  Shell:
  cd /root
  mkdir /root/scripts
  
  进入/root/scripts目录,创建ports-update.sh文件
  Shell:
  cd /root/scripts/
  vi /root/scripts/ports-update.sh
  内容如下:
  Editor:
  #!/bin/sh
  # updating port
  echo "Beginning Ports Update"
  /usr/local/bin/cvsup -g -L 2 /etc/ports-supfile
  echo "Ports Update Complete"
  对/root/scripts/ports-update.sh文件添加执行权限
  Shell:
  cd /root/scripts/
  chmod +x /root/scripts/ports-update.sh
  
  复制/usr/share/examples/cvsup/ports-supfile到/root/
  Shell:
  cd /root
  cp /usr/share/examples/cvsup/ports-supfile /root/
  测试CVSUP服务器哪个离你最近
  Shell:
  fastest_cvsup -c CN
  >> Speed Daemons:
  - 1st: cvsup4.cn.freebsd.org 32.98 ms
  - 2st: cvsup.cn.freebsd.org 35.68 ms
  - 3st: cvsup5.cn.freebsd.org 50.18 ms
  
  修改ports-supfile文件,选择最近的CVS服务器。(以上测试得知最近的是cvsup4.cn.freebsd.org)
  Shell:
  cd /root
  vi /root/ports-supfile
  修改以下部分
  
  修改前:
  *default host=CHANGE_THIS.FreeBSD.org
  修改后:
  *default host=cvsup4.cn.FreeBSD.org
  
  修改前:
  # collections,
  ports-all
  修改后:
  # collections,
  #ports-all
  
  #ports-audio
  #ports-games
  #ports-graphics
  #ports-x11
  #ports-x11-clocks
  #ports-x11-fm
  #ports-x11-fonts
  #ports-x11-servers
  #ports-x11-themes
  #ports-x11-toolkits
  #ports-x11-wm
  (备注:修改为#ports-all之后,下面的哪个被加#的就表示不同步不升级,没有加#表示要同步升级)
  复制修改好的ports-supfile文件,到/etc/ports-supfile。并且改权限为640只有root用户才可以读写
  Shell:
  cd /root
  cp /root/ports-supfile /etc/ports-supfile
  chmod 640 /etc/ports-supfile
  
  正式开始进行Ports-tree升级
  执行/root/scripts/ports-update.sh文件,进行同步
  Shell:
  /root/scripts/ports-update.sh
  Beginning Ports Update
  Parsing supfile "/etc/ports-supfile"
  Shutting down connection to server
  Finished successfully
  Ports Update Complete
  至此系统同步升级完成。
  
  Step 4 FreeBSD升级系统源代码.
  FreeBSD下升级系统src:
  创建/root/scripts/src-update.sh文件
  进入/root/scripts目录,创建src-update.sh文件
  Shell:
  cd /root/scripts/
  vi /root/scripts/src-update.sh
  内容如下:
  Editor:
  #!/bin/sh
  # updating source
  echo "Beginning Source Update"
  /usr/local/bin/cvsup -g -L 2 /etc/stable-supfile
  echo "Source Update Complete"
  对/root/scripts/src-update.sh文件添加执行权限
  Shell:
  cd /root/scripts/
  chmod +x /root/scripts/src-update.sh
  
  复制/usr/share/examples/cvsup/stable-supfile到/root/
  Shell:
  cd /root
  cp /usr/share/examples/cvsup/stable-supfile /root/
  修改stable -supfile文件,选择最近的CVS服务器。(以上测试得知最近的是cvsup4.cn.freebsd.org)
  Shell:
  cd /root
  vi /root/stable-supfile
  修改以下部分
  
  修改前:
  *default host=CHANGE_THIS.FreeBSD.org
  修改后:
  *default host=cvsup4.cn.FreeBSD.org
  
  修改前:
  *default release=cvs tag=RELENG_6
  修改后:
  *default release=cvs tag=RELENG_6_2
  
  
  复制修改好的stable-supfile文件,到/etc/ stable-supfile。并且改权限为640只有root用户才可以读写
  Shell:
  cd /root
  cp /root/stable-supfile /etc/stable-supfile
  chmod 640 /etc/stable-supfile
  
  正式开始进行系统Src升级
  执行/root/scripts/src-update.sh文件,进行同步
  Shell:
  /root/scripts/src-update.sh
  Beginning Source Update
  Parsing supfile "/etc/stable-supfile"
  Connecting to cvsup4.cn.FreeBSD.org
  Shutting down connection to server
  Finished successfully
  Source Update Complete
  至此系统同步升级完成。
  
  
  Step 5 FreeBSD下的软件包管理.
  FreeBSD下的软件包管理:
  查看系统内都安装了哪些程序
  通过pkg_info命令查询都安装了哪些程序(taball源代码安装的查询不到)
  Shell:
  pkg_info
  cvsup-without-gui-16.1h_2 General network file distribution system optimized for CVS
  fastest_cvsup-0.2.9_4 Finds fastest CVSup server
  gettext-0.14.5_2 GNU gettext package
  libiconv-1.9.2_2 Acharacter set conversion library
  linux_base-fc-4_9 Base set of packages needed in Linux mode (for i386/amd64)
  lsof-4.79D Lists information about open files (similar to fstat(1))
  perl-5.8.8 Practical Extraction and Report Language
  wget-1.10.2 Retrieve files from the Net via HTTP and FTP
  把查询到的结果输出到文件,方便进行统计
  Shell:
  cd /root/
  pkg_info >pkg_list.txt
  less /root/pkg_list.txt
  cvsup-without-gui-16.1h_2 General network file distribution system optimized for CVS
  fastest_cvsup-0.2.9_4 Finds fastest CVSup server
  gettext-0.14.5_2 GNU gettext package
  libiconv-1.9.2_2 Acharacter set conversion library
  linux_base-fc-4_9 Base set of packages needed in Linux mode (for i386/amd64)
  lsof-4.79D Lists information about open files (similar to fstat(1))
  perl-5.8.8 Practical Extraction and Report Language
  wget-1.10.2 Retrieve files from the Net via HTTP and FTP
  
  卸载已安装的软件包
  通过pkg_delete命令卸载已安装的软件包(只适用于pkg_add方式和Ports方式安装的软件包)
  pkg_delete+软件包名称和版本
  Shell:
  pkg_delete wget-1.10.2
  
  升级已安装的软件包
  升级Ports安装的软件包前,先使用pkg_version命令,用来对比已安装的软件包和Ports Collection中的版本信息。参数v显示详细信息
  Shell:
  pkg_version -v
  axel-1.0b = up-to-date with port
  cvsup-without-gui-16.1h_2 < needs updating (port has 16.1h_3)
  db41-4.1.25_4 = up-to-date with port
  fastest_cvsup-0.2.9_4 < needs updating (port has 0.2.9_5)
  gettext-0.14.5_2 < needs updating (port has 0.16.1_3)
  libiconv-1.9.2_2 < needs updating (port has 1.11_1)
  linux_base-fc-4_9 < needs updating (port has 4_10)
  lsof-4.79D = up-to-date with port
  perl-5.8.8 < needs updating (port has 5.8.8_1)
  portupgrade-2.3.1,2 = up-to-date with port
  ruby-1.8.5_3,1 < needs updating (port has 1.8.6.111,1)
  ruby18-bdb-0.6.2 = up-to-date with port
  出现<号说明已安装的程序版本旧了,需要升级。出现=号说明版本是相同的,不需要升级。
  
  在您更新了Ports 套件之后,在升级port 之前,应查看/usr/ports/UPDATING。这个文件中介绍了在升级时用户应注意的问题,以及一些可能需要进行的操作。这可能包括更改文件格式、配置文件位置的变动,以及与先前版本的兼容性等等。
  升级Ports安装的软件方法1、使用portupgrade工具
  安装portupgrade程序
  Shell:
  cd /usr/ports
  make search name=portupgrade
  cd /usr/ports/ports-mgmt/portupgrade/
  make install clean;rehash
  
  Options for portupgrade 2.3.1,2
  [X] B DB4 Use Berkeley DB >=2 as backend
  至此portupgrade程序安装完成。
  
  使用portupgrade来更新Ports
  扫描已安装的port的列表,最好每次升级前执行一下
  Shell:
  pkgdb -F
  
  升级所有安装过的Ports使用portupgrade -a命令,如果想要系统要求确认,加参数i (注:portupgrade -a只能升级通过port方式安装的程序)
  Shell:
  portupgrade -ai
  
  要是想指定优先级,优先升级某一个程序,可以使用参数-R。例如升级(注:portupgrade -a只能升级通过port方式安装的程序)
  Shell:
  portupgrade -R ruby
  
  升级经由pkg_add方式安装的程序,需要使用portupgrade -P+程序名称命令,系统会在本地查找搜索PKG_PATH 中指定的本地目录,如果没有找到,则从远程站点下载。如果远程也没有找到,将使用ports方式安装。(如果要禁止使用port可以指定-PP)
  Shell:
  portupgrade -P cvsup-without-gui
  
  查看系统在安装程序时,都安装哪些文件,放到了哪些地方。使用pkg_info -L 程序名称版本号|less命令
  Shell:
  pkg_info -L axel-1.0b | less
  Information for axel-1.0b:
  
  Files:
  /usr/local/man/man1/axel.1.gz
  /usr/local/bin/axel
  /usr/local/etc/axelrc
  /usr/local/share/locale/de/LC_MESSAGES/axel.mo
  /usr/local/share/locale/nl/LC_MESSAGES/axel.mo
  如查不记得程序版本名称,也可以使用pkg_info | grep -i 程序名称命令进行查询
  Shell:
  pkg_info | grep -i axel
  axel-1.0b A download accelerator
  
  使用Ports安装程序,会在/usr/ports/distfiles目录留有源文件,清理此目录,可以使用portsclean -DD 命令
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: