mirror of
				https://github.com/bjdgyc/anylink.git
				synced 2025-11-04 19:16:22 +08:00 
			
		
		
		
	添加 deploy 部署脚本
优化应用易用性
This commit is contained in:
		
							
								
								
									
										9
									
								
								.github/workflows/release.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										9
									
								
								.github/workflows/release.yml
									
									
									
									
										vendored
									
									
								
							@@ -60,8 +60,8 @@ jobs:
 | 
				
			|||||||
        uses: docker/build-push-action@v5
 | 
					        uses: docker/build-push-action@v5
 | 
				
			||||||
        with:
 | 
					        with:
 | 
				
			||||||
          push: true
 | 
					          push: true
 | 
				
			||||||
          #cache-from: type=gha,mode=max
 | 
					          cache-from: type=gha,scope=anylink
 | 
				
			||||||
          #cache-to: type=gha,mode=max
 | 
					          cache-to: type=gha,mode=max,scope=anylink
 | 
				
			||||||
          context: .
 | 
					          context: .
 | 
				
			||||||
          file: ./docker/Dockerfile
 | 
					          file: ./docker/Dockerfile
 | 
				
			||||||
          #platforms: linux/amd64,linux/arm64
 | 
					          #platforms: linux/amd64,linux/arm64
 | 
				
			||||||
@@ -77,6 +77,11 @@ jobs:
 | 
				
			|||||||
        run: bash release.sh
 | 
					        run: bash release.sh
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      - name: Release
 | 
					      - name: Release
 | 
				
			||||||
 | 
					        # https://github.com/ncipollo/release-action
 | 
				
			||||||
 | 
					        # artifacts: bin/release/*
 | 
				
			||||||
 | 
					        # generateReleaseNotes: true
 | 
				
			||||||
 | 
					        # draft: true
 | 
				
			||||||
 | 
					        # https://github.com/softprops/action-gh-release
 | 
				
			||||||
        uses: softprops/action-gh-release@v1
 | 
					        uses: softprops/action-gh-release@v1
 | 
				
			||||||
        #if: startsWith(github.ref, 'refs/tags/')
 | 
					        #if: startsWith(github.ref, 'refs/tags/')
 | 
				
			||||||
        with:
 | 
					        with:
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -2,6 +2,8 @@
 | 
				
			|||||||
.idea/
 | 
					.idea/
 | 
				
			||||||
anylink-deploy
 | 
					anylink-deploy
 | 
				
			||||||
anylink-deploy.tar.gz
 | 
					anylink-deploy.tar.gz
 | 
				
			||||||
 | 
					anylink
 | 
				
			||||||
 | 
					anylink.db
 | 
				
			||||||
 | 
					
 | 
				
			||||||
dist
 | 
					dist
 | 
				
			||||||
artifact-dist
 | 
					artifact-dist
 | 
				
			||||||
@@ -47,7 +47,7 @@ builds:
 | 
				
			|||||||
        {{- if eq .Os "linux" }}
 | 
					        {{- if eq .Os "linux" }}
 | 
				
			||||||
          {{- if eq .Arch "amd64" }}CC=x86_64-linux-musl-gcc{{- end }}
 | 
					          {{- if eq .Arch "amd64" }}CC=x86_64-linux-musl-gcc{{- end }}
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
          {{- if eq .Arch "arm64" }}CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++{{- end }}
 | 
					          {{- if eq .Arch "arm64" }}CC=aarch64-linux-gnu-gcc{{- end }}
 | 
				
			||||||
        {{- end }}
 | 
					        {{- end }}
 | 
				
			||||||
        {{- if eq .Os "darwin" }}
 | 
					        {{- if eq .Os "darwin" }}
 | 
				
			||||||
          {{- if eq .Arch "amd64"}}CC=o64-clang{{- end }}
 | 
					          {{- if eq .Arch "amd64"}}CC=o64-clang{{- end }}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										95
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										95
									
								
								README.md
									
									
									
									
									
								
							@@ -47,6 +47,8 @@ AnyLink 服务端仅在 CentOS 7、CentOS 8、Ubuntu 18.04、Ubuntu 20.04 测试
 | 
				
			|||||||
> 没有编程基础的同学建议直接下载 release 包,从下面的地址下载 anylink-deploy.tar.gz
 | 
					> 没有编程基础的同学建议直接下载 release 包,从下面的地址下载 anylink-deploy.tar.gz
 | 
				
			||||||
>
 | 
					>
 | 
				
			||||||
> https://github.com/bjdgyc/anylink/releases
 | 
					> https://github.com/bjdgyc/anylink/releases
 | 
				
			||||||
 | 
					>
 | 
				
			||||||
 | 
					> 如果不会安装,可以提供有偿远程协助服务。添加QQ联系我 68492170
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 使用问题
 | 
					### 使用问题
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -66,7 +68,7 @@ AnyLink 服务端仅在 CentOS 7、CentOS 8、Ubuntu 18.04、Ubuntu 20.04 测试
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
### 自行编译安装
 | 
					### 自行编译安装
 | 
				
			||||||
 | 
					
 | 
				
			||||||
> 需要提前安装好 golang >= 1.20 和 nodejs >= 16.x 和 yarn >= v1.22.x
 | 
					> 需要提前安装好 golang >= 1.20 和 nodejs = 16.x 和 yarn >= v1.22.x
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```shell
 | 
					```shell
 | 
				
			||||||
git clone https://github.com/bjdgyc/anylink.git
 | 
					git clone https://github.com/bjdgyc/anylink.git
 | 
				
			||||||
@@ -123,14 +125,22 @@ sudo ./anylink
 | 
				
			|||||||
> 示例配置文件内有详细的注释,根据注释填写配置即可。
 | 
					> 示例配置文件内有详细的注释,根据注释填写配置即可。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```shell
 | 
					```shell
 | 
				
			||||||
 | 
					# 查看帮助信息
 | 
				
			||||||
 | 
					./anylink -h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# 生成后台密码
 | 
					# 生成后台密码
 | 
				
			||||||
./anylink tool -p 123456
 | 
					./anylink tool -p 123456
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# 生成jwt密钥
 | 
					# 生成jwt密钥
 | 
				
			||||||
