目录
一、理论
1.Alpine Linux
二、实验
1.Alpine Linux安装
三、问题
1.Alpine Linux 缺少VIM命令
2.Alpine Linux SSH连接不上
3.Alpine Linux IP配置
四、总结
一、理论
1.Alpine Linux
(1)概念
Alpine 操作系统是一个面向安全的轻型 Linux 发行版。它不同于通常 Linux 发行版,Alpine 采用了 musl libc 和 busybox 以减小系统的体积和运行时资源消耗,但功能上比 busybox 又完善的多,因此得到开源社区越来越多的青睐。在保持瘦身的同时,Alpine 还提供了自己的包管理工具 apk,可以通过 https://pkgs.alpinelinux.org/packages 网站上查询包信息,也可以直接通过 apk 命令直接查询和安装各种软件。
Alpine 由非商业组织维护的,支持广泛场景的 Linux发行版,它特别为资深/重度Linux用户而优化,关注安全,性能和资源效能。Alpine 镜像可以适用于更多常用场景,并且是一个优秀的可以适用于生产的基础系统/环境。
(2)下载
进入Alpine官网,下载Alpine Linux的ISO镜像,Alpine Linux提供了专门的虚拟机版本。
(3)比较
下面是系统安装完成后,并手动使用自带软件管理器,安装vim软件后的体积对比图。
(4)安装方法
安装方法参考官方的文档: Install Alpine on VMware Workstation - Alpine Linux
(5)Alpine Linux源管理
国内源简介: - 清华大学:https://mirror.tuna.tsinghua.edu.cn/alpine/
- 阿里云:https://mirrors.aliyun.com/alpine/
- 中科大:http://mirrors.ustc.edu.cn/alpine/
- 网易:http://mirrors.163.com/
复制代码
配置:
中科大的帮助http://mirrors.ustc.edu.cn/help/alpine.html 一般情况下,将 /etc/apk/repositories 文件中 Alpine 默认的源地址 http://dl-cdn.alpinelinux.org/ 替换为 http://mirrors.ustc.edu.cn/ 即可。 - sudo vim /etc/apk/repositories
复制代码
(6) 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 #删除一个软件
复制代码
(7) Alpine Linux服务管理 - 1.简介
- alpine没有使用fedora的systemctl来进行服务管理,使用的是RC系列命令
- 未安装openrc时需执行以下命令
- sudo apk add --no-cache openrc
- 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
- 服务开机自启
- Alpine Linux 的 开机自启目录在/etc/local.d下,这个目录用于放置我们需要在本地服务启动或停止后执行的脚本。
复制代码
二、实验
1.Alpine Linux安装
(1)新建虚拟机
新建一台虚拟机,类型选Linux,
版本选Linux 3.x / 4.x (64-bit),
虚拟机名称
虚拟磁盘8G
自定义硬件, 内存一般1G
完成
引导
首次启动时使用root这个用户名登录,不需要密码
登录成功后,执行setup-alpine进入安装向导,向导会询问你一系列的问题,然后等待你的输入。
备注:如果途中操作有失误,可以按Ctrl + c 退出向导,再重新开始向导。
下面是每个问题的具体含义及操作步骤。 - Select keyboard layout [none]:
- 选择键盘布局,系统默认给你选了none,直接回车
- Enter system hostname (short form, e.g. 'foo') [localhost]
- 选择虚拟机host名称,系统给你选了localhost,没有特殊需要的话直接回车
- Which one do you want to initialize? (or '?' or 'done') [eth0]
- 选择要不要设置网卡,系统给你选了需要初始化eth0那张网卡,直接回车
- Ip address for eth0? (or 'dhcp', 'none', '?') [dhcp]
- 输入eth0网卡的IP地址,或者直接通过dhcp协议自动获取IP,系统给你选了dhcp,直接回车
- Do you want to do any manual network configuration? [no]
- 还需要手工修改网卡的其他配置吗?系统给你选了no,直接回车
- Changeing password for root
- New password:
- 安装完成后,就不能像现在这样不用密码就登录了,系统提示你输入root帐号的密码。
- Retype Password:
- 确认一遍密码
- Which timezone are you in? ('?' for list) [UTC]
- 输入时区,国内可以输入"Asia/Shanghai"
- HTTP/FTP pxory URL?
- 需要使用HTTP代理连接网络吗?一般不需要,可以直接回车
- Enter mirror number (1-21) or URL to add (or r/f/e/done) [f]
- Alpine Linux自带的包管理器需要联网下载软件包
复制代码
每个步骤直接按回车默认选择
此时屏幕上会打出多个镜像站的URL,但都是国外的
这里推荐使用国内镜像:这时候按下e,编辑镜像配置文件,把国内的镜像地址填进去:
- https://mirrors.ustc.edu.cn/alpine/latest-stable/community/
- https://mirrors.ustc.edu.cn/alpine/latest-stable/main/
- https://mirrors.aliyun.com/alpine/latest-stable/community/
- https://mirrors.aliyun.com/alpine/latest-stable/main/
复制代码
退出编辑后向导会检查地址是否可用,没问题的话会继续下面的步骤。 - Which SSH server? ('openssh', 'dropbear' or 'none') [openssh]
- SSH服务器(用于登录Linux)有两种可供选择,默认选择openssh,回车
- Which NTP client to run? ('busybox', 'openntpd', 'chorony' or 'none') [chrony]
- 选择NTP客户端(用来调整系统时钟)的类型,保持默认的chrony即可,回车
- Available disks are:
- sda (8.6 GB ATA VBOX HARDDISK )
- Which disk(s) would you like to use? (or '?' for help or 'none') [none]
- 这一步比较关键,系统发现了有块8.6GB大小,名称叫sda的硬盘
- 问你需不需要使用硬盘,因为Alpine Linux可以运行在内存里,这里的默认选项是不使用硬盘
- 所以要手动键入sda,后面的步骤才会将系统安装在硬盘上
- The following disk is selected:
- sda (8.6 GB ATA VBOX HARDDISK )
- How would you like to use it? ('sys', 'data', 'lvm' or '?' for help) [?]
- 以何种方式安装系统,这里需要键入"sys",表示把整个系统安装在硬盘上。
- 其他选项并不适用于虚拟机
- WARNING: The following disk(s) will be erased:
- sda (8.6 GB ATA VBOX HARDDISK )
- WARNING: Erase the above disk(s) and continue? [y/N]
- 向导让你确认选择的sda磁盘上的数据会全部丢失
- 虚拟机磁盘,初始肯定是没数据的,键入"y"确认
复制代码
随着屏幕滚动,系统会安装一阵子,等出现这行字时,就算安装完成了。 - Instalation is complete. Please reboot
- 安装完成,请重启(先别着急)
复制代码
看一下安装完成后系统空间的使用情况。
重启后登录
三、问题
1.Alpine Linux 缺少VIM命令
(1)报错
(2)原因分析
在Alpine Linux上安装Vim有3种方法:
①APK是Alpine Linux的包管理器,可以使用它来安装Vim。要安装Vim,请打开终端,然后键入以下命令:
安装完成后,您可以使用以下命令检查Vim的版本:
②使用源代码安装Vim
如果想要安装最新版本的Vim,则可以使用源代码安装。要安装Vim,请打开终端,然后键入以下命令: - wget https://github.com/vim/vim/archive/master.zip
- unzip master.zip
- cd vim-master
- ./configure
- make
- make install
复制代码
安装完成后,您可以使用以下命令检查Vim的版本:
③ 使用Vim容器安装Vim
如果您想要安装Vim,但又不想安装太多依赖包,则可以使用Vim容器。要安装Vim容器,请打开终端,然后键入以下命令:
安装完成后,您可以使用以下命令检查Vim的版本: - docker run --rm -it vim --version
复制代码
(3)解决方法
安装
查看版本
2.Alpine Linux SSH连接不上
(1)原因分析
未修改配置文件
(2)解决方法
(3)增加 - PermitRootLogin yes
- GatewayPorts yes
- AllowTcpForwarding yes
- PermitEmptyPasswords yes
复制代码
service sshd restart 映射虚拟机22端口
SSH 连接成功
3.Alpine Linux IP配置
(1)解决方法
添加网卡
- #编辑interfaces
- vim /etc/network/interfaces
- #配置
- auto lo
- iface lo inet loopback
-
- auto eth0
- iface eth0 inet dhcp
- auto eth1
- iface eth1 inet dhcp
- hostname localhost
复制代码
重启网络服务 - service networking restart
复制代码
四、总结
Alpine Linux安装非常简单,快速。虽然是命令行安装,比CentOS的安装都容易。
系统安装完后,体积上面有着非常明显的优势。
|