0%

WSL

Windows Subsystem for Linux(简称WSL)是一个在Windows 10\11上能够运行原生Linux二进制可执行文件(ELF格式)的兼容层。它是由微软与Canonical公司合作开发,开发人员可以在 Windows计算机上同时访问 Windows和Linux的强大功能。通过适用于Linux的Windows子系统(WSL),开发人员可以安装Linux发行版(例如 Ubuntu、OpenSUSE、Kali、Debian、Arch Linux等),并直接在Windows上使用Linux应用程序、实用程序和Bash命令行工具,不用进行任何修改,也无需承担传统虚拟机或双启动设置的费用。

WSL安装使用

一、安装

  1. 安装Terminal(非必须)
  2. 安装WSL(win10自带)
  3. 安装虚拟平台(启用WSL功能):wsl --install

二、使用

wsl –hep

  1. 查看列表:wsl -l -v
  2. 安装系统
  1. 进入系统:wsl -d Debian
  2. 关闭系统:wsl –shutdown
    • wsl -d Ubuntu-22.04 –shutdown
  3. 设置默认:wsl -s Debian
  4. 设置代理
  1. 取消代理
  • unset http_proxy
  • unset https_proxy
  1. 卸载系统:wsl –unregister Ubuntu-24.04

三、问题

  1. 安装多个相同版本的Linux
  2. 安装多个Linux发行版,ip地址一样

四、参考

  1. issues

以Ubuntu-24.04为例

  1. wsl –install Ubuntu-24.04

  2. wsl,进入系统

  • wsl –user root,以root用户进入系统
  1. 设置用户名和密码:liusir/123456

  2. sudo su -

  • 123456
  1. passwd root
  • 123456
  1. ifconfig
  • Command ‘ifconfig’ not found, but can be installed with:
    • apt install net-tools
  1. apt update

  2. apt upgrade

  3. systemctl start sshd

  • Failed to start sshd.service: Unit sshd.service not found.
    • apt install openssh-server
    • systemctl enable ssh.service
    • systemctl list-units –type=service | grep ssh,查看已安装的服务
    • vim /etc/ssh/sshd_config
      • PermitRootLogin yes
    • service sshd restart
    • 卸载服务
      • apt remove openssh-server
      • apt autoremove
  1. usermod -l liuyulong liusir,修改用户名

  2. userdel liuyulong

  3. groupdel liusir

  4. cd /home && rm -rf liusir

  5. useradd liusir

  6. passwd liusir

  7. useradd liuyulong

  • ssh登录报错
    • /home/liusir/.hushlogin file.
    • touch: cannot touch ‘/home/liusir/.motd_shown’: No such file or directory
    • cd /home
    • mkhomedir_helper liusir
    • mkhomedir_helper liuyulong
      • useradd liusir -m
      • useradd liuyulong -m
      • usermod -s /bin/bash liusir
      • usermod -s /bin/bash liuyulong
  • 再次登录,报错:/usr/bin/xauth: file /home/liusir/.Xauthority does not exist
    • 在对应主目录下创建:touch .Xauthority
  1. 卸载Ubuntu-24.04: wsl –unregister Ubuntu-24.04

安装多个相同发行版本的Linux

一、操作

  1. 下载:https://github.com/DDoSolitary/LxRunOffline/releases/download/v3.5.0/LxRunOffline-v3.5.0-msvc.zip

  2. 解压

  3. 执行:LxRunOffline.exe d -n Ubuntu-24.04 -d C:\WSL\Ubuntu-24.04-02 -N Ubuntu-24.04-02

  • 报错:[ERROR] The distro "Ubuntu-24.04-02" already exists.
  • 解决:wsl –unregister Ubuntu-24.04-02,卸载后重新复制
  1. 修改hostname:/etc/hostname
  • sudo hostnamectl set-hostname ubuntu-01
  • sudo hostnamectl set-hostname ubuntu-02
  1. 修改hosts:/etc/hosts
  • 127.0.1.1 ubuntu-01
  • 127.0.1.1 ubuntu-02
  1. 退出重进

