欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

FreeBSD--如何最有效率的安装软件

程序员文章站 2022-08-29 15:39:03
Freebsd 下如何最有效率的安装软件 From FreeBSD的默认下载工具是fetch Fetch ftp://ftp.gnu.org/gnu/gettext/Gettext-0.17.tar.g ......

 

From <>

FreeBSD的默认下载工具是fetch

Fetch ftp://ftp.gnu.org/gnu/gettext/Gettext-0.17.tar.gz

 

Ports机制

首先,FreeBSD下最有特色的软件安装和升级机制就是ports,既方便又高效。下面我们从ports套件的安装开始讲起,让你细致的了解有关ports的每一个细节

一、ports套件的安装

①我的FreeBSD 8.0-release是最小化安装,所以既没有ports,也没有/usr/ports目录。选择启用ports的话,需要在root下输入"sysinstall"来安装它:

输入sysinstall --> 选择Configure --> Distributions --> ports,然后安装即可。

②ports的默认路径是/usr/ports。这个ports的根目录下面有很多的文件夹及子文件夹,组成一个树状目录,包含大量ports下的软件。比如mail是邮件服务软件,games是游戏,www代表web服务软件,databases则是数据库软件。

[root@bsd01 /usr/ports]# cd www
[root@bsd01 /usr/ports/www]# ls -d apache*
apache-contrib apache13 apache13-modssl+ipv6
apache-forrest apache13+ipv6 apache13-ssl
apache-jserv apache13-modperl apache20
apache-mode.el apache13-modssl apache22

如果你需要安装什么软件,只要进入当前目录,然后“make install clean”即可。

[root@bsd01 ~]# cd /usr/ports/www/apache22
[root@bsd01 /usr/ports/www/apache22] make install clean

/usr/ports/distfiles是存放软件包的文件夹。ports会先检查/usr/ports/distfiles目录内有没有这个软件包,如果没有它就会自动从网上下载安装。

二、加速ports的升级速度

ports从网上下载软件包自动安装,那么从那里下载呢?首先,我们需要安装axel来取代默认的下载工具fetch,这样可以提高ports的安装速度:

cd /usr/ports/ftp/axel
make install

然后,我们需要一个源地址管理。跟ubuntu上的/etc/source.list文件一样,freebsd用的文件是/etc/make.conf,我们可以修改其文件,达到加速下载的目的。

#修改 /et/make.conf
vi /etc/make.conf
#加入以下内容
FETCH_CMD=axel
FETCH_BEFORE_ARGS= -n 10 -a
FETCH_AFTER_ARGS=
DISABLE_SIZE=yes
MASTER_SITE_OVERRIDE?=\


ftp://ftp.freebsdchina.org/pub/FreeBSD/ports/distfiles/$%7BDIST_SUBDIR%7D/
MASTER_SITE_OVERRIDE?=${MASTER_SITE_BACKUP}      

这样处理后,在公司的网络环境下,FreeBSD的下载速度明显提高了,有时居然能达到1M/s,这样升级及安装软件方便极了;呵呵,终于可以摆脱fetch的龟速了。

三、更新ports目录树

既然ports的树目录全部下载到本地,那么即使FreeBSD有新的软件包或者添置了新的软件,本地目录树也不会更新。所以,我们每隔一段时间需要更新本地目录树。我来介绍一种在FreeBSD中方便、快捷的更新ports的方法:使用portsnap来更新ports目录树。

①配置portsnap:

我们使用portsnap,首先要设置一下它的配置文件,位于/etc/portsnap.conf:

[root@bsd01 /usr/ports]# vi /etc/portsnap.conf

SERVERNAME=portsnap.freebsd.org

修改成:

SERVERNAME=portsnap.hshh.org

这个是他的更新服务器。另外还有几个国内比较快的portsnap服务器:

portsnap.hshh.org

portsnap2.hshh.org

portsnap3.hshh.org (网通)

portsnap4.hshh.org

②首次使用portsnap:

在你的FreeBSD首次使用portsnap必须执行下面2步:

[root@bsd01 ~]# portsnap fetch
[root@bsd01 ~]# portsnap extract

portsnap fecth是从网上获取portsnap快照的最新压缩包,听闻这个压缩包官方没小时更新一次。

portsnap extract 则是把这个压缩包创立到/usr/ports。哪怕你以前已经手工安装了ports,他也会重新创立一次。