./anylink tool -s
 | 
					./anylink tool -s
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# 查看所有配置项
 | 
				
			||||||
 | 
					./anylink tool -d
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
> 数据库配置示例
 | 
					> 数据库配置示例
 | 
				
			||||||
 | 
					>
 | 
				
			||||||
 | 
					> 数据库表结构自动生成,无需手动导入(请赋予 DDL 权限)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| db_type  | db_source                                              |
 | 
					| db_type  | db_source                                              |
 | 
				
			||||||
|----------|--------------------------------------------------------|
 | 
					|----------|--------------------------------------------------------|
 | 
				
			||||||
@@ -142,6 +152,14 @@ sudo ./anylink
 | 
				
			|||||||
>
 | 
					>
 | 
				
			||||||
> [conf/server-sample.toml](server/conf/server-sample.toml)
 | 
					> [conf/server-sample.toml](server/conf/server-sample.toml)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Upgrade
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					> 升级前请备份配置文件`conf`目录 和 数据库,并停止服务
 | 
				
			||||||
 | 
					>
 | 
				
			||||||
 | 
					> 使用新版的 `anylink` 二进制文件替换旧版
 | 
				
			||||||
 | 
					>
 | 
				
			||||||
 | 
					> 重启服务后,即可完成升级
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Setting
 | 
					## Setting
 | 
				
			||||||
 | 
					
 | 
				
			||||||
> 以下参数必须设置其中之一
 | 
					> 以下参数必须设置其中之一
 | 
				
			||||||
@@ -214,12 +232,17 @@ https://cloud.tencent.com/document/product/216/62007
 | 
				
			|||||||
> 以下参数可以通过执行 `ip a` 查看
 | 
					> 以下参数可以通过执行 `ip a` 查看
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# 命令行执行 master网卡需要打开混杂模式
 | 
				
			||||||
 | 
					ip link set dev eth0 promisc on
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#=====================#
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# 配置文件修改
 | 
				
			||||||
# 首先关闭nat转发功能
 | 
					# 首先关闭nat转发功能
 | 
				
			||||||
iptables_nat = false
 | 
					iptables_nat = false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# master网卡需要打开混杂模式
 | 
					link_mode = "macvtap"
 | 
				
			||||||
ip link set dev eth0 promisc on
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#内网主网卡名称
 | 
					#内网主网卡名称
 | 
				
			||||||
ipv4_master = "eth0"
 | 
					ipv4_master = "eth0"
 | 
				
			||||||
#以下网段需要跟ipv4_master网卡设置成一样
 | 
					#以下网段需要跟ipv4_master网卡设置成一样
 | 
				
			||||||
@@ -229,28 +252,36 @@ ipv4_start = "10.1.2.100"
 | 
				
			|||||||
ipv4_end = "10.1.2.200"
 | 
					ipv4_end = "10.1.2.200"
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Systemd
 | 
					## Deploy
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					> 部署配置文件放在 `deploy` 目录下,请根据实际情况修改配置文件
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### Systemd
 | 
				
			||||||
 | 
					
 | 
				
			||||||
1. 添加 anylink 程序
 | 
					1. 添加 anylink 程序
 | 
				
			||||||
 | 
					    - 首先把 `anylink-deploy` 文件夹放入 `/usr/local/anylink-deploy`
 | 
				
			||||||
    - anylink 程序目录放入 `/usr/local/anylink-deploy`
 | 
					 | 
				
			||||||
    - 添加执行权限 `chmod +x /usr/local/anylink-deploy/anylink`
 | 
					    - 添加执行权限 `chmod +x /usr/local/anylink-deploy/anylink`
 | 
				
			||||||
 | 
					2. 把 `anylink.service` 脚本放入:
 | 
				
			||||||
2. systemd/anylink.service 脚本放入:
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    - centos: `/usr/lib/systemd/system/`
 | 
					    - centos: `/usr/lib/systemd/system/`
 | 
				
			||||||
    - ubuntu: `/lib/systemd/system/`
 | 
					    - ubuntu: `/lib/systemd/system/`
 | 
				
			||||||
 | 
					 | 
				
			||||||
3. 操作命令:
 | 
					3. 操作命令:
 | 
				
			||||||
 | 
					 | 
				
			||||||
    - 启动: `systemctl start anylink`
 | 
					    - 启动: `systemctl start anylink`
 | 
				
			||||||
    - 停止: `systemctl stop anylink`
 | 
					    - 停止: `systemctl stop anylink`
 | 
				
			||||||
    - 开机自启: `systemctl enable anylink`
 | 
					    - 开机自启: `systemctl enable anylink`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### Docker Compose
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					1. 进入 `deploy` 目录
 | 
				
			||||||
 | 
					2. 执行脚本 `docker-compose up`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### k8s
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					1. 进入 `deploy` 目录
 | 
				
			||||||
 | 
					2. 执行脚本 `kubectl apply -f deployment.yaml`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Docker
 | 
					## Docker
 | 
				
			||||||
 | 
					
 | 
				
			||||||
1. 获取镜像
 | 
					1. 获取镜像
 | 
				
			||||||
 | 
					 | 
				
			||||||
   ```bash
 | 
					   ```bash
 | 
				
			||||||
   # 具体tag可以从docker hub获取
 | 
					   # 具体tag可以从docker hub获取
 | 
				
			||||||
   # https://hub.docker.com/r/bjdgyc/anylink/tags
 | 
					   # https://hub.docker.com/r/bjdgyc/anylink/tags
 | 
				
			||||||
@@ -258,50 +289,67 @@ ipv4_end = "10.1.2.200"
 | 
				
			|||||||
   ```
 | 
					   ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
2. 查看命令信息
 | 
					2. 查看命令信息
 | 
				
			||||||
 | 
					 | 
				
			||||||
   ```bash
 | 
					   ```bash
 | 
				
			||||||
   docker run -it --rm bjdgyc/anylink -h
 | 
					   docker run -it --rm bjdgyc/anylink -h
 | 
				
			||||||
   ```
 | 
					   ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
3. 生成密码
 | 
					3. 生成密码
 | 
				
			||||||
 | 
					 | 
				
			||||||
   ```bash
 | 
					   ```bash
 | 
				
			||||||
   docker run -it --rm bjdgyc/anylink tool -p 123456
 | 
					   docker run -it --rm bjdgyc/anylink tool -p 123456
 | 
				
			||||||
   #Passwd:$2a$10$lCWTCcGmQdE/4Kb1wabbLelu4vY/cUwBwN64xIzvXcihFgRzUvH2a
 | 
					   #Passwd:$2a$10$lCWTCcGmQdE/4Kb1wabbLelu4vY/cUwBwN64xIzvXcihFgRzUvH2a
 | 
				
			||||||
   ```
 | 
					   ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
4. 生成 jwt secret
 | 
					4. 生成 jwt secret
 | 
				
			||||||
 | 
					 | 
				
			||||||
   ```bash
 | 
					   ```bash
 | 
				
			||||||
   docker run -it --rm bjdgyc/anylink tool -s
 | 
					   docker run -it --rm bjdgyc/anylink tool -s
 | 
				
			||||||
   #Secret:9qXoIhY01jqhWIeIluGliOS4O_rhcXGGGu422uRZ1JjZxIZmh17WwzW36woEbA
 | 
					   #Secret:9qXoIhY01jqhWIeIluGliOS4O_rhcXGGGu422uRZ1JjZxIZmh17WwzW36woEbA
 | 
				
			||||||
   ```
 | 
					   ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
5. 启动容器
 | 
					5. 查看所有配置项
 | 
				
			||||||
 | 
					 | 
				
			||||||
   ```bash
 | 
					   ```bash
 | 
				
			||||||
 | 
					   docker run -it --rm bjdgyc/anylink tool -d
 | 
				
			||||||
 | 
					   ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					6. 启动容器
 | 
				
			||||||
 | 
					   ```bash
 | 
				
			||||||
 | 
					   # 默认启动
 | 
				
			||||||
   docker run -itd --name anylink --privileged \
 | 
					   docker run -itd --name anylink --privileged \
 | 
				
			||||||
       -p 443:443 -p 8800:8800 \
 | 
					       -p 443:443 -p 8800:8800 -p 443:443/udp \
 | 
				
			||||||
       --restart=always \
 | 
					       --restart=always \
 | 
				
			||||||
       bjdgyc/anylink
 | 
					       bjdgyc/anylink
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					   # 自定义配置目录
 | 
				
			||||||
 | 
					   # 首次启动会自动创建配置文件
 | 
				
			||||||
 | 
					   # 配置文件初始化完成后,容器会强制退出,请重新启动容器
 | 
				
			||||||
 | 
					   docker run -itd --name anylink --privileged \
 | 
				
			||||||
 | 
					       -p 443:443 -p 8800:8800 -p 443:443/udp \
 | 
				
			||||||
 | 
					       -v /home/myconf:/app/conf \
 | 
				
			||||||
 | 
					       --restart=always \
 | 
				
			||||||
 | 
					       bjdgyc/anylink
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					   docker restart anylink
 | 
				
			||||||
   ```
 | 
					   ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
6. 使用自定义参数启动容器
 | 
					6. 使用自定义参数启动容器
 | 
				
			||||||
   ```bash
 | 
					   ```bash
 | 
				
			||||||
   # 参数可以参考 -h 命令
 | 
					   # 参数可以参考 ./anylink tool -d
 | 
				
			||||||
 | 
					   # 可以使用命令行参数 或者 环境变量 配置
 | 
				
			||||||
   docker run -itd --name anylink --privileged \
 | 
					   docker run -itd --name anylink --privileged \
 | 
				
			||||||
       -p 443:443 -p 8800:8800 \
 | 
					       -e LINK_LOG_LEVEL=info \
 | 
				
			||||||
 | 
					       -p 443:443 -p 8800:8800 -p 443:443/udp \
 | 
				
			||||||
 | 
					       -v /home/myconf:/app/conf \
 | 
				
			||||||
       --restart=always \
 | 
					       --restart=always \
 | 
				
			||||||
       bjdgyc/anylink \
 | 
					       bjdgyc/anylink \
 | 
				
			||||||
       -c=/etc/server.toml --ip_lease=1209600 # IP地址租约时长
 | 
					       --ip_lease=1209600 # IP地址租约时长
 | 
				
			||||||
   ```
 | 
					   ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
7. 构建镜像 (非必需)
 | 
					7. 构建镜像 (非必需)
 | 
				
			||||||
 | 
					 | 
				
			||||||
   ```bash
 | 
					   ```bash
 | 
				
			||||||
   #获取仓库源码
 | 
					   #获取仓库源码
 | 
				
			||||||
   git clone https://github.com/bjdgyc/anylink.git
 | 
					   git clone https://github.com/bjdgyc/anylink.git
 | 
				
			||||||
   # 构建镜像
 | 
					   # 构建镜像
 | 
				
			||||||
 | 
					   sh build_docker.sh
 | 
				
			||||||
 | 
					   或
 | 
				
			||||||
   docker build -t anylink -f docker/Dockerfile .
 | 
					   docker build -t anylink -f docker/Dockerfile .
 | 
				
			||||||
   ```
 | 
					   ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -329,7 +377,6 @@ ipv4_end = "10.1.2.200"
 | 
				
			|||||||
