欢迎阅读我的笔记博客

30) Alpine 命令

0- 简介

0.1- 特点

  1. 小巧:基于Musl libc和busybox,和busybox一样小巧,最小的Docker镜像只有5MB;
  2. 安全:面向安全的轻量发行版;
  3. 简单:提供APK包管理工具,软件的搜索、安装、删除、升级都非常方便。
  4. 适合容器使用:由于小巧、功能完备,非常适合作为容器的基础镜像。

0.2- Docker下的运行

docker pull alpine
docker run -it --name myalpine alpine

0.3- 作为Docker容器的基础镜像

_ _ _以Alpine为基础镜像,创建一个MySQL容器:
Dockerfile文件的内容:

FROM alpine:3.6
RUN apk add --no-cache mysql-client
ENTRYPOINT ["mysql"]

0.4- 网卡配置文件

/etc/network/interfaces
/etc/init.d/networking restart #重启网络

1- Alpine Linux源管理

1.1- 国内源

  1. 清华大学:https://mirror.tuna.tsinghua.edu.cn/alpine/
  2. 阿里云:https://mirrors.aliyun.com/alpine/3.
  3. 中科大:http://mirrors.ustc.edu.cn/alpine/

1.2- 配置

_ _ _ 将 /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 文件:

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

最后:

apk update

1.3- 执行命令

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

2- Alpine包管理

_ _ _ Alpine使用apk进行包管理

2.1- apk命令

2.1.1- apk update

apk update #更新最新镜像源列表
apk search #查找所以可用软件包
apk search -v #查找所以可用软件包及其描述内容
apk search -v 'acf*' #通过软件包名称查找软件包
apk search -v -d 'docker' #通过描述文件查找特定的软件包

2.1.3- apk add

apk add openssh #安装一个软件
apk add openssh openntp vim   #安装多个软件
apk add --no-cache mysql-client  #不使用本地镜像源缓存,相当于先执行update,再执行add
apk add -u #升级指定软件包

2.1.4- apk info

apk info #列出所有已安装的软件包
apk info -a zlib #显示完整的软件包信息
apk info -r zlib #列出所有包的依赖
apk info -s zlib #显示软件包大小
apk info -d zlib #显示软件包的描述
apk info --who-owns /sbin/lbu #显示指定文件属于的包
apk info -L zlib #列出软件包的内容
apk info -e zlib #检测软件包的安装
apk info -R zlib #列出指定包的依赖

2.1.5- apk upgrade

apk upgrade #升级所有软件
apk upgrade openssh #升级指定软件
apk upgrade openssh openntp vim   #升级多个软件
apk add --upgrade busybox #指定升级部分软件包

2.1.6- apk del

apk del openssh  #删除一个软件

3- Alpine服务管理

_ _ _ 使用的是RC系列命令进行服务管理.

3.1- rc-update

用于不同运行级增加或者删除服务:

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.2- rc-status

用于运行级的状态管理。

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)

3.3- rc-service

用于管理服务的状态

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)

3.4- openrc

管理不同的运行级。

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)

3.5- 案例

rc-update add docker boot #增加docker服务到系统启动时运行
rc-service networking restart #重启网络服务
rc-status -a #列出所有服务

4- 实用命令

apk add iproute2  #查看网络连接的协议端口的命令ss,可以替代netstat命令
#  ss -ta   ##查看建立的TCP连接

apk add drill   #替代dig和nslookup DNS查询命令
#  drill blog.csdn.net @8.8.8.8  ##查询域名的信息
#  drill -x 114.114.114.114 @10.61.191.221 ##根据IP地址,反向查找域名

apk add openssh-server  #开启SSH服务
/etc/init.d/sshd restart
rc-update add sshd

5- 详细介绍wiki

http://wiki.alpinelinux.org
posted @ 2020-02-29 20:07  lemanlai  阅读(1827)  评论(0编辑  收藏  举报