Alpine Linux是一個面向安全應用的輕量級Linux發行版。它采用了musl libc和busybox以減小系統的體積和運行時資源消耗,同時還提供了自己的包管理工具apk。
Alpine Linux的內核都打了grsecurity/PaX補丁,並且所有的程序都編譯為Position Independent Executables (PIE) 以增強系統的安全性。
Alpine Linux的優勢和問題
優勢
- Alpine Linux的Docker鏡像特點是輕巧(大小只有5M)且有完整的包管理工具(APK)。
- Docker官方鏡像可能會用Alpine Linux替換Ubuntu。
問題
- Alpine Linux使用了musl,可能和其他Linux發行版使用的glibc實現會有些不同。
Alpine Linux 包管理
apk包管理命令
Alpine使用apk
進行包管理,通過apk –help命令查看完整的包管理命令,下面列舉常用命令:
update:從遠程鏡像源中更新本地鏡像源索引
update命令會從各個鏡像源列表下載APKINDEX.tar.gz並存儲到本地緩存,一般在/var/cache/apk/(Alpine在該目錄下)、 /var/lib/apk/ 、/etc/apk/cache/下。
apt-update
add命令從倉庫中安裝最新軟件包,並自動安裝必須的依賴包,也可以從第三方倉庫添加軟件包。add:安裝PACKAGES並自動解決依賴關系
$ apk add openssh openntp vim $ apk add --no-cache mysql-client $ apk add docker --update-cache --repository http://mirrors.ustc.edu.cn/alpine/v3.4/main/ --allow-untrusted
安裝指定版本軟件包
$ apk add asterisk=1.6.0.21-r0 $ apk add 'asterisk<1.6.1' $ apk add 'asterisk>1.6.1
del:卸載並刪除PACKAGES
apk del openssh openntp vim
upgrade命令升級系統已安裝的所以軟件包(一般包括內核),當然也可指定僅升級部分軟件包(通過-u或–upgrade選擇指定)。upgrade:升級當前已安裝的軟件包
$ apk update #更新最新本地鏡像源
$ apk upgrade #升級軟件
$ apk add --upgrade busybox #指定升級部分軟件包
search命令搜索可用軟件包,-v參數輸出描述內容,支出通配符,-d或–description參數指定通過軟件包描述查詢。search:搜索軟件包
$ apk search #查找所以可用軟件包
$ apk search -v #查找所以可用軟件包及其描述內容
$ apk search -v 'acf*' #通過軟件包名稱查找軟件包
$ apk search -v -d 'docker' #通過描述文件查找特定的軟件包
info命令用於顯示軟件包的信息。info:列出PACKAGES或鏡像源的詳細信息
$ apk info #列出所有已安裝的軟件包
$ apk info -a zlib #顯示完整的軟件包信息
$ apk info --who-owns /sbin/lbu #顯示指定文件屬於的包
官方鏡像列表:http://rsync.alpinelinux.org/alpine/MIRRORS.txt鏡像源配置
MIRRORS.txt中是當前Alpine官方提供的鏡像源(Alpine安裝的時候系統自動選擇最佳鏡像源)
- 國內鏡像源
清華TUNA鏡像源:https://mirror.tuna.tsinghua.edu.cn/alpine/
中科大鏡像源:http://mirrors.ustc.edu.cn/alpine/
阿里雲鏡像源:http://mirrors.aliyun.com/alpine/
如何配置軟件源
以中科大源為例:在/etc/apk/repositories
文件中加入對應源地址就行了,一行一個地址。
$ vi /etc/apk/repositories
# /media/cdrom/apks
http://mirrors.ustc.edu.cn/alpine/v3.5/main
http://mirrors.ustc.edu.cn/alpine/v3.5/community
Alpine Linux使用的是Gentoo
一樣的OpenRC
init系統.Alpine Linux init系統
以下命令可用於管理init系統
- rc-update
rc-update主要用於不同運行級增加或者刪除服務。
rc-update語法格式
Usage: rc-update [options] add <service> [<runlevel>...] or: rc-update [options] del <service> [<runlevel>...] or: rc-update [options] [show [<runlevel>...]] Options: [ asuChqVv ] -a, --all Process all runlevels -s, --stack Stack a runlevel instead of a service -u, --update Force an update of the dependency tree -h, --help Display this help output -C, --nocolor Disable color output -V, --version Display software version -v, --verbose Run verbosely -q, --quiet Run quietly (repeat to suppress errors)
使用實例
$ rc-update add docker boot #增加一個服務
$ rc-update del docker boot #刪除一個服務
- rc-status
rc-status 主要用於運行級的狀態管理。
rc-status語法格式
Usage: rc-status [options] <runlevel>... or: rc-status [options] [-a | -c | -l | -r | -s | -u] Options: [ aclrsuChqVv ] -a, --all Show services from all run levels -c, --crashed Show crashed services -l, --list Show list of run levels -r, --runlevel Show the name of the current runlevel -s, --servicelist Show service list -u, --unused Show services not assigned to any runlevel -h, --help Display this help output -C, --nocolor Disable color output -V, --version Display software version -v, --verbose Run verbosely -q, --quiet Run quietly (repeat to suppress errors)
使用實例
$ rc-status #檢查默認運行級別的狀態
$ rc-status -a #檢查所有運行級別的狀態
- rc-service
rc-service主用於管理服務的狀態
rc-service語法格式
Usage: rc-service [options] [-i] <service> <cmd>... or: rc-service [options] -e <service> or: rc-service [options] -l or: rc-service [options] -r <service> Options: [ e:ilr:INChqVv ] -e, --exists <arg> tests if the service exists or not -i, --ifexists if the service exists then run the command -I, --ifinactive if the service is inactive then run the command -N, --ifnotstarted if the service is not started then run the command -l, --list list all available services -r, --resolve <arg> resolve the service name to an init script -h, --help Display this help output -C, --nocolor Disable color output -V, --version Display software version -v, --verbose Run verbosely -q, --quiet Run quietly (repeat to suppress errors)
使用實例
$ rc-service sshd start #啟動一個服務。
$ rc-service sshd stop #停止一個服務。
$ rc-service sshd restart #重啟一個服務。
- openrc
openrc主要用於管理不同的運行級。
openrc語法格式
Usage: openrc [options] [<runlevel>] Options: [ a:no:s:SChqVv ] -n, --no-stop do not stop any services -o, --override <arg> override the next runlevel to change into when leaving single user or boot runlevels -s, --service <arg> runs the service specified with the rest of the arguments -S, --sys output the RC system type, if any -h, --help Display this help output -C, --nocolor Disable color output -V, --version Display software version -v, --verbose Run verbosely -q, --quiet Run quietly (repeat to suppress errors)
defaultAlpine Linux可用的運行級
- sysinit
- boot
- single
- reboot
- shutdown
使用實例
$ openrc single #更改為single運行級
其它指令
$ reboot #重啟系統,類似於shutdown -r now。
$ halt #關機,類似於shutdown -h now。
$ poweroff #關機
參考文檔
http://www.google.com
http://t.cn/RizgdLy
https://wiki.alpinelinux.org/wiki/Alpine_Linux_Init_System
https://wiki.alpinelinux.org/wiki/Alpine_Linux_package_management
轉自:https://www.hi-linux.com/posts/64839.html?utm_source=tuicool&utm_medium=referral