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一样的OpenRCinit系统.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

Alpine Linux配置使用技巧【一个只有5M的操作系统(转)】的更多相关文章

  1. Alpine Linux:如何配置GUI的图形桌面环境:x Desktop Environment

    alpine linux 真是不错.小巧.迅捷! 官方的各个版本的alpine镜像内没有带图形环境的.那我们如何构建自己的桌面图形环境呢? 其实:这个问题,在起官网的wiki内有指南,我们根据那些相关 ...

  2. 把玩Alpine linux(二):APK包管理器

    导读 Alpine Linux非常精简,开机内存占用也在二三十兆大,没有拆箱即用,就需要我们自己去做一些了解和配置 Alpine Linux的优劣 优势 Alpine Linux的Docker镜像特点 ...

  3. Docker系列之(三):Docker微容器Alpine Linux

    1. 前言 使用Docker创建容器时,基础镜像通常选择Ubuntu或Centos,不管哪个镜像的大小都在100MB以上. Alpine Linux是一个面向安全的轻型的Linux发行版. Alpin ...

  4. 转载Alpine Linux常用命令

    Alpine Linux常用命令 目录 一:Alpine Linux开启SSH远程登陆 1.简介: 2.配置 3.配置命令 4.重启服务 二:Alpine Linux源管理 1.简介 2.国内源简介: ...

  5. 把玩Alpine linux(一):安装

    导读 Alpine Linux是一个面向安全应用的轻量级Linux发行版.它采用了musl libc和busybox以减小系统的体积和运行时资源消耗,同时还提供了自己的包管理工具apk.Alpine ...

  6. Alpine Linux常用命令

    一:Alpine Linux开启SSH远程登陆 1.简介: 最重要的一个服务了,远程登陆需要用它,文件传输需要用它,必备功能.不管你是在实体机上跑,虚拟机上跑,docker里面跑,这个都是必须的. 2 ...

  7. Linux配置Nginx+Tomcat负载均衡

    cd /usr/local/tomcat1/webapps/ROOT/ tar -zxvf nginx-1.14.2.tar.gz -C /usr/local 一.Linux配置Nginx 一.下载N ...

  8. 系统管理员需知:25个Linux服务器安全技巧(转)

    来源:51CTO 作者:51CTO       大家都认为 Linux 默认是安全的,我大体是认可的 (这是个有争议的话题).Linux默认确实有内置的安全模型.你需要打开它并且对其进行定制,这样才能 ...

  9. 最全Linux应急响应技巧 【转】

    概述 Linux环境下处理应急响应事件往往会更加的棘手,因为相比于Windows,Linux没有像Autorun.procexp这样的应急响应利器,也没有统一的应急响应处理流程.所以,这篇文章将会对L ...

随机推荐

  1. swift--触摸(UITouch)事件(点击,移动,抬起)

    触摸事件: UITouch:一个手机第一次点击屏幕,会形成一个UITouch对象,知道离开销毁.表示触碰.UITouch对象能表明当前手指触碰的屏幕位置.状态,状态分为开始触碰.移动.离开. 具体方法 ...

  2. 动易CMS漏洞收集

    动易SiteWeaver6.8短消息0day跨站漏洞 user用户登陆,默认账号密码 admin/admin888 短消息代码模式下编辑,预览 <img src="../Skin/bl ...

  3. HTTP 代理

    HTTP 代理: (1) 如果我们一直用同一个IP去爬取同一个网站上的网页,久了之后可能会被该网站服务器屏蔽,因此我们可以使用代理IP来爬取,代理实际上指的就是代理服务器(2) 当我们使用代理IP爬取 ...

  4. 解决Xcode "The selected destination does not support the architecture " 错误错误

    XCODE编译运行项目后,发现工程编译后无法运行,出现:"The selected destination does not support the architecture for whi ...

  5. 罗云彬win32汇编教程笔记 子函数的声明, 定义与调用

    在主程序中用call指令来调用子程序. Win32汇编中的子程序也采用堆栈来传递参数,这样就可以用invoke伪指令来进行调用和语法检查工作. 一. 子程序的定义 子程序的定义方式如下所示. 子程序名 ...

  6. java基础---->多线程之wait和notify(八)

    这里学习一下java多线程中的关于wait方法和notify方法的用法.命运不是风,来回吹,命运是大地,走到哪你都在命运中. wait和notify方法的使用 一.wait与notify的简单实例 i ...

  7. Go基础---->go的基础学习(四)

    这里简单的介绍一下go中的关于多线程的知识. Go中的多线程 一.go中简单的并发例子 package main import ( "fmt" "time" ) ...

  8. LeetCode——Pascal's Triangle II

    Description: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3 ...

  9. 从TCP三次握手说起–浅析TCP协议中的疑难杂症(2)

    版权声明:本文由黄日成原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/108 来源:腾云阁 https://www.qclo ...

  10. 11.事件驱动events

    事件驱动events ==> events.EventEmitter, EventEmitter 的核心就是事件发射与事件监听器功能的封装更详细的 API 文档参见 http://nodejs. ...