(注:这2步可以合成使用,指令为 [root@bsd01 ~]# portsnap fetch extract)

③以后使用portsnap更新,只需要执行下面2步:

[root@bsd01 ~]# portsnap fetch
[root@bsd01 ~]# portsnap update

同样,这2步可以合成使用:[root@bsd01 ~]# portsnap fetch update

portsnap第一次运行extract命令时,可能需要一段时间,以后更新使用update的时候,速度就快很多了。

 

From <>

 

Pkg 用法

Usage: pkg [-v] [-d] [-l] [-N] [-j <jail name or id>|-c <chroot path>|-r <rootdir>] [-C <configuration file>] [-R <repo config dir>] [-o var=value] [-4|-6] <command> [<args>]

Global options supported:

        -d             Increment debug level

        -j             Execute pkg(8) inside a jail(8)

        -r             Execute pkg(8) using relocating installation to <rootdir>

        -c             Execute pkg(8) inside a chroot(8)

        -C             Use the specified configuration file

        -R             Directory to search for individual repository configurations

        -l             List available commands and exit

        -v             Display pkg(8) version

        -N             Test if pkg(8) is activated and avoid auto-activation

        -o             Override configuration option from the command line

        -4             Only use IPv4

        -6             Only use IPv6

 

Commands supported:

        add            Compatibility interface to install a package

        alias          List the command line aliases

        annotate       Add, modify or delete tag-value style annotations on packages

        audit          Reports vulnerable packages

        autoremove     Removes orphan packages

        backup         Backs-up and restores the local package database

        check          Checks for missing dependencies and database consistency

        clean          Cleans old packages from the cache

        config         Display the value of the configuration options

        convert        Convert database from/to pkgng

        create         Creates software package distributions

        delete         Deletes packages from the database and the system

        fetch          Fetches packages from a remote repository

        help           Displays help information

        info           Displays information about installed packages

        install        Installs packages from remote package repositories and local archives

        lock           Locks package against modifications or deletion

        plugins        Manages plugins and displays information about plugins

        query          Queries information about installed packages

        register       Registers a package into the local database

        remove         Deletes packages from the database and the system

        repo           Creates a package repository catalogue

        rquery         Queries information in repository catalogues

        search         Performs a search of package repository catalogues

        set            Modifies information about packages in the local database

        ssh            Package server (to be used via ssh)

        shell          Opens a debug shell

        shlib          Displays which packages link against a specific shared library

        stats          Displays package database statistics

        unlock         Unlocks a package, allowing modification or deletion

        update         Updates package repository catalogues

        updating       Displays UPDATING information for a package

        upgrade        Performs upgrades of packaged software distributions

        version        Displays the versions of installed packages

        which          Displays which package installed a specific file

 

Commands provided by plugins:

 

For more information on the different commands see 'pkg help <command>'.

 

pkg install -- install packages from remote package repositories or local
     archives



     The following options are supported by pkg        install:

-A, --automatic
                Mark the installed packages as automatic. Will        be automati-
                cally removed if no other packages depend on them. For        more
                information please refer to .

-C, --case-sensitive
                Make the standard or the regular expression (-x) matching
                against        pkg-name case sensitive.

-f, --force
                Force the reinstallation of the        package        if already installed.

-g, --glob
                Treat the package names        as shell glob patterns.

-I, --no-install-scripts
                If any installation scripts (pre-install or post-install)
                exist for a given package, do not execute them.         When a        pack-
                age is updated,        deinstallation scripts (pre-deinstall or post-
                deinstall) are not run either.

-i, --case-insensitive
                Make the standard or the regular expression (-x) matching
                against        pkg-name case insensitive. This is the        default,
                unless modified        by setting CASE_SENSITIVE_MATCH        to true        in
                pkg.conf.

-M, --ignore-missing
                Force the installation of the package with missing dependen-
                cies.

-n, --dry-run
                Dry-run        mode. The list        of changes to packages is always
                printed, but no        changes        are actually made.

-F, --fetch-only
                Do not perform actual installation of packages,        merely fetch
                packages that should be        upgraded and detect possible con-
                flicts.

-q, --quiet
                Force quiet output, except when        -n is used, where pkg install
                will always show packages to be        installed, upgraded or
                deleted.

-R, --recursive
                When used with -f, reinstalls any packages that        require        the
                given package.

-r        reponame, --repository reponame
                Install        packages from only the named repository, irrespective
                of the configured ``active'' status from repo.conf.

-U, --no-repo-update
                Suppress the automatic update of the local copy        of the reposi-
                tory catalogue from remote. Automatic repository catalogue
                updates        are only attempted when        the effective UID of the
                process        has write access to the        package        database. Otherwise
                they are silently ignored.

-x, --regex
                Treat the package names        as regular expressions according to
                the "modern" or        "extended" syntax of .

-y, --yes        Assume yes when        asked for confirmation before package instal-
                lation.

 

From <>