Alpine Linux 常用命令

2023-12-05 20:30
文章标签 linux 常用命令 alpine

本文主要是介绍Alpine Linux 常用命令,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Alpine Linux源管理

1.国内源简介:
这几个都有alpine的源
清华大学:https://mirror.tuna.tsinghua.edu.cn/alpine/
阿里云:https://mirrors.aliyun.com/alpine/
中科大:http://mirrors.ustc.edu.cn/alpine/
网易:http://mirrors.163.com/

2.配置:
直接抄中科大的帮助http://mirrors.ustc.edu.cn/help/alpine.html
一般情况下,将 /etc/apk/repositories 文件中 Alpine 默认的源地址 http://dl-cdn.alpinelinux.org/ 替换为 http://mirrors.ustc.edu.cn/ 即可。

sudo vi /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 #删除一个软件

安装python

sudo apk add --no-cache python3 python3-dev
其中已自带pip
在这里插入图片描述
python其他依赖

sudo pip3 install Flask -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
sudo pip install paho-mqtt -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
sudo pip install redis -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
sudo pip install requests -i http://pypi.douban.com/simple --trusted-host pypi.douban.com

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] -lor: 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 intowhen leaving single user or boot runlevels-s, --service <arg>               runs the service specified with the restof 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下,这个目录用于放置我们需要在本地服务启动或停止后执行的脚本

先上目录下的说明文档:

This directory should contain programs or scripts which are to be run
when the local service is started or stopped.If a file in this directory is executable and it has a .start extension,
it will be run when the local service is started. If a file is
executable and it has a .stop extension, it will be run when the local
service is stopped.All files are processed in lexical order.Keep in mind that files in this directory are processed sequentially,
and the local service is not considered started or stopped until
everything is processed, so if you have a process which takes a long
time to run, it can delay your boot or shutdown processing.

简单翻译了下:

此目录应包含在启动或停止本地服务时要运行的程序或脚本。
如果此目录中的文件是可执行文件且扩展名为.start,
则在启动本地服务时将运行该文件。
如果文件是可执行的并且具有.stop扩展名,
则在本地服务停止时将运行该文件。所有文件都按词汇顺序处理。
请记住,此目录中的文件是按顺序处理的,并且在处理完所有内容之前不会将本地服务视为已启动或停止,
因此如果您的进程需要很长时间才能运行,则可能会延迟启动或关闭处理。

自定义开机自启服务,由于Alpine Linux自带了nohup后台守护,我们就直接使用nohup设置开机自启。

先编辑下startup.start文件,注意,.start后缀需要固定,前面名称随意
vi startup.start
我的内容如下

#!/bin/bash
sudo nohup python3 /home/plugin/main.py & >> /home/plugin/plugin.log

然后保存退出。

赋予脚本可执行权限:

chmod +x startup.start

设置 local 服务开机启动:

rc-update add local
sudo service local start

如执行rc-update add local失败,可能需执行sudo touch /run/openrc/softlevel之后在执行rc-update add local
这样当系统开机时就能执行startup.start开达到开机自动的目的。
在这里插入图片描述
bashps -a 查看启动的进程
在这里插入图片描述
总结:以上内容也适用于在docker 中基于Alpine 镜像的业务扩展。

这篇关于Alpine Linux 常用命令的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/459021

相关文章

Linux lvm实例之如何创建一个专用于MySQL数据存储的LVM卷组

《Linuxlvm实例之如何创建一个专用于MySQL数据存储的LVM卷组》:本文主要介绍使用Linux创建一个专用于MySQL数据存储的LVM卷组的实例,具有很好的参考价值,希望对大家有所帮助,... 目录在Centos 7上创建卷China编程组并配置mysql数据目录1. 检查现有磁盘2. 创建物理卷3. 创

Linux查看系统盘和SSD盘的容量、型号及挂载信息的方法

《Linux查看系统盘和SSD盘的容量、型号及挂载信息的方法》在Linux系统中,管理磁盘设备和分区是日常运维工作的重要部分,而lsblk命令是一个强大的工具,它用于列出系统中的块设备(blockde... 目录1. 查看所有磁盘的物理信息方法 1:使用 lsblk(推荐)方法 2:使用 fdisk -l(

Linux中的more 和 less区别对比分析

《Linux中的more和less区别对比分析》在Linux/Unix系统中,more和less都是用于分页查看文本文件的命令,但less是more的增强版,功能更强大,:本文主要介绍Linu... 目录1. 基础功能对比2. 常用操作对比less 的操作3. 实际使用示例4. 为什么推荐 less?5.

linux lvm快照的正确mount挂载实现方式

《linuxlvm快照的正确mount挂载实现方式》:本文主要介绍linuxlvm快照的正确mount挂载实现方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录linux lvm快照的正确mount挂载1. 检查快照是否正确创建www.chinasem.cn2.

Linux给磁盘扩容(LVM方式)的方法实现

《Linux给磁盘扩容(LVM方式)的方法实现》本文主要介绍了Linux给磁盘扩容(LVM方式)的方法实现,涵盖PV/VG/LV概念及操作步骤,具有一定的参考价值,感兴趣的可以了解一下... 目录1 概念2 实战2.1 相关基础命令2.2 开始给LVM扩容2.3 总结最近测试性能,在本地打数据时,发现磁盘空

Linux网络配置之网桥和虚拟网络的配置指南

《Linux网络配置之网桥和虚拟网络的配置指南》这篇文章主要为大家详细介绍了Linux中配置网桥和虚拟网络的相关方法,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 一、网桥的配置在linux系统中配置一个新的网桥主要涉及以下几个步骤:1.为yum仓库做准备,安装组件epel-re

windows和Linux安装Jmeter与简单使用方式

《windows和Linux安装Jmeter与简单使用方式》:本文主要介绍windows和Linux安装Jmeter与简单使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地... 目录Windows和linux安装Jmeter与简单使用一、下载安装包二、JDK安装1.windows设

Kali Linux安装实现教程(亲测有效)

《KaliLinux安装实现教程(亲测有效)》:本文主要介绍KaliLinux安装实现教程(亲测有效),具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、下载二、安装总结一、下载1、点http://www.chinasem.cn击链接 Get Kali | Kal

linux服务之NIS账户管理服务方式

《linux服务之NIS账户管理服务方式》:本文主要介绍linux服务之NIS账户管理服务方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、所需要的软件二、服务器配置1、安装 NIS 服务2、设定 NIS 的域名 (NIS domain name)3、修改主

Linux实现简易版Shell的代码详解

《Linux实现简易版Shell的代码详解》本篇文章,我们将一起踏上一段有趣的旅程,仿照CentOS–Bash的工作流程,实现一个功能虽然简单,但足以让你深刻理解Shell工作原理的迷你Sh... 目录一、程序流程分析二、代码实现1. 打印命令行提示符2. 获取用户输入的命令行3. 命令行解析4. 执行命令