- [OpenConnect](https://gitlab.com/openconnect/openconnect) (Windows/macOS/Linux)
 | 
					- [OpenConnect](https://gitlab.com/openconnect/openconnect) (Windows/macOS/Linux)
 | 
				
			||||||
- [AnyLink Secure Client](https://github.com/tlslink/anylink-client) (Windows/macOS/Linux)
 | 
					- [AnyLink Secure Client](https://github.com/tlslink/anylink-client) (Windows/macOS/Linux)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
## Contribution
 | 
					## Contribution
 | 
				
			||||||
 | 
					
 | 
				
			||||||
欢迎提交 PR、Issues,感谢为 AnyLink 做出贡献。
 | 
					欢迎提交 PR、Issues,感谢为 AnyLink 做出贡献。
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										2
									
								
								build.sh
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								build.sh
									
									
									
									
									
								
							@@ -31,7 +31,7 @@ cp -rf $cpath/web/ui .
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
# -tags osusergo,netgo,sqlite_omit_load_extension
 | 
					# -tags osusergo,netgo,sqlite_omit_load_extension
 | 
				
			||||||
flags="-v -trimpath"
 | 
					flags="-v -trimpath"
 | 
				
			||||||
ldflags="-s -w -extldflags '-static' -X main.appVer=$ver -X main.commitId=$(git rev-parse HEAD) -X main.date=$(date --iso-8601=seconds)"
 | 
					ldflags="-s -w -extldflags '-static' -X main.appVer=$ver -X main.commitId=$(git rev-parse HEAD) -X main.date=$(date -Iseconds)"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#国内可替换源加快速度
 | 
					#国内可替换源加快速度
 | 
				
			||||||
export GOPROXY=https://goproxy.io
 | 
					export GOPROXY=https://goproxy.io
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,9 +5,11 @@ echo $ver
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
# docker login -u bjdgyc
 | 
					# docker login -u bjdgyc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# docker build -t bjdgyc/anylink -f docker/Dockerfile .
 | 
					# 生成时间 2024-01-30T21:41:27+08:00
 | 
				
			||||||
 | 
					# date -Iseconds
 | 
				
			||||||
 | 
					
 | 
				
			||||||
docker buildx build -t bjdgyc/anylink --progress=plain --build-arg CN="yes" --build-arg appVer=$ver \
 | 
					docker buildx build -t bjdgyc/anylink:latest --progress=plain --build-arg CN="yes" --build-arg appVer=$ver \
 | 
				
			||||||
  --build-arg commitId=$(git rev-parse HEAD) -f docker/Dockerfile .
 | 
					  --build-arg commitId=$(git rev-parse HEAD) -f docker/Dockerfile .
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					echo "docker tag latest $ver"
 | 
				
			||||||
docker tag bjdgyc/anylink:latest bjdgyc/anylink:$ver
 | 
					docker tag bjdgyc/anylink:latest bjdgyc/anylink:$ver
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,8 +17,8 @@ ExecStart=/usr/local/anylink-deploy/anylink --conf=/usr/local/anylink-deploy/con
 | 
				
			|||||||
# ExecStart=/bin/bash -c 'exec /usr/local/anylink-deploy/anylink --conf=/usr/local/anylink-deploy/conf/server.toml >> /usr/local/anylink-deploy/log/anylink.log 2>&1'
 | 
					# ExecStart=/bin/bash -c 'exec /usr/local/anylink-deploy/anylink --conf=/usr/local/anylink-deploy/conf/server.toml >> /usr/local/anylink-deploy/log/anylink.log 2>&1'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# systemd new than v236
 | 
					# systemd new than v236
 | 
				
			||||||
# StandardOutput=file:/usr/local/anylink-deploy/log/anylink.log
 | 
					# StandardOutput=file:/usr/local/anylink-deploy/log/anylink-systemd.log
 | 
				
			||||||
# StandardError=file:/usr/local/anylink-deploy/log/anylink.log
 | 
					# StandardError=file:/usr/local/anylink-deploy/log/anylink-systemd.log
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[Install]
 | 
					[Install]
 | 
				
			||||||
WantedBy=multi-user.target
 | 
					WantedBy=multi-user.target
 | 
				
			||||||
							
								
								
									
										101
									
								
								deploy/deployment.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										101
									
								
								deploy/deployment.yaml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,101 @@
 | 
				
			|||||||
 | 
					apiVersion: apps/v1
 | 
				
			||||||
 | 
					kind: Deployment
 | 
				
			||||||
 | 
					metadata:
 | 
				
			||||||
 | 
					  name: anylink
 | 
				
			||||||
 | 
					  namespace: default
 | 
				
			||||||
 | 
					  labels:
 | 
				
			||||||
 | 
					    link-app: anylink
 | 
				
			||||||
 | 
					spec:
 | 
				
			||||||
 | 
					  replicas: 1
 | 
				
			||||||
 | 
					  selector:
 | 
				
			||||||
 | 
					    matchLabels:
 | 
				
			||||||
 | 
					      link-app: anylink
 | 
				
			||||||
 | 
					  template:
 | 
				
			||||||
 | 
					    metadata:
 | 
				
			||||||
 | 
					      labels:
 | 
				
			||||||
 | 
					        link-app: anylink
 | 
				
			||||||
 | 
					    spec:
 | 
				
			||||||
 | 
					      #hostNetwork: true
 | 
				
			||||||
 | 
					      dnsPolicy: ClusterFirst
 | 
				
			||||||
 | 
					      containers:
 | 
				
			||||||
 | 
					        - name: anylink
 | 
				
			||||||
 | 
					          env:
 | 
				
			||||||
 | 
					            - name: NODE_NAME
 | 
				
			||||||
 | 
					              valueFrom:
 | 
				
			||||||
 | 
					                fieldRef:
 | 
				
			||||||
 | 
					                  apiVersion: v1
 | 
				
			||||||
 | 
					                  fieldPath: spec.nodeName
 | 
				
			||||||
 | 
					            - name: GOMAXPROCS
 | 
				
			||||||
 | 
					              valueFrom:
 | 
				
			||||||
 | 
					                resourceFieldRef:
 | 
				
			||||||
 | 
					                  resource: limits.cpu
 | 
				
			||||||
 | 
					            - name: POD_CPU_LIMIT
 | 
				
			||||||
 | 
					              valueFrom:
 | 
				
			||||||
 | 
					                resourceFieldRef:
 | 
				
			||||||
 | 
					                  resource: limits.cpu
 | 
				
			||||||
 | 
					            - name: POD_MEMORY_LIMIT
 | 
				
			||||||
 | 
					              valueFrom:
 | 
				
			||||||
 | 
					                resourceFieldRef:
 | 
				
			||||||
 | 
					                  resource: limits.memory
 | 
				
			||||||
 | 
					            - name: TZ
 | 
				
			||||||
 | 
					              value: "Asia/Shanghai"
 | 
				
			||||||
 | 
					          image: bjdgyc/anylink:latest
 | 
				
			||||||
 | 
					          imagePullPolicy: Always
 | 
				
			||||||
 | 
					          args:
 | 
				
			||||||
 | 
					            - --conf=/app/conf/server.toml
 | 
				
			||||||
 | 
					          ports:
 | 
				
			||||||
 | 
					            - name: https
 | 
				
			||||||
 | 
					              containerPort: 443
 | 
				
			||||||
 | 
					              protocol: TCP
 | 
				
			||||||
 | 
					            - name: https-admin
 | 
				
			||||||
 | 
					              containerPort: 8800
 | 
				
			||||||
 | 
					              protocol: TCP
 | 
				
			||||||
 | 
					            - name: dtls
 | 
				
			||||||
 | 
					              containerPort: 443
 | 
				
			||||||
 | 
					              protocol: UDP
 | 
				
			||||||
 | 
					          # 设置资源
 | 
				
			||||||
 | 
					          resources:
 | 
				
			||||||
 | 
					            limits:
 | 
				
			||||||
 | 
					              cpu: "2"
 | 
				
			||||||
 | 
					              memory: 4Gi
 | 
				
			||||||
 | 
					              ephemeral-storage: "2Gi"
 | 
				
			||||||
 | 
					          securityContext:
 | 
				
			||||||
 | 
					            privileged: true
 | 
				
			||||||
 | 
					      # 禁用自动注入 service 信息到环境变量
 | 
				
			||||||
 | 
					      enableServiceLinks: false
 | 
				
			||||||
 | 
					      restartPolicy: Always
 | 
				
			||||||
 | 
					      terminationGracePeriodSeconds: 30
 | 
				
			||||||
 | 
					      nodeSelector:
 | 
				
			||||||
 | 
					        kubernetes.io/os: linux
 | 
				
			||||||
 | 
					      securityContext: { }
 | 
				
			||||||
 | 
					      tolerations:
 | 
				
			||||||
 | 
					        - operator: Exists
 | 
				
			||||||
 | 
					      #设置优先级
 | 
				
			||||||
 | 
					      priorityClassName: system-cluster-critical
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					---
 | 
				
			||||||
 | 
					apiVersion: v1
 | 
				
			||||||
 | 
					kind: Service
 | 
				
			||||||
 | 
					metadata:
 | 
				
			||||||
 | 
					  name: anylink
 | 
				
			||||||
 | 
					  namespace: default
 | 
				
			||||||
 | 
					  labels:
 | 
				
			||||||
 | 
					    link-app: anylink
 | 
				
			||||||
 | 
					spec:
 | 
				
			||||||
 | 
					  ports:
 | 
				
			||||||
 | 
					    - name: https
 | 
				
			||||||
 | 
					      port: 443
 | 
				
			||||||
 | 
					      targetPort: 443
 | 
				
			||||||
 | 
					      protocol: TCP
 | 
				
			||||||
 | 
					    - name: https-admin
 | 
				
			||||||
 | 
					      port: 8800
 | 
				
			||||||
 | 
					      targetPort: 8800
 | 
				
			||||||
 | 
					      protocol: TCP
 | 
				
			||||||
 | 
					    - name: dtls
 | 
				
			||||||
 | 
					      port: 443
 | 
				
			||||||
 | 
					      targetPort: 443
 | 
				
			||||||
 | 
					      protocol: UDP
 | 
				
			||||||
 | 
					  selector:
 | 
				
			||||||
 | 
					    link-app: anylink
 | 
				
			||||||
 | 
					  sessionAffinity: ClientIP
 | 
				
			||||||
 | 
					  type: ClusterIP
 | 
				
			||||||
							
								
								
									
										19
									
								
								deploy/docker-compose.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								deploy/docker-compose.yaml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
				
			|||||||
 | 
					services:
 | 
				
			||||||
 | 
					  anylink:
 | 
				
			||||||
 | 
					    image: bjdgyc/anylink:latest
 | 
				
			||||||
 | 
					    container_name: anylink
 | 
				
			||||||
 | 
					    restart: always
 | 
				
			||||||
 | 
					    privileged: true
 | 
				
			||||||
 | 
					    #cpus: 2
 | 
				
			||||||
 | 
					    #mem_limit: 4g
 | 
				
			||||||
 | 
					    ports:
 | 
				
			||||||
 | 
					      - 443:443
 | 
				
			||||||
 | 
					      - 8800:8800
 | 
				
			||||||
 | 
					      - 443:443/udp
 | 
				
			||||||
 | 
					    environment:
 | 
				
			||||||
 | 
					      LINK_LOG_LEVEL: info
 | 
				
			||||||
 | 
					    command:
 | 
				
			||||||
 | 
					      - --conf=/app/conf/server.toml
 | 
				
			||||||
 | 
					    #volumes:
 | 
				
			||||||
 | 
					    #  - /home/myconf:/app/conf
 | 
				
			||||||
 | 
					    dns_search: .
 | 
				
			||||||
@@ -16,39 +16,37 @@ ARG commitId="commitId"
 | 
				
			|||||||
ENV TZ=Asia/Shanghai
 | 
					ENV TZ=Asia/Shanghai
 | 
				
			||||||
 | 
					
 | 
				
			||||||
WORKDIR /server
 | 
					WORKDIR /server
 | 
				
			||||||
COPY docker/init.sh /tmp/init.sh
 | 
					COPY docker/init_build.sh /tmp/
 | 
				
			||||||
COPY server/ /server/
 | 
					COPY server/ /server/
 | 
				
			||||||
COPY web/ui  /server/ui
 | 
					COPY web/ui  /server/ui
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#RUN apk add gcc musl-dev bash
 | 
					#RUN apk add gcc musl-dev bash
 | 
				
			||||||
RUN sh /tmp/init.sh
 | 
					RUN sh /tmp/init_build.sh
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# anylink
 | 
					# anylink
 | 
				
			||||||
FROM alpine:3.19
 | 
					FROM alpine:3.19
 | 
				
			||||||
LABEL maintainer="github.com/bjdgyc"
 | 
					LABEL maintainer="github.com/bjdgyc"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ARG CN="no"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ENV TZ=Asia/Shanghai
 | 
					ENV TZ=Asia/Shanghai
 | 
				
			||||||
ENV ANYLINK_IN_CONTAINER=true
 | 
					ENV ANYLINK_IN_CONTAINER=true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
WORKDIR /app
 | 
					WORKDIR /app
 | 
				
			||||||
 | 
					COPY docker/init_release.sh /tmp/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
COPY --from=builder_golang /server/anylink  /app/
 | 
					COPY --from=builder_golang /server/anylink  /app/
 | 
				
			||||||
COPY docker/docker_entrypoint.sh  /app/
 | 
					COPY docker/docker_entrypoint.sh server/bridge-init.sh ./README.md ./LICENSE /app/
 | 
				
			||||||
COPY ./server/bridge-init.sh /app/
 | 
					COPY ./deploy /app/deploy
 | 
				
			||||||
COPY ./server/conf  /app/conf
 | 
					 | 
				
			||||||
COPY ./systemd /app/systemd
 | 
					 | 
				
			||||||
COPY ./README.md  /app/README.md
 | 
					 | 
				
			||||||
COPY ./LICENSE  /app/LICENSE
 | 
					 | 
				
			||||||
COPY ./home  /app/home
 | 
					COPY ./home  /app/home
 | 
				
			||||||
 | 
					COPY ./server/conf  /app/conf
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#TODO 本地打包时使用镜像
 | 
					#TODO 本地打包时使用镜像
 | 
				
			||||||
#RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories
 | 
					RUN sh /tmp/init_release.sh
 | 
				
			||||||
RUN apk add --no-cache bash iptables iproute2 tzdata \
 | 
					 | 
				
			||||||
    && chmod +x /app/docker_entrypoint.sh \
 | 
					 | 
				
			||||||
    && mkdir /app/log \
 | 
					 | 
				
			||||||
    && ls /app
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
EXPOSE 443 8800
 | 
					
 | 
				
			||||||
 | 
					EXPOSE 443 8800 443/udp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#CMD ["/app/anylink"]
 | 
					#CMD ["/app/anylink"]
 | 
				
			||||||
ENTRYPOINT ["/app/docker_entrypoint.sh"]
 | 
					ENTRYPOINT ["/app/docker_entrypoint.sh"]
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,6 +18,14 @@ case $var1 in
 | 
				
			|||||||
  #iptables -t nat -A POSTROUTING -s "${IPV4_CIDR}" -o eth0+ -j MASQUERADE
 | 
					  #iptables -t nat -A POSTROUTING -s "${IPV4_CIDR}" -o eth0+ -j MASQUERADE
 | 
				
			||||||
  #iptables -nL -t nat
 | 
					  #iptables -nL -t nat
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  # 启动服务 先判断配置文件是否存在
 | 
				
			||||||
 | 
					  if [ ! -f /app/conf/profile.xml ]; then
 | 
				
			||||||
 | 
					    /bin/cp -r /home/conf-bak/* /app/conf/
 | 
				
			||||||
 | 
					    echo "After the configuration file is initialized, the container will be forcibly exited. Restart the container."
 | 
				
			||||||
 | 
					    echo "配置文件初始化完成后,容器会强制退出,请重新启动容器。"
 | 
				
			||||||
 | 
					    exit 1
 | 
				
			||||||
 | 
					  fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  exec /app/anylink "$@"
 | 
					  exec /app/anylink "$@"
 | 
				
			||||||
  ;;
 | 
					  ;;
 | 
				
			||||||
esac
 | 
					esac
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
#!/bin/bash
 | 
					#!/bin/sh
 | 
				
			||||||
 | 
					
 | 
				
			||||||
set -x
 | 
					set -x
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										21
									
								
								docker/init_release.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								docker/init_release.sh
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
				
			|||||||
 | 
					#!/bin/sh
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					set -x
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#TODO 本地打包时使用镜像
 | 
				
			||||||
 | 
					if [[ $CN == "yes" ]]; then
 | 
				
			||||||
 | 
					  sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories
 | 
				
			||||||
 | 
					  export GOPROXY=https://goproxy.cn
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					apk add --no-cache bash iptables iproute2 tzdata
 | 
				
			||||||
 | 
					chmod +x /app/docker_entrypoint.sh
 | 
				
			||||||
 | 
					mkdir /app/log
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#备份配置文件
 | 
				
			||||||
 | 
					cp -r /app/conf /home/conf-bak
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					tree /app
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					uname -a
 | 
				
			||||||
 | 
					date -Iseconds
 | 
				
			||||||
@@ -17,8 +17,8 @@ cpath=$(pwd)
 | 
				
			|||||||
ver=$(cat version)
 | 
					ver=$(cat version)
 | 
				
			||||||
echo "当前版本 $ver"
 | 
					echo "当前版本 $ver"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					rm -rf artifact-dist
 | 
				
			||||||
mkdir artifact-dist
 | 
					mkdir artifact-dist
 | 
				
			||||||
rm -rf artifact-dist/* app
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
function archive() {
 | 
					function archive() {
 | 
				
			||||||
  os=$1
 | 
					  os=$1
 | 
				
			||||||
@@ -26,11 +26,11 @@ function archive() {
 | 
				
			|||||||
  #echo "整理部署文件 $os $arch"
 | 
					  #echo "整理部署文件 $os $arch"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  deploy="anylink-$ver-$os-$arch"
 | 
					  deploy="anylink-$ver-$os-$arch"
 | 
				
			||||||
 | 
					  docker container rm $deploy
 | 
				
			||||||
  docker container create --platform $os/$arch --name $deploy bjdgyc/anylink:$ver
 | 
					  docker container create --platform $os/$arch --name $deploy bjdgyc/anylink:$ver
 | 
				
			||||||
  docker cp -a $deploy:/app ./
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  rm -rf anylink-deploy
 | 
					  rm -rf anylink-deploy
 | 
				
			||||||
  mv app anylink-deploy
 | 
					  docker cp -a $deploy:/app ./anylink-deploy
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  ls -lh anylink-deploy
 | 
					  ls -lh anylink-deploy
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  tar zcf ${deploy}.tar.gz anylink-deploy
 | 
					  tar zcf ${deploy}.tar.gz anylink-deploy
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -155,6 +155,7 @@ type SCfg struct {
 | 
				
			|||||||
	Env  string      `json:"env"`
 | 
						Env  string      `json:"env"`
 | 
				
			||||||
	Info string      `json:"info"`
 | 
						Info string      `json:"info"`
 | 
				
			||||||
	Data interface{} `json:"data"`
 | 
						Data interface{} `json:"data"`
 | 
				
			||||||
 | 
						Val  interface{} `json:"default"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func ServerCfg2Slice() []SCfg {
 | 
					func ServerCfg2Slice() []SCfg {
 | 
				
			||||||
@@ -169,18 +170,27 @@ func ServerCfg2Slice() []SCfg {
 | 
				
			|||||||
		field := typ.Field(i)
 | 
							field := typ.Field(i)
 | 
				
			||||||
		value := s.Field(i)
 | 
							value := s.Field(i)
 | 
				
			||||||
		tag := field.Tag.Get("json")
 | 
							tag := field.Tag.Get("json")
 | 
				
			||||||
		usage, env := getUsageEnv(tag)
 | 
							usage, env, val := getUsageEnv(tag)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		datas = append(datas, SCfg{Name: tag, Env: env, Info: usage, Data: value.Interface()})
 | 
							datas = append(datas, SCfg{Name: tag, Env: env, Info: usage, Data: value.Interface(), Val: val})
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return datas
 | 
						return datas
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func getUsageEnv(name string) (usage, env string) {
 | 
					func getUsageEnv(name string) (usage, env string, val interface{}) {
 | 
				
			||||||
	for _, v := range configs {
 | 
						for _, v := range configs {
 | 
				
			||||||
		if v.Name == name {
 | 
							if v.Name == name {
 | 
				
			||||||
			usage = v.Usage
 | 
								usage = v.Usage
 | 
				
			||||||
 | 
								if v.Typ == cfgStr {
 | 
				
			||||||
 | 
									val = v.ValStr
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								if v.Typ == cfgInt {
 | 
				
			||||||
 | 
									val = v.ValInt
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								if v.Typ == cfgBool {
 | 
				
			||||||
 | 
									val = v.ValBool
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -57,6 +57,21 @@ func execute() {
 | 
				
			|||||||
		envs[rr.Key().String()] = rr.Value().Index(0).String()
 | 
							envs[rr.Key().String()] = rr.Value().Index(0).String()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if !runSrv {
 | 
				
			||||||
 | 
							if debug {
 | 
				
			||||||
 | 
								scfgData := ServerCfg2Slice()
 | 
				
			||||||
 | 
								fmtStr := "%-18v %-23v %-20v %v\n"
 | 
				
			||||||
 | 
								fmt.Printf(fmtStr, "Name", "Env", "Value", "Info")
 | 
				
			||||||
 | 
								for _, v := range scfgData {
 | 
				
			||||||
 | 
									if v.Name == "admin_pass" || v.Name == "jwt_secret" {
 | 
				
			||||||
 | 
										v.Val = "******"
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									fmt.Printf(fmtStr, v.Name, v.Env, v.Val, v.Info)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							os.Exit(0)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 移动配置解析代码
 | 
						// 移动配置解析代码
 | 
				
			||||||
	conf := linkViper.GetString("conf")
 | 
						conf := linkViper.GetString("conf")
 | 
				
			||||||
	linkViper.SetConfigFile(conf)
 | 
						linkViper.SetConfigFile(conf)
 | 
				
			||||||
@@ -65,10 +80,6 @@ func execute() {
 | 
				
			|||||||
		// 没有配置文件,直接报错
 | 
							// 没有配置文件,直接报错
 | 
				
			||||||
		panic("config file err:" + err.Error())
 | 
							panic("config file err:" + err.Error())
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					 | 
				
			||||||
	if !runSrv {
 | 
					 | 
				
			||||||
		os.Exit(0)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func initCmd() {
 | 
					func initCmd() {
 | 
				
			||||||
@@ -112,28 +123,6 @@ func initCmd() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	cobra.OnInitialize(func() {
 | 
						cobra.OnInitialize(func() {
 | 
				
			||||||
		linkViper.AutomaticEnv()
 | 
							linkViper.AutomaticEnv()
 | 
				
			||||||
 | 
					 | 
				
			||||||
		// ver := linkViper.GetBool("version")
 | 
					 | 
				
			||||||
		// if ver {
 | 
					 | 
				
			||||||
		//	printVersion()
 | 
					 | 
				
			||||||
		//	os.Exit(0)
 | 
					 | 
				
			||||||
		// }
 | 
					 | 
				
			||||||
		//
 | 
					 | 
				
			||||||
		// return
 | 
					 | 
				
			||||||
		//
 | 
					 | 
				
			||||||
		// conf := linkViper.GetString("conf")
 | 
					 | 
				
			||||||
		// _, err := os.Stat(conf)
 | 
					 | 
				
			||||||
		// if errors.Is(err, os.ErrNotExist) {
 | 
					 | 
				
			||||||
		//	// 没有配置文件,不做处理
 | 
					 | 
				
			||||||
		//	panic("conf stat err:" + err.Error())
 | 
					 | 
				
			||||||
		// }
 | 
					 | 
				
			||||||
		//
 | 
					 | 
				
			||||||
		//
 | 
					 | 
				
			||||||
		// linkViper.SetConfigFile(conf)
 | 
					 | 
				
			||||||
		// err = linkViper.ReadInConfig()
 | 
					 | 
				
			||||||
		// if err != nil {
 | 
					 | 
				
			||||||
		//	panic("config file err:" + err.Error())
 | 
					 | 
				
			||||||
		// }
 | 
					 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -151,6 +140,8 @@ func initToolCmd() *cobra.Command {
 | 
				
			|||||||
	toolCmd.Flags().BoolVarP(&debug, "debug", "d", false, "list the config viper.Debug() info")
 | 
						toolCmd.Flags().BoolVarP(&debug, "debug", "d", false, "list the config viper.Debug() info")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	toolCmd.Run = func(cmd *cobra.Command, args []string) {
 | 
						toolCmd.Run = func(cmd *cobra.Command, args []string) {
 | 
				
			||||||
 | 
							runSrv = false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		switch {
 | 
							switch {
 | 
				
			||||||
		case rev:
 | 
							case rev:
 | 
				
			||||||
			printVersion()
 | 
								printVersion()
 | 
				
			||||||
@@ -169,7 +160,7 @@ func initToolCmd() *cobra.Command {
 | 
				
			|||||||
			pass, _ := utils.PasswordHash(passwd)
 | 
								pass, _ := utils.PasswordHash(passwd)
 | 
				
			||||||
			fmt.Printf("Passwd:%s\n", pass)
 | 
								fmt.Printf("Passwd:%s\n", pass)
 | 
				
			||||||
		case debug:
 | 
							case debug:
 | 
				
			||||||
			linkViper.Debug()
 | 
								// linkViper.Debug()
 | 
				
			||||||
		default:
 | 
							default:
 | 
				
			||||||
			fmt.Println("Using [anylink tool -h] for help")
 | 
								fmt.Println("Using [anylink tool -h] for help")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -179,6 +170,6 @@ func initToolCmd() *cobra.Command {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func printVersion() {
 | 
					func printVersion() {
 | 
				
			||||||
	fmt.Printf("%s v%s build on %s [%s, %s] BuildDate:%s commit_id(%s)\n",
 | 
						fmt.Printf("%s v%s build on %s [%s, %s] date:%s commit_id(%s)\n",
 | 
				
			||||||
		APP_NAME, APP_VER, runtime.Version(), runtime.GOOS, runtime.GOARCH, BuildDate, CommitId)
 | 
							APP_NAME, APP_VER, runtime.Version(), runtime.GOOS, runtime.GOARCH, BuildDate, CommitId)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,7 +23,7 @@ var configs = []config{
 | 
				
			|||||||
	{Typ: cfgStr, Name: "conf", Usage: "config file", ValStr: "./conf/server.toml", Short: "c"},
 | 
						{Typ: cfgStr, Name: "conf", Usage: "config file", ValStr: "./conf/server.toml", Short: "c"},
 | 
				
			||||||
	{Typ: cfgStr, Name: "profile", Usage: "profile.xml file", ValStr: "./conf/profile.xml"},
 | 
						{Typ: cfgStr, Name: "profile", Usage: "profile.xml file", ValStr: "./conf/profile.xml"},
 | 
				
			||||||
	{Typ: cfgStr, Name: "server_addr", Usage: "TCP服务监听地址(任意端口)", ValStr: ":443"},
 | 
						{Typ: cfgStr, Name: "server_addr", Usage: "TCP服务监听地址(任意端口)", ValStr: ":443"},
 | 
				
			||||||
	{Typ: cfgBool, Name: "server_dtls", Usage: "开启DTLS", ValBool: false},
 | 
						{Typ: cfgBool, Name: "server_dtls", Usage: "开启DTLS", ValBool: true},
 | 
				
			||||||
	{Typ: cfgStr, Name: "server_dtls_addr", Usage: "DTLS监听地址(任意端口)", ValStr: ":443"},
 | 
						{Typ: cfgStr, Name: "server_dtls_addr", Usage: "DTLS监听地址(任意端口)", ValStr: ":443"},
 | 
				
			||||||
	{Typ: cfgStr, Name: "admin_addr", Usage: "后台服务监听地址", ValStr: ":8800"},
 | 
						{Typ: cfgStr, Name: "admin_addr", Usage: "后台服务监听地址", ValStr: ":8800"},
 | 
				
			||||||
	{Typ: cfgBool, Name: "proxy_protocol", Usage: "TCP代理协议", ValBool: false},
 | 
						{Typ: cfgBool, Name: "proxy_protocol", Usage: "TCP代理协议", ValBool: false},
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -31,8 +31,8 @@ jwt_secret = "abcdef.0123456789.abcdef"
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#TCP服务监听地址(任意端口)
 | 
					#TCP服务监听地址(任意端口)
 | 
				
			||||||
server_addr = ":443"
 | 
					server_addr = ":443"
 | 
				
			||||||
#开启 DTLS, 默认关闭
 | 
					#开启 DTLS
 | 
				
			||||||
server_dtls = false
 | 
					server_dtls = true
 | 
				
			||||||
#UDP监听地址(任意端口)
 | 
					#UDP监听地址(任意端口)
 | 
				
			||||||
server_dtls_addr = ":443"
 | 
					server_dtls_addr = ":443"
 | 
				
			||||||
#后台服务监听地址
 | 
					#后台服务监听地址
 | 
				
			||||||
@@ -40,6 +40,7 @@ admin_addr = ":8800"
 | 
				
			|||||||
#开启tcp proxy protocol协议
 | 
					#开启tcp proxy protocol协议
 | 
				
			||||||
proxy_protocol = false
 | 
					proxy_protocol = false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#虚拟网络类型[tun macvtap tap]
 | 
				
			||||||
link_mode = "tun"
 | 
					link_mode = "tun"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#客户端分配的ip地址池
 | 
					#客户端分配的ip地址池
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -25,10 +25,15 @@ jwt_secret = "abcdef.0123456789.abcdef"
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#TCP服务监听地址(任意端口)
 | 
					#TCP服务监听地址(任意端口)
 | 
				
			||||||
server_addr = ":443"
 | 
					server_addr = ":443"
 | 
				
			||||||
 | 
					#开启 DTLS
 | 
				
			||||||
 | 
					server_dtls = true
 | 
				
			||||||
 | 
					#UDP监听地址(任意端口)
 | 
				
			||||||
 | 
					server_dtls_addr = ":443"
 | 
				
			||||||
#后台服务监听地址
 | 
					#后台服务监听地址
 | 
				
			||||||
admin_addr = ":8800"
 | 
					admin_addr = ":8800"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#虚拟网络类型[tun macvtap]
 | 
				
			||||||
 | 
					link_mode = "tun"
 | 
				
			||||||
#客户端分配的ip地址池
 | 
					#客户端分配的ip地址池
 | 
				
			||||||
ipv4_master = "eth0"
 | 
					ipv4_master = "eth0"
 | 
				
			||||||
ipv4_cidr = "192.168.90.0/24"
 | 
					ipv4_cidr = "192.168.90.0/24"
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,7 +4,6 @@ import (
 | 
				
			|||||||
	"crypto/tls"
 | 
						"crypto/tls"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"io"
 | 
						"io"
 | 
				
			||||||
	"log"
 | 
					 | 
				
			||||||
	"net"
 | 
						"net"
 | 
				
			||||||
	"net/http"
 | 
						"net/http"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
@@ -66,7 +65,7 @@ func startTls() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	ln, err = net.Listen("tcp", addr)
 | 
						ln, err = net.Listen("tcp", addr)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		log.Fatal(err)
 | 
							base.Fatal(err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	defer ln.Close()
 | 
						defer ln.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user