12.OpenWrt-OPKG包管理

12.OpenWrt-OPKG包管理

Android系统手机都有应用商店,苹果手机也有app store,用来下载安装各种app.在OpenWrt系统中也有自己的 应用商店,OpenWrt是通过OPKG(Open/OpenWrt Package)来管理软件包,OPKG是一个轻量快速的软件包管理系统,用来管理软件包的下载、安装、升级、卸载和查询等,并处理软件包的依赖关系.OPKG不光可以安装应用程序也可以安装驱动程序等,安装的软件可以是编译出来的ipk安装包,也可以是从互联网下载的安装包.

12.1 OPKG 命令

OPKG 的功能主要分两类,一种是软件包的管理命令,另外一种是软件包的查询命令.另外还有很多可以修饰的选项.

12.1.1 软件包的管理

软件包的管理是OPKG最重要的功能,主要包含更新软件包列表、安装、卸载和升级等功能.

1. opkg update

该命令用于更新可以安装的软件包列表.该命令不需要参数,执行时从服务器地址下载软件包列表文件并存储在/var/opkg-lists/目录下.OPKG在安装或升级时需要读取这个文件,这个文件代表当前仓库中所有可用的软件包.也可以删除该文件来释放存储空间,在安装软件前需要重新获取这个文件.

2. opkg install

该命令用于安装软件包, 需要一个参数,传递一个软件包名称.如果软件包之间有依赖关系,会自动下载所有被依赖的软件包,并依次将所有被依赖的软件包安装上.

3. opkg remove

该命令用于卸载软件包,需要一个参数,传递一个软件包名称.需要注意的是,在安装时自动安装的软件包并不会删除,需要自己手动删除,或者在卸载软件包的同时增加(–autoremove)参数将不需要的安装包也删除.示例 3-2 所示代码用于删除 file 软件包及不再使用的依赖包.

4. opkg upgrade

该命令用于升级软件包.如果软件包没有安装,该命令执行之后和“opkg install”效果相同.如果升级多个软件包,以空格分隔列在命令之后即可.例如使用 opkg upgrade ip wget 来升级两个软件包.对大多数用户来说,不推荐升级软件包. OpenWrt 发布后再进行升级大多数情况下是不可能的,这是因为 OpenWrt 发布之后一般不再更新,除非主干的快照被编译机器人(buildbot)自动更新.如果内核升级了,可能带来升级风险,因为内核可能和原始安装的应用软件不兼容.因此一般只升级应用,即非内核软件包.

12.1.2 查询信息

OPKG 查询命令可以在软件仓库中查询,也可以在运行的系统中查询. OPKG 提供了软件包的双向查询功能:正向查询,即从软件包来查询所包含的文件列表;也可以反向查询,从系统中所安装的文件查询所属的软件包.

1. opkg list

该命令用于列出所有可使用的软件包,列出内容格式为:软件包名称 – 版本 – 描述.描述内容是可以有换行的.如果使用 grep 命令来查找软件包则需注意, grep 是单行匹配, 因此使用 grep 查找的结果并不准确.

2. opkg list-installed

该命令用于列出系统中已经安装的软件包.

3. opkg list-changed-conffiles

该命令用于列出用户修改过的配置文件.

4. opkg files

该命令用于列出属于这个软件包( )中的所有文件,这个软件包必须已经安装.

5. opkg search

该命令用于列出提供的软件包,注意:需要传递文件的绝对路径.

6. opkg find

该命令用于列出软件包名称和匹配的软件包. 是一个正则表达式,可以精确匹配,也可以使用星号来模糊匹配,例如使用“net*”或者“net”,均可以匹配 NetCat.

7. opkg info [pkg]

该命令用于显示已安装[pkg]软件包的信息,包含软件包名称、版本、所依赖的软件包名称、安装状态和安装时间等.如果没有指定参数则输出所有已安装软件包的信息.“opkgstatus”和这个命令功能完全相同.

8. opkg download

该命令用于将软件包下载到当前目录.

9. opkg print-architecture

该命令用于列出安装包的架构.

10. opkg whatdepends [-A] [pkg]

该命令用于针对已安装的软件包,输出依赖这个软件包的软件包.

12.2 使用举例

12.2.1 安装软件包

SSH是非常有用的调试工具,可以在同一局域网中连接到板子的Terminal,也可以通过SSH收发文件.有时候并不知道软件包的完整名称,这时候可以通过模糊查找,找到对应的软件包名称来进行安装.

