一:Alpine Linux開啟SSH遠程登陸
1.簡介:
最重要的一個服務了,遠程登陸需要用它,文件傳輸需要用它,必備功能。不管你是在實體機上跑,虛擬機上跑,docker里面跑,這個都是必須的。
2.配置
配置文件位置:/etc/ssh/sshd_config
配置文件選項:#PermitRootLogin prohibit-password
修改為:PermitRootLogin yes
3.配置命令
看不懂上面的,直接用下面這句。
sed -i "s/#PermitRootLogin.*/PermitRootLogin yes/g" /etc/ssh/sshd_config
4.重啟服務
改了配置不會直接生效,需要重啟服務器或者服務。
重啟服務器:reboot
重啟服務:rc-service sshd restart
二:Alpine Linux源管理
1.簡介
源這個概念在linux早就存在了,其實就是類似於軟件市場的存在,apple在iphone上發揚光大了,並且自己管理安全的軟件,使得iphone上軟件兼容性等等問題得到改善,用戶體驗比較好,android基於linux核心開發,也有了軟件市場,最著名的就是google市場,因為被牆,所以國內各個大軟件廠商也都有了自己的市場。
每個市場(源)都有自己的服務器,linux默認的都是外國的服務器,我們訪問比較慢,所以就有了鏡像服務器放在國內,讓我們訪問快一些。管理源,就是增加鏡像服務器。
而且,linux因為是大眾維護更新代碼,所以還區分了穩定版,測試版……各種版本的市場,這些都需要進行源管理。
2.國內源簡介:
這幾個都有alpine的源
清華大學:https://mirror.tuna.tsinghua.edu.cn/alpine/
阿里雲:https://mirrors.aliyun.com/alpine/
中科大:http://mirrors.ustc.edu.cn/alpine/
還有一些沒有alpine的
網易:http://mirrors.163.com/
3.配置:
直接抄中科大的幫助http://mirrors.ustc.edu.cn/help/alpine.html
一般情況下,將 /etc/apk/repositories
文件中 Alpine 默認的源地址 http://dl-cdn.alpinelinux.org/
替換為 http://mirrors.ustc.edu.cn/
即可。
可以使用如下命令:
sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
也可以直接編輯 /etc/apk/repositories
文件。以下是 v3.5 版本的參考配置:
https://mirrors.ustc.edu.cn/alpine/v3.5/main https://mirrors.ustc.edu.cn/alpine/v3.5/community
也可以使用 latest-stable
指向最新的穩定版本:
https://mirrors.ustc.edu.cn/alpine/latest-stable/main https://mirrors.ustc.edu.cn/alpine/latest-stable/community
更改完 /etc/apk/repositories
文件后請運行 apk update
更新索引以生效。
3.我的配置:
打開/etc/apk/repositories后發現,中科大的sed命令無效,因為默認的源不是dl-cdn
自己改一下吧
原:
#/media/cdrom/apks http://ftp.halifax.rwth-aachen.de/alpine/v3.7/main #http://ftp.halifax.rwth-aachen.de/alpine/v3.7/community #http://ftp.halifax.rwth-aachen.de/alpine/edge/main #http://ftp.halifax.rwth-aachen.de/alpine/edge/community #http://ftp.halifax.rwth-aachen.de/alpine/edge/testing http://mirror.yandex.ru\/mirrors/alpine/v3.7/main #http://mirror.yandex.ru\/mirrors/alpine/v3.7/community #http://mirror.yandex.ru\/mirrors/alpine/edge/main #http://mirror.yandex.ru\/mirrors/alpine/edge/community #http://mirror.yandex.ru\/mirrors/alpine/edge/testing
改為:
http://mirrors.ustc.edu.cn/alpine/v3.7/main http://mirrors.ustc.edu.cn/alpine/v3.7/community http://mirrors.ustc.edu.cn/alpine/edge/main http://mirrors.ustc.edu.cn/alpine/edge/community http://mirrors.ustc.edu.cn/alpine/edge/testing
也可以復制下面這組命令,一次執行
echo http://mirrors.ustc.edu.cn/alpine/v3.7/main >/etc/apk/repositories echo http://mirrors.ustc.edu.cn/alpine/v3.7/community >>/etc/apk/repositories echo http://mirrors.ustc.edu.cn/alpine/edge/main >>/etc/apk/repositories echo http://mirrors.ustc.edu.cn/alpine/edge/community >>/etc/apk/repositories echo http://mirrors.ustc.edu.cn/alpine/edge/testing >>/etc/apk/repositories
或者
echo 'http://mirrors.ustc.edu.cn/alpine/v3.7/main http://mirrors.ustc.edu.cn/alpine/v3.7/community http://mirrors.ustc.edu.cn/alpine/edge/main http://mirrors.ustc.edu.cn/alpine/edge/community http://mirrors.ustc.edu.cn/alpine/edge/testing' >/etc/apk/repositories
三:Alpine Linux 包管理
1.簡介
Alpine使用apk
進行包管理,下面介紹常用命令
2.apk update
$ apk update #更新最新鏡像源列表
3.apk search
$ apk search #查找所以可用軟件包
$ apk search -v #查找所以可用軟件包及其描述內容
$ apk search -v 'acf*' #通過軟件包名稱查找軟件包
$ apk search -v -d 'docker' #通過描述文件查找特定的軟件包
4.apk add
$ apk add openssh #安裝一個軟件
$ apk add openssh openntp vim #安裝多個軟件
$ apk add --no-cache mysql-client #不使用本地鏡像源緩存,相當於先執行update,再執行add
5.apk info
$ apk info #列出所有已安裝的軟件包
$ apk info -a zlib #顯示完整的軟件包信息
$ apk info --who-owns /sbin/lbu #顯示指定文件屬於的包
6.apk upgrade
$ apk upgrade #升級所有軟件
$ apk upgrade openssh #升級指定軟件
$ apk upgrade openssh openntp vim #升級多個軟件
$ apk add --upgrade busybox #指定升級部分軟件包
7.apk del
$ apk del openssh #刪除一個軟件
四:Alpine Linux服務管理
1.簡介
alpine沒有使用fedora的systemctl來進行服務管理,使用的是RC系列命令
2.rc-update
rc-update主要用於不同運行級增加或者刪除服務。
alpine:~# rc-update --help 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)
3.rc-status
rc-status 主要用於運行級的狀態管理。
alpine:~# rc-status --help Usage: rc-status [options] <runlevel>... or: rc-status [options] [-a | -c | -l | -m | -r | -s | -u] Options: [ aclmrsuChqVv ] -a, --all Show services from all run levels -c, --crashed Show crashed services -l, --list Show list of run levels -m, --manual Show manually started services -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)
4.rc-service
rc-service主用於管理服務的狀態
alpine:~# rc-service --help 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: [ ce:ilr:INChqVv ] -e, --exists <arg> tests if the service exists or not -c, --ifcrashed if the service is crashed then run the command -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)
5.openrc
openrc主要用於管理不同的運行級。
alpine:~# openrc --help 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)
6.我常用的RC系列命令
1.增加服務到系統啟動時運行,下例為docker
rc-update add docker boot
2.重啟網絡服務
rc-service networking restart
3.列出所有服務
rc-status -a
五:關機重啟
$ reboot #重啟系統
$ poweroff #關機
轉載: