[TOC]

Docker 快速部署 nfs-server 服务

步骤 01.载入模块 nfs 依赖模块

1
2
3
4
tee -a /etc/modules-load.d/modules.conf <<'EOF'
modprobe nfs
modprobe nfsd
EOF

温馨提示: Linux modprobe命令用于自动处理可载入模块,modprobe可载入指定的个别模块,或是载入一组相依的模块。

步骤 02.创建NFS共享目录以及运行nfs-server容器,并且验证服务

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$ mkdir -vp /app/storage/nfs
$ docker run --privileged -d --name nfs \
-v /app/storage/nfs:/nfsshare \
-e NFS_EXPORT_0='/nfsshare *(rw,sync,no_root_squash,no_all_squash,no_subtree_check,nohide,crossmnt)' \
-p 2049:2049 -p 2049:2049/udp \
-p 111:111 -p 111:111/udp \
-p 32765:32765 -p 32765:32765/udp \
-p 32767:32767 -p 32767:32767/udp \
erichough/nfs-server

# 在Ubuntu宿主机上安装nfs客户端工具
$ sudo apt install nfs-client
$ showmount -e 10.20.176.101
Export list for 10.20.176.101:
/nfsshare *

步骤 03.手动挂载nfs到指定磁盘目录中。

1
mount -v -t nfs -o ro,nfsvers=3,nolock,proto=udp,port=2049 10.20.176.101:/nfsshare /mnt/nfs

参考地址: https://github.com/ehough/docker-nfs-server


Docker 快速部署 samba-server 服务

描述: Samba 是适用于 Linux 和 Unix 的标准 Windows 互操作性程序套件。自 1992 年以来,Samba 为所有使用 SMB/CIFS 协议的客户端提供了安全、稳定和快速的文件和打印服务,例如所有版本的 DOS 和 Windows、OS/2、Linux 等等。

步骤 01.部署 samba-server 服务

1
2
3
4
5
6
7
$ sudo mkdir -vp /app/storage/nfs
$ sudo docker run -it --name samba -p 139:139 -p 445:445 \
-e TZ=Etc/UTC \
-v /app/storage/nfs:/share \
-d dperson/samba -p \
-u "iuser;123456" \
-s "iuser;/share;yes;no;yes"

步骤 02.Windows 中挂载 samba-server

1
2
3
4
5
6
7
8
9
# 方式1.
\\10.20.176.101\iuser

# 方式2.
C:\Users\WeiyiGeek>net use J: \\10.20.176.101\iuser "123456" /USER:iuser /PERSISTEN:yes
# 命令成功完成。

C:\Users\WeiyiGeek>net use | findstr iuser
# OK J: \\10.20.176.101\iuser Microsoft Windows Network

可用 ENVIRONMENT VARIABLES:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
* CHARMAP - As above, configure character mapping
* GENERIC - As above, configure a generic section option (See NOTE3 below)
* GLOBAL - As above, configure a global option (See NOTE3 below)
* IMPORT - As above, import a smbpassword file
* NMBD - As above, enable nmbd
* PERMISSIONS - As above, set file permissions on all shares
* RECYCLE - As above, disable recycle bin
* SHARE - As above, setup a share (See NOTE3 below)
* SMB - As above, disable SMB2 minimum version
* TZ - Set a timezone, IE EST5EDT
* USER - As above, setup a user (See NOTE3 below)
* WIDELINKS - As above, allow access wide symbolic links
* WORKGROUP - As above, set workgroup
* USERID - Set the UID for the samba server's default user (smbuser)
* GROUPID - Set the GID for the samba server's default user (smbuser)
* INCLUDE - As above, add a smb.conf include

官方地址: https://www.samba.org/
参考地址: https://hub.docker.com/r/dperson/samba
Github地址: https://github.com/dperson/samba/issues


Docker 快速部署 Squid 代理服务

描述: Dockerfile 为 Squid 代理服务器创建 Docker 容器镜像, 当前最新版本 sameersbn/squid:3.5.27-2

Q: 什么是 Squid ?
Squid 是一个支持 HTTP、HTTPS、FTP 等的 Web 缓存代理。它通过缓存和重用频繁请求的网页来减少带宽并提高响应时间, Squid 具有广泛的访问控制功能,是出色的服务器加速器。

项目地址: https://github.com/sameersbn/docker-squid
hub地址: https://hub.docker.com/r/sameersbn/squid

温馨提示: 如果你是 CentOS 系统 SELinux 用户应尝试使用命令 setenforce 0 禁用 SELinux,看看它是否能解决问题。

快速部署

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# 1.无代理验证启动(临时用)
docker run --name squid -d --restart=always \
--publish 3128:3128 \
--volume /srv/docker/squid/cache:/var/spool/squid \
sameersbn/squid:3.5.27-2

# 2.docker-compose.yml 方式
Squid:
image: sameersbn/squid:3.5.27-2
ports:
- "3128:3128"
volumes:
- /srv/docker/squid/cache:/var/spool/squid
restart: always

# 3.有代理验证启动(推荐更安全)
htpasswd -c /etc/squid/passwd weiyigeek
# weiyigeek:$apr1$WJnE/R0y$oFBKE6Ir.V5ZAEeH0JK8c.

tee /etc/squid/squid.conf <<'EOF'
# 常规设置
http_port 3128
debug_options ALL,1
hosts_file /etc/hosts
coredump_dir /var/spool/squid
access_log /var/log/squid/access.log squid

