https://www.hi-linux.com/posts/64839.html
Alpine Linux是一個(gè)面向安全應(yīng)用的輕量級(jí)Linux發(fā)行版嘴脾。它采用了musl libc和busybox以減小系統(tǒng)的體積和運(yùn)行時(shí)資源消耗泉褐,同時(shí)還提供了自己的包管理工具apk已脓。
Alpine Linux的內(nèi)核都打了grsecurity/PaX補(bǔ)丁特姐,并且所有的程序都編譯為Position Independent Executables (PIE) 以增強(qiáng)系統(tǒng)的安全性侈净。
Alpine Linux的優(yōu)勢(shì)和問題
優(yōu)勢(shì)
- Alpine Linux的Docker鏡像特點(diǎn)是輕巧(大小只有5M)且有完整的包管理工具(APK)疯坤。
- Docker官方鏡像可能會(huì)用Alpine Linux替換Ubuntu。
問題
- Alpine Linux使用了musl靶剑,可能和其他Linux發(fā)行版使用的glibc實(shí)現(xiàn)會(huì)有些不同蜻拨。
Alpine Linux 包管理
apk包管理命令
Alpine使用apk
進(jìn)行包管理,通過apk --help命令查看完整的包管理命令桩引,下面列舉常用命令:
- update:從遠(yuǎn)程鏡像源中更新本地鏡像源索引
update命令會(huì)從各個(gè)鏡像源列表下載APKINDEX.tar.gz并存儲(chǔ)到本地緩存缎讼,一般在/var/cache/apk/(Alpine在該目錄下)、 /var/lib/apk/ 坑匠、/etc/apk/cache/下血崭。
$ apk update
- add:安裝PACKAGES并自動(dòng)解決依賴關(guān)系
add命令從倉(cāng)庫(kù)中安裝最新軟件包,并自動(dòng)安裝必須的依賴包,也可以從第三方倉(cāng)庫(kù)添加軟件包笛辟。
$ 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:升級(jí)當(dāng)前已安裝的軟件包
upgrade命令升級(jí)系統(tǒng)已安裝的所以軟件包(一般包括內(nèi)核)功氨,當(dāng)然也可指定僅升級(jí)部分軟件包(通過-u或–upgrade選擇指定)。
$ apk update #更新最新本地鏡像源
$ apk upgrade #升級(jí)軟件
$ apk add --upgrade busybox #指定升級(jí)部分軟件包
- search:搜索軟件包
search命令搜索可用軟件包手幢,-v參數(shù)輸出描述內(nèi)容,支出通配符忱详,-d或–description參數(shù)指定通過軟件包描述查詢围来。
$ apk search #查找所以可用軟件包
$ apk search -v #查找所以可用軟件包及其描述內(nèi)容
$ apk search -v 'acf*' #通過軟件包名稱查找軟件包
$ apk search -v -d 'docker' #通過描述文件查找特定的軟件包
- info:列出PACKAGES或鏡像源的詳細(xì)信息
info命令用于顯示軟件包的信息。
$ apk info #列出所有已安裝的軟件包
$ apk info -a zlib #顯示完整的軟件包信息
$ apk info --who-owns /sbin/lbu #顯示指定文件屬于的包
鏡像源配置
MIRRORS.txt中是當(dāng)前Alpine官方提供的鏡像源(Alpine安裝的時(shí)候系統(tǒng)自動(dòng)選擇最佳鏡像源)
- 國(guó)內(nèi)鏡像源
清華TUNA鏡像源:https://mirror.tuna.tsinghua.edu.cn/alpine/
中科大鏡像源:http://mirrors.ustc.edu.cn/alpine/
阿里云鏡像源:http://mirrors.aliyun.com/alpine/
如何配置軟件源
以中科大源為例:在/etc/apk/repositories
文件中加入對(duì)應(yīng)源地址就行了匈睁,一行一個(gè)地址监透。
$ 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 init系統(tǒng)
Alpine Linux使用的是Gentoo
一樣的OpenRC
init系統(tǒng).
以下命令可用于管理init系統(tǒng)
- rc-update
rc-update主要用于不同運(yùn)行級(jí)增加或者刪除服務(wù)。
rc-update語(yǔ)法格式
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)
使用實(shí)例
$ rc-update add docker boot #增加一個(gè)服務(wù)
$ rc-update del docker boot #刪除一個(gè)服務(wù)
- rc-status
rc-status 主要用于運(yùn)行級(jí)的狀態(tài)管理航唆。
rc-status語(yǔ)法格式
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)
使用實(shí)例
$ rc-status #檢查默認(rèn)運(yùn)行級(jí)別的狀態(tài)
$ rc-status -a #檢查所有運(yùn)行級(jí)別的狀態(tài)
- rc-service
rc-service主用于管理服務(wù)的狀態(tài)
rc-service語(yǔ)法格式
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)
使用實(shí)例
$ rc-service sshd start #啟動(dòng)一個(gè)服務(wù)胀蛮。
$ rc-service sshd stop #停止一個(gè)服務(wù)。
$ rc-service sshd restart #重啟一個(gè)服務(wù)糯钙。
- openrc
openrc主要用于管理不同的運(yùn)行級(jí)粪狼。
openrc語(yǔ)法格式
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)
Alpine Linux可用的運(yùn)行級(jí)
- default
- sysinit
- boot
- single
- reboot
- shutdown
使用實(shí)例
$ openrc single #更改為single運(yùn)行級(jí)
- 其它指令
$ reboot #重啟系統(tǒng),類似于shutdown -r now任岸。
$ halt #關(guān)機(jī)再榄,類似于shutdown -h now。
$ poweroff #關(guān)機(jī)
參考文檔
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