Avatar

Organizations

6 results for Alpine Linux
  • VsCode Remote SSH 默认是不支持 Alpine Linux 的,不过,对 Alpine Linux 进行一些改动,就可以实现,比较方便。

    步骤如下:

    安装

    1. 安装 Bash
    2. 安装需要的包
    $ apk del dropbear
    $ apk add gcompat libstdc++6 openssh wget git
    

    Alpine 配置

    $ nano /etc/ssh/sshd-config
    
    AllowTcpForwarding yes
    PermitTunnel       yes
    

    git 配置

    1. VsCode 连接 Alpine Linux
    2. F1 > “Preferences: Open Remote Settings (JSON) (SSH: )”
    3. 添加下面的内容:
    {
    	"git.path": "/usr/bin/git",
    }
    

    参考文档:

    alpine linux remote ssh vscode Created Tue, 03 Jan 2023 20:42:02 +0800
  • Alpine Linux 原始安装的是 busybox,小巧精干,但毕竟与主流的 Bash 还是有区别,特别是与其它系统联动时会比较麻烦,所以还是安装 Bash,统一 Shell 环境,方便日后使用。

    而且基本网上的安装教程都有问题,所以这里给出正确的安装步骤。

    安装

    $ apk add bash libuser
    

    配置

    $ touch /etc/login.defs
    $ mkdir /etc/default
    $ touch /etc/default/useradd
    $ lchsh <root>
    Changing shell for root.
    Password: <root password>
    New Shell [/bin/ash]: /bin/bash
    Shell changed.
    

    参考文档:

    linux bash alpine linux Created Tue, 03 Jan 2023 20:08:42 +0800
  • WindTerm 无法认证

    WindTerm客户端,取消 “会话设置 -> SSH -> 验证 -> 尝试键盘交互认证” 可已正常连接。

    安装 OpenSSH Server

    $ apk update
    $ apk add openssh-server openssh
    
    ; /etc/ssh/sshd_config
    
    # 开放Root登录
    - #PermitRootLogin prohibit-password
    + PermitRootLogin yes
    
    # 允许其它用户登录
    - #PasswordAuthentication yes
    + PasswordAuthentication yes
    
    # 解决ssh自动断开
    - #ClientAliveInterval 0
    - #ClientAliveCountMax 3
    + ClientAliveInterval 60
    + ClientAliveCountMax 3
    
    $ rc-service sshd start
    
    $ rc-service sshd restart
    # 设置开机启动
    $ rc-update add sshd
    # 删除开机启动服务
    $ rc-update del sshd
    # 显示所有服务
    # rc-status -a
    

    终端配置

    在 /etc/profile.d 文件夹下,创建sh文件来实现。

    linux cli alpine linux Created Wed, 28 Dec 2022 16:27:00 +0800
  • 在 Alpine 上安装 Docker 真是一件让人感觉非常愉快的事情,因为过程非常简单。

    修改 apk 源

    $ nano /etc/apk/repositories
    

    因为 docker 在社区的库里,所以要打开 community 的源。

    #/media/cdrom/apks
    http://mirrors.tuna.tsinghua.edu.cn/alpine/v3.16/main
    http://mirrors.tuna.tsinghua.edu.cn/alpine/v3.16/community
    #http://mirrors.tuna.tsinghua.edu.cn/alpine/edge/main
    #http://mirrors.tuna.tsinghua.edu.cn/alpine/edge/community
    #http://mirrors.tuna.tsinghua.edu.cn/alpine/edge/testing
    

    安装 Docker

    $ apk update
    $ apk add docker docker-cli-compose
    # 这里要特别注意,docker compose 的包名在 Alpine 里是 docker-cli-compose,不是 docker-compose-plugin。
    # docker-compose 包是 compose 的独立安装包,官方已经不再支持这种安装方式。
    ...
    $ docker -v
    Docker version 20.10.16, build aa7e414fdcb23a66e8fabbef0a560ef1769eace5
    $ docker compose version
    Docker Compose version v2.12.2
    

    配置 Docker

    (CentOS 7 | Rocky 9) 安装 Docker

    linux Alpine linux Docker Created Sun, 19 Jun 2022 16:08:06 +0800
  • 网卡静态地址

    ~# nano /etc/network/interfaces
    
    auto lo
    iface lo inet loopback
    
    auto eth0
    iface eth0 inet static
        address 192.168.10.16/24
        gateway 192.168.10.10
        hostname alpine
    

    配置 DNS

    # nano /etc/resolv.conf
    nameserver 114.114.114.114
    

    重启网络

    ~# service networking restart
    
    linux network Alpine linux Created Sun, 19 Jun 2022 15:25:18 +0800
  • 特点:

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

    不同版本:

    • STANDARD:最小的可启动镜像,需要网络才能安装。带有Intel, AMD等CPU的微代码。
    • VIRTUAL:与STANDARD类似,但更小,更适合虚拟系统使用。
    • EXTENDED:包括最常用的软件包。适用于路由器和服务器。从RAM运行。扩展版本,带有更多软件包。
    • XEN:内置XEN Hypervisor支持。
    • NETBOOT:netboot的内核、initramfs和modloop。
    • RASPBERRY PI:带有树莓派内核的版本。
    • GENERIC ARM:带有ARM内核,带有uboot加载器。
    • MINI ROOT FILESYSTEM:最小系统版本,仅包含内核,只用于构建Docker镜像。

    1. 准备系统

    Alpine 有许多版本,其中 VIRTUAL 是专门针对虚拟环境优化过的,所以主要使用这个版本来安装。

    https://www.alpinelinux.org/downloads/

    2. 登录

    ...
    # 使用启动盘启动后,直接使用 root 登录系统
    localhost login: root
    

    3. 安装

    ...
    localhost:~# setup-alpine
    
    # 选择键盘布局
    # 这里两个都选 cn 或都不选
    ...
    Select keyboard layout: [none] cn
    ...
    Select variant (or 'abort'): cn
    
    # 设置主机名
    ...
    Enter system hostname (fully qualified form, e.g. 'foo.example.org') [localhost] home
    
    # 设置网络
    ...
    Which one do you want to initialize? (or '?' or 'done') [eth0] eth0
    
    Ip address for eth0? (or 'dhcp', 'none', '?') [dhcp] dhcp
    Do you want to do any manual network configuration? (y/n) [n] n
    # or 手动输入IP地址
    Ip address for eth0? (or 'dhcp', 'none', '?') [dhcp] 192.168.10.16/24
    Gateway? (or 'none') [none] 192.168.10.10
    Do you want to do any manual network configuration? (y/n) [n] n
    DNS domain name? (e.g 'bar.com') 
    DNS nameserver(s)? 114.114.114.114
    
    # 设置密码
    ...
    New password: 
    ...
    Retype password:
    
    # 设置时区
    # PRC 代理中国,也可以输入 Asia/,再输入 Shanghai
    ...
    Which timezone are you in? ('?' for list) [UTC] PRC
    
    # 设备代理
    ...
    HTTP/FTP proxy URL? (e.g. 'http://proxy:8080', or 'none') [none] none
    
    # 设置更新源
    # f 是自动测试并选择最快的源,建议使用
    ...
    Enter mirror number (1-74) or URL to add (or r/f/e/done) [1] f
    
    # 
    Setup a user? (enter a lower-case loginname, or 'no') [no] no
    
    # 设置ssh服务
    Which ssh server? ('openssh', 'dropbear', or 'none') [openssh] openssh
    # 这里一定要输入 yes 
    # 许多教程都说 Alpine 默认没有远程登录,都上手动修改,其实是可以在安装时就设备好的
    Allow root ssh login? ('?' for help) [prohibit-password] yes
    Enter ssh key or URL for root (or 'none') [none] none
    
    # 设置磁盘
    ...
    Which disk(s) would you like to use? (or '?' for help or 'none') [none] sda
    ...
    How would you like to use it? ('sys', 'data', 'crypt', 'lvm' or '?' for help) [?] sys
    ...
    WARNING: Erase the aboue disk(s) and continue? (y/n) [n] y
    ...
    Installation is complete. Please reboot.
    # 到这里安装全部完成
    

    3.1. 自动安装

    # 准备应答文件
    

    4. 命令重启电脑

    home:~# reboot
    

    5. 关闭防火墙

    home:~# rc-service iptables stop
    home:~# rc-update del iptables
    
    vm qmue\kvm linux proxmoxve Alpine linux Created Sun, 19 Jun 2022 11:46:55 +0800