# 内部网络
acl localnet src 10.0.0.0/8 # RFC1918 possible internal network
acl localnet src 172.16.0.0/12 # RFC1918 possible internal network
acl localnet src 192.168.0.0/16 # RFC1918 possible internal network

# 允许所有
acl all src all
acl manager proto cache_object
acl localhost src 127.0.0.1/32
acl to_localhost dst 127.0.0.0/8 0.0.0.0/32
http_access allow localnet
http_access allow localhost
http_access deny all
http_access allow all

# 启用PROXY用户验证 (可选)
auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/passwd
acl auth_user proxy_auth REQUIRED
http_access allow auth_user

# 允许客户端IP范围 (可选)
# acl client src 10.0.0.0/8
# http_access allow client
# http_access deny all
EOF

docker run --name squid -d --restart=always \
--publish 3128:3128 \
--volume /etc/squid/squid.conf:/etc/squid/squid.conf \
--volume /etc/squid/passwd:/etc/squid/passwd \
--volume /srv/docker/squid/cache:/var/spool/squid \
sameersbn/squid:3.5.27-2

温馨提示: 要在正在运行的实例上重新加载 Squid 配置,您可以将 HUP 信号发送到容器。
温馨提示: 扩展补充 squid 服务企业内部实践配置 squid.conf

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
$ egrep -v "^#|^$" tar/squid.conf  | more
acl all src all
acl SSL_ports port 443
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # https
acl Safe_ports port 70 # gopher
acl Safe_ports port 210 # wais
acl Safe_ports port 1025-65535 # unregistered ports
acl Safe_ports port 280 # http-mgmt
acl Safe_ports port 488 # gss-http
acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
acl CONNECT method CONNECT
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost manager
http_access deny manager
http_access allow localhost
http_access allow all
http_port 3128
coredump_dir /var/spool/squid
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
refresh_pattern (Release|Packages(.gz)*)$ 0 20% 2880
refresh_pattern . 0 20% 4320


快速使用
描述: 配置您的 Web 浏览器网络/连接设置以使用 172.17.0.1:3128 上的代理服务器, 或者在你linux命令行或Dockerfile可进行如下配置。

1
2
3
4
5
6
7
8
9
10
11
12
13
# .bashrc
export ftp_proxy=http://172.17.0.1:3128
export http_proxy=http://172.17.0.1:3128
export https_proxy=http://172.17.0.1:3128

# Dockerfile
ENV http_proxy=http://172.17.0.1:3128 \
https_proxy=http://172.17.0.1:3128 \
ftp_proxy=http://172.17.0.1:3128

# 有认证的 代理地址
http://{your-username}:{your-password}@{your-ip OR domain-name}:3128
http://weiyigeek:password@proxy.weiyigeek.top:3128


Docker 快速部署 Jenkins 自动集成与交互平台

描述: 此处采用docker-compose方式进行部署Jenkins,其部署的资源清单如下,当前2022年7月13日 11:59:38节点最新版本为2.60.3。

步骤 01.安装部署与初始化操作,带ssl证书访问。

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# 资源清单
tee docker-compose.yml <<'EOF'
# Docker deploy Jenkins Server
version: '3.2'
services:
jenkins:
image: jenkins/jenkins:2.60.3-alpine
container_name: jenkins_server
user: jenkins
labels:
- "app=jenkins"
- "author=WeiyiGeek"
environment:
TZ: "Asia/Shanghai"
JAVA_OPTS: "-XshowSettings:vm -Dhudson.slaves.NodeProvisioner.initialDelay=0 -Dhudson.slaves.NodeProvisioner.MARGIN=50 -Dhudson.slaves.NodeProvisioner.MARGIN0=0.85 -Duser.timezone=Asia/Shanghai -Dhudson.footerURL=https://www.weiyigeek.top -Dfile.encoding=UTF-8"
JENKINS_OPTS: "--httpPort=8080 --httpsPort=8443 --httpsCertificate=/var/lib/jenkins/pki/weiyigeek.top.pem --httpsPrivateKey=/var/lib/jenkins/pki/weiyigeek.top.key"
JENKINS_SLAVE_AGENT_PORT: 50000
volumes:
- /storage/nfs/docker/jenkins/data:/var/jenkins_home
- /opt/jenkins/cert:/var/lib/jenkins/pki
- /etc/localtime:/etc/localtime
extra_hosts:
- "slb-vip.k8s:192.168.12.110"
- "slbvip.k8s.devtest:10.20.176.211"
- "jenkins.weiyigeek.top:127.0.0.1"
ports:
- '8080:8080'
- '8443:8443'
- '50000:50000'
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/login"]
interval: 2m30s
timeout: 10s
retries: 3
restart: always
dns:
- 223.6.6.6
EOF

# 目录权限
chown -R 1000:1000 /storage/nfs/docker/jenkins/data /opt/jenkins/cert

# 运行
docker-compose up -d

# 获取初始化密码
docker logs -f --tail 50 jenkins_server
# Jenkins initial setup is required. An admin user has been created and a password generated.
# Please use the following password to proceed to installation:
# 48bd96655888485fb8bece064a6657bf

温馨提示:最后设置 hosts 硬解析后访问类似 https://jenkins.weiyigeek.top:8443/login?from=%2F 地址进行 jenkins 初始化。

温馨提示: 此处笔者采用的通配符证书(weiyigeek.top.pem 、 weiyigeek.top.key)分别使用 --httpsCertificate--httpsPrivateKey 进行指定。