更新软件包 :guilabel:opkg update.
模糊查找关键字 :guilabel:opkg list |grep ssh.
安装软件包 :guilabel:opkg install openssh-server.

 root@GTC-OpenWrt:/# opkg update
   Downloading https://downloads.openwrt.org/snapshots/targets/ramips/mt76x8/packages/Packages.gz
   Updated list of available packages in /var/opkg-lists/openwrt_core
   Downloading https://downloads.openwrt.org/snapshots/targets/ramips/mt76x8/packages/Packages.sig
   Signature check passed.
   Downloading https://downloads.openwrt.org/snapshots/packages/mipsel_24kc/base/Packages.gz
   Updated list of available packages in /var/opkg-lists/openwrt_base
   Downloading https://downloads.openwrt.org/snapshots/packages/mipsel_24kc/base/Packages.sig
   Signature check passed.
   Downloading https://downloads.openwrt.org/snapshots/packages/mipsel_24kc/luci/Packages.gz
   Updated list of available packages in /var/opkg-lists/openwrt_luci
   Downloading https://downloads.openwrt.org/snapshots/packages/mipsel_24kc/luci/Packages.sig
   Signature check passed.
   Downloading https://downloads.openwrt.org/snapshots/packages/mipsel_24kc/packages/Packages.gz
   Updated list of available packages in /var/opkg-lists/openwrt_packages
   Downloading https://downloads.openwrt.org/snapshots/packages/mipsel_24kc/packages/Packages.sig
   Signature check passed.
   Downloading https://downloads.openwrt.org/snapshots/packages/mipsel_24kc/routing/Packages.gz
   Updated list of available packages in /var/opkg-lists/openwrt_routing
   Downloading https://downloads.openwrt.org/snapshots/packages/mipsel_24kc/routing/Packages.sig
   Signature check passed.
   Downloading https://downloads.openwrt.org/snapshots/packages/mipsel_24kc/telephony/Packages.gz
   Updated list of available packages in /var/opkg-lists/openwrt_telephony
   Downloading https://downloads.openwrt.org/snapshots/packages/mipsel_24kc/telephony/Packages.sig
   Signature check passed.

   root@GTC-OpenWrt:~# opkg list |grep ssh
   announce - 1.0.1-1 - Announce services on the network with Zeroconf/Bonjour. This announces services such as ssh, sftp, and http running on the local machine to the network.
   autossh - 1.4g-4 - Autossh client
   avahi-daemon-service-ssh - 0.8-7 - Avahi is an mDNS/DNS-SD (aka RendezVous/Bonjour/ZeroConf) implementation (library). It facilitates service discovery on a local network -- this means that you can plug your laptop or computer into a network and instantly be able to view other people who you can chat with, find printers to print to or find files being shared. This kind of technology is already found in MacOS X (branded 'Rendezvous', 'Bonjour' and sometimes 'ZeroConf') and is very convenient. . This package contains the service definition for announcing SSH service.
   cryptsetup-ssh - 2.5.0-1 - Experimental SSH token support for cryptsetup.
   erlang-ssh - 4.13 - Erlang/OTP is a general-purpose programming language and runtime environment. Erlang has built-in support for concurrency, distribution and fault tolerance. . This Erlang/OTP package provides an implementation of the Secure Shell protocol, with SSH & SFTP support.
   gsocket - 1.4.37-1 - Global Socket allows two workstations on different private networks to communicate with each other. Through firewalls and through NAT - like there is no firewall.  The TCP connection is secured with AES-256 and using OpenSSL's SRP protocol (RFC 5054). It does not require a PKI and has forward secrecy and (optional) TOR support.  The gsocket tools derive temporary session keys and IDs and connect two TCP pipes through the Global Socket Relay Network (GSRN). This is  done regardless and independent of the local IP Address or geographical location.  The session keys (secrets) never leave the workstation. The GSRN sees only the encrypted traffic.  The workhorse is 'gs-netcat' which opens a ssh-like interactive PTY command shell to a remote workstation (which resides on a private and remote network and/or behind a firewall).
   libssh - 0.10.3-1 - libssh is a mulitplatform C library implementing the SSHv2 and SSHv1 protocol for client and server implementations.
   libssh2-1 - 1.10.0-1 - libssh2 is a client-side C library implementing the SSH2 protocol.
   luci-proto-pppossh - git-21.158.38888-88b9d84 - Support for pppossh
   openssh-client - 9.0p1-1 - OpenSSH client.
   openssh-client-utils - 9.0p1-1 - OpenSSH client utilities.
   openssh-keygen - 9.0p1-1 - OpenSSH keygen.
   openssh-moduli - 9.0p1-1 - OpenSSH server moduli file.
   openssh-server - 9.0p1-1 - OpenSSH server.
   openssh-server-pam - 9.0p1-1 - OpenSSH server (with PAM support).
   openssh-sftp-avahi-service - 9.0p1-1 - This package contains the service definition for announcing SFTP support via mDNS/DNS-SD.
   openssh-sftp-client - 9.0p1-1 - OpenSSH SFTP client.
   openssh-sftp-server - 9.0p1-1 - OpenSSH SFTP server.
   pagekitec - 0.91.201110C-2 - PageKite is a system for running publicly visible servers (generally web servers) on machines without a direct connection to the Internet, such as mobile devices or computers behind restrictive firewalls. PageKite works around NAT, firewalls and IP-address limitations by using a combination of tunnels and reverse proxies.  This package provides an implementation of the PageKite Protocol in C, optimized for high-performance or embedded applications.   This package contains a basic backend useful for exposing http/ssh servers.  Basic UCI support for configuring this backend is also included.
   passh - 1.0.1-2 - Passh is an sshpass alternative.
   pppossh - 2 - This package adds protocol support for PPP over SSH.  The protocol name is 'pppossh' as in netifd interface config option 'proto'.
   rrsync - 3.2.7-1 - rrsync is a script which wraps around rsync to restrict its permission to a particular subdirectory via ~/.ssh/authorized_keys and/or to read-only or write-only mode
   sshfs - 3.7.2-3 - Mount remote system over sftp.
   sshpass - 1.09-1 - Sshpass is a tool for non-interactively performing password authentication with SSH's so-called "interactive keyboard password authentication". Most user should use SSH's more secure public-key authentication instead.
   sshtunnel - 4-5 - Creates openssh ssh(1) Local and Remote tunnels configured in UCI file. Can be used to allow remote connections, possibly over NATed connections or without public IP/DNS
   strongswan-mod-sshkey - 5.9.7-8.1 - StrongSwan SSH key decoding plugin
   tmate-ssh-server - 511fd2bd852464e76824279609a34ee93fe148a4-2 - tmate-ssh-server is the server side part of tmate.io.

   root@GTC-OpenWrt:/# opkg install openssh-server
   Installing openssh-server (9.0p1-1) to root...
   Downloading https://downloads.openwrt.org/snapshots/packages/mipsel_24kc/packages/openssh-server_9.0p1-1_mipsel_24kc.ipk
   Installing libopenssl1.1 (1.1.1s-1) to root...
   Downloading https://downloads.openwrt.org/snapshots/packages/mipsel_24kc/base/libopenssl1.1_1.1.1s-1_mipsel_24kc.ipk
   Installing zlib (1.2.12-4) to root...
   Downloading https://downloads.openwrt.org/snapshots/packages/mipsel_24kc/base/zlib_1.2.12-4_mipsel_24kc.ipk
   Installing openssh-keygen (9.0p1-1) to root...
   Downloading https://downloads.openwrt.org/snapshots/packages/mipsel_24kc/packages/openssh-keygen_9.0p1-1_mipsel_24kc.ipk
   Installing libcbor0 (0.8.0-1) to root...
   Downloading https://downloads.openwrt.org/snapshots/packages/mipsel_24kc/packages/libcbor0_0.8.0-1_mipsel_24kc.ipk
   Installing libevdev (1.13.0-1) to root...
   Downloading https://downloads.openwrt.org/snapshots/packages/mipsel_24kc/packages/libevdev_1.13.0-1_mipsel_24kc.ipk
   Installing libudev-zero (1.0.1-1) to root...
   Downloading https://downloads.openwrt.org/snapshots/packages/mipsel_24kc/packages/libudev-zero_1.0.1-1_mipsel_24kc.ipk
   Installing libfido2-1 (1.12.0-1) to root...
   Downloading https://downloads.openwrt.org/snapshots/packages/mipsel_24kc/packages/libfido2-1_1.12.0-1_mipsel_24kc.ipk
   Configuring libevdev.
   Configuring libopenssl1.1.
   Configuring zlib.
   Configuring openssh-keygen.
   Configuring libcbor0.
   Configuring libudev-zero.
   Configuring libfido2-1.
   Configuring openssh-server.

你可能感兴趣的:(服务器,linux,OpenWrt,路由器)