Total Pageviews

Thursday, 13 June 2019

centos 7的新一代包管理工具-snap

snap简介

什么是snap,snap是一种全新的软件包管理方式,它类似一个容器拥有一个应用程序所有的文件和库,各个应用程序之间完全独立。所以使用snap包的好处就是它解决了应用程序之间的依赖问题,使应用程序之间更容易管理。但是由此带来的问题就是它占用更多的磁盘空间。
Snap的安装包扩展名是.snap,类似于一个容器,它包含一个应用程序需要用到的所有文件和库(snap包包含一个私有的root文件系统,里面包含了依赖的软件包)。它们会被安装到单独的目录;各个应用程序之间相互隔离。使用snap有很多好处,首先它解决了软件包的依赖问题;其次,也使应用程序更容易管理。
现在支持snap的应用并不多,snap软件包一般安装在/snap目录下

安装

安装 EPEL

yum install epel-release

安装 snapd

yum install snapd

添加snap启动通信 socket

systemctl enable --now snapd.socket

创建链接(snap软件包一般安装在/snap目录下)

ln -s /var/lib/snapd/snap /snap

参考文档

常用的命令

### 切换软件仓库

#扩展
snap refresh hugo --channel=extended 

#稳定
snap refresh hugo --channel=stable.

### 更新一个snap包,
如果你后面不加包的名字的话那就是更新所有的snap包

sudo snap refresh 

### 列出已经安装的snap包

sudo snap list

### 搜索要安装的snap包

sudo snap find 

### 安装一个snap包

sudo snap install 

### 把一个包还原到以前安装的版本

snap revert 

### 删除一个snap包
sudo snap remove 

实例-安装hugo

snap install hugo
又如:

root@server:~# snap install rocketchat-server
2019-06-13T20:17:37+08:00 INFO Waiting for restart...
rocketchat-server 1.0.3 from Rocket.Chat (rocketchat) installed
root@server:~#
-----------------------
Ubuntu 16.04/debian9/debian10 vps上,通过Snap安装应用程序
16.04LTS可以说是一个不寻常的5年支持版本,同时也带来了Snap应用,并通过Snap可以安装众多的软件包。需要注意的是,Snap是一个全新的软件包架构,但是同样也比其它的软件包大很多。
简单的安装步骤:
ubuntu 16.04系统/debian10系统已经默认安装了Snap,所以有些系统执行了update之后会提示更新到新版本,这里不建议再装,不然下面安装应用程序会卡死。
sudo apt install snapd snappy
安装应用
sudo snap install electronic-wechat deepin-music
经过测试发现snap安装软件不稳定,并且安装的包无法运行,所以现在使用这个安装还不太靠谱,还是用deb包吧!!!
参考:
http://www.sohu.com/a/69162826_116172
---------------------------------------------------

This repo introduces support the bundling/delivering shadowsocks/ChinaDNS through the 'snap' mechanism/store - for more details see https://snapcraft.io.  

"A snap is a bundle of your app and its dependencies that works without modification across Linux. Snaps are discoverable and installable from the Snap store, an app store with an audience of millions." [1]
In case the support/snapcraft.yaml file is accepted it can be published in the Snap Store [2] which is required for people to easily install it.

Build/Snap

$ sudo apt install -y build-essential squashfuse
$ sudo snap install --classic snapcraft
$ git clone https://github.com/shadowsocks/chinadns-snap.git
$ cd chinadns-snap
$ snapcraft
Installing build dependencies: autoconf automake autopoint autotools-dev libltdl-dev libltdl7 libtool m4
...
Pulling chinadns 
Cloning into '/home/ubuntu/chinadns-snap/parts/chinadns/src'...
...
Building chinadns 
env NOCONFIGURE=1 ./autogen.sh
configure.ac:12: installing './compile'
configure.ac:9: installing './install-sh'
configure.ac:9: installing './missing'
src/Makefile.am: installing './depcomp'
./configure --prefix=
...
make -j4
...
Staging chinadns 
Priming chinadns 
Snapping 'chinadns' |                                                                                          
Snapped chinadns_master_amd64.snap

Install/Contents

$ sudo snap install ./chinadns_master_amd64.snap --dangerous --classic
chinadns master installed

$ which chinadns 
/snap/bin/chinadns

$ find /snap/chinadns/
/snap/chinadns/
/snap/chinadns/current
/snap/chinadns/x1
/snap/chinadns/x1/bin
/snap/chinadns/x1/bin/chinadns
/snap/chinadns/x1/command-chinadns.wrapper
/snap/chinadns/x1/meta
/snap/chinadns/x1/meta/gui
/snap/chinadns/x1/meta/snap.yaml
/snap/chinadns/x1/share
/snap/chinadns/x1/share/chnroute.txt
/snap/chinadns/x1/share/iplist.txt

Testing

Run chinadns in a shell:
$ sudo -i
# curl 'http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest' | grep ipv4 | grep CN | awk -F\| '{ printf("%s/%d\n", $4, 32-log($5)/log(2)) }' > ~/chnroute.txt
# chinadns -m -c ~/chnroute.txt -s 114.114.114.114,8.8.8.8 -p 5354 -v
Fri Dec 14 14:53:48 2018 request google.com
Fri Dec 14 14:53:48 2018 response google.com from 114.114.114.114:53 - 216.58.197.110, filter
Fri Dec 14 14:53:48 2018 response google.com from 8.8.8.8:53 - 216.58.197.110, pass
Fri Dec 14 14:53:48 2018 response google.com from 114.114.114.114:53 - 216.58.200.14, filter
Fri Dec 14 14:53:48 2018 response google.com from 8.8.8.8:53 - 172.217.160.110, pass
then test chinadns in another shell, it looks like:
$ dig google.com @127.0.0.1 -p 5354

; <<>> DiG 9.11.3-1ubuntu1.2-Ubuntu <<>> google.com @127.0.0.1 -p 5354
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- 0="" 127.0.0.1="" 14:53:48="" 14="" 1="" 2018="" 216.58.197.110="" 24="" 3600="" 38446="" 51220="" 78="" a="" additional:="" additional="" answer:="" answer="" authority:="" caishikou.redirect.="" code="" cst="" dec="" flags:="" fri="" google.com.="" id:="" in="" msec="" msg="" noerror="" opcode:="" qr="" query:="" query="" question="" ra="" rcvd:="" rd="" section:="" server:="" size="" status:="" time:="" when:="">

Reference

  1. "Creating a snap" in https://docs.snapcraft.io/creating-a-snap/6799
  2. "Share with your friends" in https://docs.snapcraft.io/c-c-applications/7817
  3. "Demystifying Snap Confinement" in https://snapcraft.io/blog/demystifying-snap-confinement
  4. "Commands and aliases" in https://docs.snapcraft.io/commands-and-aliases/3950
from  https://github.com/zhhuabj/chinadns-snap

No comments:

Post a Comment