debian dockerfile 更新国内源

1
2
3
4

RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
RUN sed -i 's/security.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list

Debian 12 (bookworm) 安装方法及其国内软件源

参考网站

1
2
3
4
5

sudo apt-get update
sudo apt-get upgrade
# 把 /etc/apt/sources.list 里面的内容全部注释掉,增加以下 Debian 12 的软件源:

国内常见镜像站点

Debian全球镜像站列表:Debian全球镜像站

下面列出国内常用的镜像站点及 /etc/apt/sources.list 中的具体对应内容:

阿里云镜像站

1
2
3
4
5
6
7
8
deb https://mirrors.aliyun.com/debian/ bookworm main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian/ bookworm main non-free non-free-firmware contrib
deb https://mirrors.aliyun.com/debian-security/ bookworm-security main
deb-src https://mirrors.aliyun.com/debian-security/ bookworm-security main
deb https://mirrors.aliyun.com/debian/ bookworm-updates main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian/ bookworm-updates main non-free non-free-firmware contrib
deb https://mirrors.aliyun.com/debian/ bookworm-backports main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian/ bookworm-backports main non-free non-free-firmware contrib

腾讯云镜像站

1
2
3
4
5
6
7
8
deb https://mirrors.tencent.com/debian/ bookworm main non-free non-free-firmware contrib
deb-src https://mirrors.tencent.com/debian/ bookworm main non-free non-free-firmware contrib
deb https://mirrors.tencent.com/debian-security/ bookworm-security main
deb-src https://mirrors.tencent.com/debian-security/ bookworm-security main
deb https://mirrors.tencent.com/debian/ bookworm-updates main non-free non-free-firmware contrib
deb-src https://mirrors.tencent.com/debian/ bookworm-updates main non-free non-free-firmware contrib
deb https://mirrors.tencent.com/debian/ bookworm-backports main non-free non-free-firmware contrib
deb-src https://mirrors.tencent.com/debian/ bookworm-backports main non-free non-free-firmware contrib

网易镜像站

1
2
3
4
5
6
7
8
deb https://mirrors.163.com/debian/ bookworm main non-free non-free-firmware contrib
deb-src https://mirrors.163.com/debian/ bookworm main non-free non-free-firmware contrib
deb https://mirrors.163.com/debian-security/ bookworm-security main
deb-src https://mirrors.163.com/debian-security/ bookworm-security main
deb https://mirrors.163.com/debian/ bookworm-updates main non-free non-free-firmware contrib
deb-src https://mirrors.163.com/debian/ bookworm-updates main non-free non-free-firmware contrib
deb https://mirrors.163.com/debian/ bookworm-backports main non-free non-free-firmware contrib
deb-src https://mirrors.163.com/debian/ bookworm-backports main non-free non-free-firmware contrib

华为镜像站

1
2
3
4
5
6
7
8
deb https://mirrors.huaweicloud.com/debian/ bookworm main non-free non-free-firmware contrib
deb-src https://mirrors.huaweicloud.com/debian/ bookworm main non-free non-free-firmware contrib
deb https://mirrors.huaweicloud.com/debian-security/ bookworm-security main
deb-src https://mirrors.huaweicloud.com/debian-security/ bookworm-security main
deb https://mirrors.huaweicloud.com/debian/ bookworm-updates main non-free non-free-firmware contrib
deb-src https://mirrors.huaweicloud.com/debian/ bookworm-updates main non-free non-free-firmware contrib
deb https://mirrors.huaweicloud.com/debian/ bookworm-backports main non-free non-free-firmware contrib
deb-src https://mirrors.huaweicloud.com/debian/ bookworm-backports main non-free non-free-firmware contrib

清华大学镜像站

1
2
3
4
5
6
7
8
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware

中科大镜像站

1
2
3
4
5
6
7
8
deb https://mirrors.ustc.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb-src https://mirrors.ustc.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb https://mirrors.ustc.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb-src https://mirrors.ustc.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb https://mirrors.ustc.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
deb-src https://mirrors.ustc.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
deb https://mirrors.ustc.edu.cn/debian-security/ bookworm-security main contrib non-free non-free-firmware
deb-src https://mirrors.ustc.edu.cn/debian-security/ bookworm-security main contrib non-free non-free-firmware