二、问题

  1. 复制报错,多半为参数问题

  2. 复制后ip/mac什么的都一样

  • 修改IP地址和MAC地址

    • sudo ifconfig eth0 192.168.1.2 netmask 255.255.255.0

    • sudo route add default gw 192.168.1.1 dev eth0

    • sudo ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE

      • 报错:SIOCSIFHWADDR: Device or resource busy - you may need to down the interface
      • 处理
        • sudo ifconfig eth0 down
        • sudo ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE
        • sudo ifconfig eth0 up
    • sudo ifconfig eth0 192.168.1.3 netmask 255.255.255.0

    • sudo route add default gw 192.168.1.1 dev eth0

    • sudo ifconfig eth0 hw ether 00:A1:B1:C1:D1:E1

      • sudo ifconfig eth0 down
      • sudo ifconfig eth0 hw ether 00:A1:B1:C1:D1:E1
      • sudo ifconfig eth0 up

三、参考

  1. https://github.com/DDoSolitary/LxRunOffline

Ubuntu-安装MySQL

  1. 目录规划

    • 安装目录:/usr/local/mysql
    • 数据目录:/mysql/data
    • 错误日志:/tmp/mysql/
    • 慢查询日志:/tmp/mysql/
    • socks目录:/var/run/mysqld/
  2. 用户设置和目录设置

    • groupadd mysql
    • useradd -r -g mysql mysql
    • 准备数据目录 mkdir -p /data/mysql
    • 赋予权限 chown mysql.mysql /data/mysql
  3. 安装

    • apt-get update
    • apt-get install cmake openssl libssl-dev libncurses5-dev libncursesw5-dev build-essential pkg-config git net-tools -f build-essential libncurses5-dev libncurses5
    • wget https://downloads.mysql.com/archives/get/p/23/file/mysql-boost-5.7.44.tar.gz
    • 解压源码至/usr/local/mysql-5.7.44
    • cmake . -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/mysql-5.7.44/boost/boost_1_59_0
    • make && make install
      • 有时候安装失败或想更换安装选项,重新设置后make clean
    • 切换到安装目录 cd /usr/local/mysql
    • sudo cp support-files/mysql.server /etc/init.d/mysqld
    • sudo chmod 700 /etc/init.d/mysqld
    • sudo chown -R mysql:mysql /usr/local/mysql
    • 修改配置文件,默认/etc/mysql/conf.d/mysql.cnf
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    [client]
    port=3306

    [mysql]
    default-character-set=utf8mb4

    [mysqld]
    port = 3306
    socket = /var/run/mysqld/mysql.sock #有坑
    pid-file = /tmp/mysql/mysql.pid
    basedir = /usr/local/mysql
    datadir = /data/mysql
    tmpdir = /tmp/mysql
    character_set_server = utf8mb4
    collation_server = utf8mb4_bin
    log-error=/tmp/mysql/error.log
    secure-file-priv = /tmp/mysql/
    # bind-address=localhost # MySQL绑定IP
    wait_timeout = 86400
    binlog_cache_size = 16M
    slow_query_log = true
    slow_query_log_file = /tmp/mysql/slow_query_log.log
    long_query_time = 1
    • sudo mysqld –defaults-file=/etc/mysql/my.cnf –user=root –initialize,初始化数据库并得到初始密码:gae>=TdlA3Ff
    • 启动MySQL:sudo service mysqld start/sudo systemctl start mysql.service
    • 关闭MySQL:sudo service mysqld stop/sudo systemctl stop mysql.service
    • 登录客户端:mysql -h 127.0.0.1 -uroot -p
    • 修改root密码:alter user ‘root’@’localhost’ identified by ‘root’;

搭建MySQL主从

一、主库

二、从库


Ubuntu-搭建GitLab

一、操作

  1. sudo apt-get update

  2. sudo apt-get install -y curl openssh-server ca-certificates tzdata perl

  3. curl -L get.gitlab.cn | bash

  4. sudo EXTERNAL_URL=”https://gitlab.liusir.me" apt-get install -y gitlab-jh

  5. 修改hosts:172.19.158.177 gitlab.liusir.me

    • 172.19.158.177是安装的Linux地址
  6. 安装成功,访问:https://gitlab.liusir.me

    • 默认用户:root
    • 默认密码:/etc/gitlab/initial_root_password
  7. 卸载:sudo gitlab-ctl stop && sudo gitlab-ctl remove-accounts

  8. 登录gitlab后台

  9. 修改密码

  10. 新建群组

  11. 新建项目

二、问题

  1. gitlab-ctl reconfigure

  2. SSL certificate problem: self-signed certificate

    • export GIT_SSL_NO_VERIFY=true
      • Windows: set GIT_SSL_NO_VERIFY=true git clone
      • Linux:env GIT_SSL_NO_VERIFY=true git push
    • git config –global http.sslVerify “false”

三、参考

  1. 参考一