HEXO 升级

对于HEXO的升级,可以参考以下步骤:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 查看当前版本
hexo version

# 全局升级hexo命令
npm i hexo-cli -g

# 安装npm-check
npm install -g npm-check

# 检查插件是否需要升级
npm-check

# 安装npm-upgrade
npm install -g npm-upgrade

# 更新package.json
npm-upgrade

code-server手册

启动

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# docker-compose.yml
version: "3"
services:
code-server:
image: lscr.io/linuxserver/code-server:latest
container_name: code-server
environment:
- PUID=1000
- PGID=1000
- TZ=Etc/UTC
- PASSWORD=这里是密码 #optional
- SUDO_PASSWORD=这里是密码 #optional
- DEFAULT_WORKSPACE=/config/workspace #optional
volumes: # 配置在外部 方便更新软件
- /share/data_docker/code_server_data:/config
networks:
- network_default
ports:
- 443:8443
restart: unless-stopped
networks:
network_default:
external: true
name: network_default

配置

常见插件

  • Eclipse快捷键: eclipse keymap
  • 中文简体: zh-cn
  • JAVA开发: spring-boot-devtools
  • Markdown:
    • markdown-all-in-one
    • markdown preview enhaanced
    • markdownlint
  • 通义灵码: tongyi lingma

安装依赖

1
2
3
4
# code-server 使用的是 Ubuntu22.04
apt-get update -y
apt-get install -y openjdk-21-jdk
apt-get install -y npm

安装node

1
2
3
4
5
6
7
8
9
10
# 安装node
apt-get install node
# 安装n
sudo npm install -g n
# 安装node最新stable版本
n stable
# 切换node版本
sudo rm /usr/bin/node
sudo ln -s /usr/local/bin/node /usr/bin/node
npm install -g npm

其他

  • node 所在路径: /app/code-server/lib

申请免费的通配SSL证书

环境

  • 系统:CentOS 7.9
  • 域名:*.example.com

步骤

安装Certbot

  1. 安装Snap
    Snap
  2. 安装Certbot
    Certbot文档

申请证书

1
2
3
4
5
6
7
8
# 因为申请通配证书需要手动验证,所以需要使用dns-01验证方式
certbot certonly -d "*.xx.com" -d xx.com --manual --preferred-challenges dns-01
# 按照提示进行验证 在dns解析中添加txt记录
# 在提示信息中给到的类似https://toolbox.googleapps.com/apps/dig/#TXT/的站点验证txt记录后 再进行下一步

# 最后会生成证书 保存目录会在日志中打印出来
# 证书有效期为90天 需要手动续签 同时还有邮件的,非常方便

github_hosts

github_hosts

说明

github_hosts是一个用于配置github加速的hosts文件。

使用方法

将github_hosts文件中的内容复制到你的hosts文件中,并保存。

仓库地址

镜像链接

Spring Tool Suite

Spring Tool Suite 设置Tab键为4个空格

  • 在Spring Tool Suite -> window -> Preference -> General -> Editors,选择Insert spaces for tabs,若要展示空格可勾选Show whitespace characters
    preferences.jpg

  • 然后展开Java -> Code Style -> Formatter,点击New按钮,在New Profile窗口中,填写Profile name之后,点击OK
    formatter.jpg

  • 在弹出的窗口中,展开Indentation,设置Tab policy的值为 Spaces only

  • profile.jpg

springboot with docker

常用的springboot项目中的Dockerfile示例

Dockerfile:利用容器打包并缓存maven

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# 拉取编译环境
FROM maven:3.8.3-openjdk-17 as builder
# 创建项目目录
RUN mkdir /project

# 使用项目配置的文件
COPY settings.xml /usr/share/maven/conf/settings.xml

# 拷贝源码到固定的目录,注意前面有个 '.'
COPY ./pom.xml /project/pom.xml

# 切换到源码目录
WORKDIR /project

# 安装依赖
RUN mvn dependency:go-offline

# 复制源代码
COPY ./src /project/src

# 使用maven进行编译
RUN mvn clean package -Dmaven.test.skip=true

# 拉取运行环境,这个镜像打包出的镜像比较小,如需要可换成oracle的jre
FROM openjdk:17

# 从编译好的镜像中将jar拷贝到运行时容器
COPY --from=builder /project/target/xxxx.jar /

# 容器启动时执行的命令,这里可加jvm参数
ENTRYPOINT ["java","-jar","/xxxx.jar"]

# 开放端口,根据自己的配置进行开放
EXPOSE 8080

配套deploy.sh脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/bash
start=$(date +%s)
cd /data/java_project_dir #切换到java项目所在目录
echo "切换目录"
git pull
echo "更新代码 完成"
docker build . --tag tts
echo "打包镜像 完成"
docker stop tts
echo "停止服务 完成"
docker rm tts
echo "删除容器 完成"
docker run -itd --name=tts -p 28085:8080 tts
echo "启动服务 完成"
docker image prune -f
echo "删除无tag镜像"
end=$(date +%s)
take=$(( end - start ))
echo 操作完成 本次用时:${take}s

安装dnf命令

正常情况下openjdk:17的镜像中是不带有yum或者dnf命令,如果要用上这个命令那就需要安装一下

  • 启动与openjdk:17 对应相同版本的 oracleLinux (查询镜像内的cat /etc/os-release)

    1
    docker run -itd --name=oraclelinux85 oraclelinux:8.5
  • 进入容器

    1
    docker exec -it oraclelinux85 /bin/bash
  • 安装基础包

    1
    yum -y install yum-utils
  • 下载dnf所有程序包(包括依赖),程序会下载所有文件在当前目录下

    1
    repotrack dnf
  • 退出容器 oraclelinux85 ,并复制文件到宿主机

    1
    docker cp oraclelinux85:/root/* ./tmp 
  • 复制文件从宿主机到目标容器

    1
    docker cp ./tmp  targetContainer:/root/
  • 进入目标容器安装程序

    1
    2
    3
    4
    docker exec -it targetContainer /bin/bah
    cd /root/
    rpm -Uvh --force --nodeps *.rpm
    rm -rf *.rpm

    最后,愉快的使用dnf命令吧

PaddleRec

从Docker中的Ubuntu16.04

1
2
3
4
5
6
7
8
# 拉取镜像
docker pull ubuntu:16.04

# 绑定8888端口并启动
docker run -p 8888:8888 -itd --name ubuntu ubuntu:16.04

# 进入容器内部
docker exec -it ubuntu /bin/bash

在更新容器内的操作系统

1
2
3
4
5
# 更新源
apt update

# 更新操作系统
apt upgrade

安装依赖

1
apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl vim zip unzip wget

更新openssl版本至1.1.1c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

# 切换到主目录
cd ~

# 下载源代码
wget https://www.openssl.org/source/openssl-1.1.1c.tar.gz

# 解压源代码
tar -zxf openssl-1.1.1c.tar.gz

# 进入源代码目录
cd openssl-1.1.1c

# 执行编译安装
./config
make
make install

# 链接库文件
ln -s /usr/local/lib/libcrypto.so.1.1 /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1
ln -s /usr/local/lib/libssl.so.1.1 /usr/lib/x86_64-linux-gnu/libssl.so.1.1

# 备份openssl
mv /usr/bin/openssl /root/

# 链接目录
ln -s /usr/local/bin/openssl /usr/bin/openssl

# 查看当前openssl版本
openssl version

安装Git

1
apt-get install git -y

安装 pyenv 方便安装Python3.7.4

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
curl https://pyenv.run | bash

#添加 对应文件到 .bashrc


#安装 python3.7.4
pyenv install 3.7.4

#全局使用
pyenv global 3.7.4

# 更新pip
python -m pip install --upgrade pip

#安装飞桨1.8.4
python -m pip install paddlepaddle==1.8.4 -i https://mirror.baidu.com/pypi/simple

# 降低飞桨默认安装最新版本的protobuf
pip install protobuf==3.20.1

安装 Jupyter lab

1
2
3
pip install jupyterlab
pip install jupyterlab-language-pack-zh-CN
jupyter lab --allow-root