Article directory
-
Installation and use of Gitea under Linux
Installation and use of Gitea under Linux
1. Local source code installation
1. Prepare the environment
Compile and install through source code, which needs to be installed in advance.
- go 1.19 or above
- node 16 or above, and install npm
- make: Compilation tool, generally comes with the system.
- gcc: C compilation tool, generally comes with the system.
Among them, please refer to my other blog post for node and npm installation:
https://blog.csdn.net/Acegem/article/details/129675519?spm =1001.2014.3001.5502 - mysql: A new library needs to be created inside. The library name is:
gitea
2. Download source code
Downloadhttps://github.com/go-gitea/giteaGet itgitea-main.zip
.
3. Compile
After unzipgitea-main.zip
, prepare to compile.
Compile tags options:
- bindata: bindata: This compilation option will package all the external resources required to run Gitea into an executable file, so deployment will be very simple because no other files will be needed except the executable program.
- sqlite sqlite_unlock_notify: This compilation option will enable support for SQLite3 databases. It is recommended to use this mode only when used by a small number of people.
- pam: This compile option will enable PAM (Linux Pluggable Authentication Modules) authentication. You need to enable this option if you use this authentication mode.
The following is the compilation method I use:
cd gitea-main
# 编译
TAGS="bindata" make build
# 交叉编译。Go 编译器支持交叉编译到不同的目标架构。
# 交叉构建适用于 Linux ARM64 的 Gitea
GOOS=linux GOARCH=arm64 TAGS="bindata" make build
# 交叉构建适用于 Linux ARM64 的 Gitea,并且带上 Gitea 发行版采用的编译选项
CC=aarch64-unknown-linux-gnu-gcc GOOS=linux GOARCH=arm64 TAGS="bindata" make build
Attachment:
List of target architectures supported by Go:
$GOOS | $GOARCH |
---|---|
linux | 386 |
linux | amd64 |
linux | arm |
linux | arm64 |
linux | loong64 |
linux | mips |
linux | mipsle |
linux | mips64 |
linux | mips64le |
linux | ppc64 |
linux | ppc64le |
linux | riscv64 |
linux | s390x |
windows | 386 |
windows | amd64 |
windows | arm |
windows | arm64 |
android | 386 |
android | amd64 |
android | arm |
android | arm64 |
ios | arm64 |
darwin | amd64 |
darwin | arm64 |
freebsd | 386 |
freebsd | amd64 |
freebsd | arm |
netbsd | 386 |
netbsd | amd64 |
netbsd | arm |
openbsd | 386 |
openbsd | amd64 |
openbsd | arm |
openbsd | arm64 |
plan9 | 386 |
plan9 | amd64 |
plan9 | arm |
aix | ppc64 |
dragonfly | amd64 |
let us know | amd64 |
js | wasm |
solaris | amd64 |
After compilation, a gitea binary file will be generated.
4. Start
enter
./gitea web
Start and run
Open the browser and visithttp://localhost:3000
Click "Register" in the upper right corner to register an account, but site configuration will be required for first time use, as follows.
5. Site configuration
After clicking "Install Now", you can register an account and log in to use it.
Attachment: In addition, you can also directly download the gitea binary package locally for binary installation.
2. Local source code + docker mysql installation
1. Source code compilation
You can compile the source code first, then connect to mysql, and compile the same as above.
2. Create gitea_db container
# 拉取mysql8.0镜像
docker pull mysql:8.0
# 查看镜像
docker images
# 创建容器并后台运行。主机通过3307端口对应着mysql容器的3306端口
docker run -td --name gitea_db --restart=always -p 3307:3306 -e MYSQL_ROOT_PASSWORD=root mysql:8.0
Enter the container to create the gitea library
# 进入容器
docker exec -it gitea_db bash
# 进入容器后:
# 登入mysql
mysql -uroot -p
# 创建新库gitea
create database gitea;
3. Startup and configuration
# 启动
./gitea
Browser accesslocalhost:3000
, configuration will be performed for the first time:
3. docker source code + docker mysql installation
Create two containers:
- gitea_web: stores gitea projects
- gitea_db: stores mysql
(In fact, you can also create a container and put both gitea and mysql in one container, but the microservice idea is used here.)< /span>
1. Create gitea_db container
# 拉取mysql8.0镜像
docker pull mysql:8.0
# 查看镜像
docker images
# 创建容器并后台运行。主机通过3307端口对应着mysql容器的3306端口
docker run -td --name mysql_db --restart=always -p 3307:3306 -e MYSQL_ROOT_PASSWORD=root mysql:8.0
2. Create gitea_web container
Take the Ubuntu20.04 environment as an example.
docker pull ubuntu:20.04
# 创建容器。主机通过15000端口对应着gitea_web容器的3000端口,容器里挂载个U盘目录/volumes_usb对应着主机目录/home/user/mydocker/mnt/
docker create -it --name gitea_web -p 15000:3000 -v /home/user/mydocker/mnt/:/volumes_usb ubuntu:20.04
docker start gitea_web
# 确保 gitea_web 和 gitea_db 容器在运行
docker ps
(配置网桥)
# 自建一个网桥customize_bridge,让gitea_web 和 gitea_db两个容器连接起来,即在同一网段,能通信
docker network create -d bridge customize_bridge
docker network connect customize_bridge gitea_web
docker network connect customize_bridge gitea_db
Enter the container and install some basic tools online
# 进入容器
docker exec -it gitea_web bash
# 进入容器后:
apt update
apt install make
apt install gcc
apt install vim
cd /volumes_usb
Refer to the beginning of this article一、源码安装
, and then place the prepared gitea source code, node, and npm offline files in the host/home/user/mydocker/mnt/
directory so that the container can Find and use it through the /volumes_usb
directory, and the next operation process is the same as the beginning of this article 一、源码安装
.
At this time, you can customize the CPU and system environment during compilation.
After successful compilation, a gitea binary file will be generated, but the gitea binary file does not support execution with root, so a new user needs to be created.
# 进入容器
docker exec -it gitea_web bash
# 进入容器后:
# 创建新用户user
adduser user
# 更换gitea项目文件的所有者,以便能操作
chown user:user -R /路径/gitea-main
# 切换新建的user用户
su user
cd gitea-main
./gitea
3. Access
Host accesslocalhost:15000
, the final site configuration is as follows:
4. Docker-compose installation
1. Prepare docker-compose.yml
Create a new filedocker-compose.yml
in the custom directory. For example, create a new file under /home/user/mydocker/docker_gitea
:
docker-compose.yml
version: "2"
networks:
gitea:
external: false
services:
server:
container_name: gitea_server
image: gitea/gitea:latest
environment:
- USER_UID=1000
- USER_GID=1000
restart: always
networks:
- gitea
volumes:
- ./data:/data
ports:
- "15000:3000"
- "10022:22"
depends_on:
- db
db:
container_name: gitea_db
image: mysql:8.0
restart: always
environment:
- MYSQL_ROOT_PASSWORD=gitea
- MYSQL_USER=gitea
- MYSQL_PASSWORD=gitea
- MYSQL_DATABASE=gitea
networks:
- gitea
volumes:
- ./mysql:/var/lib/mysql
This function is to create two containers: gitea_server, gitea_db
- gitea_server: stores gitea projects and applications. The gitea web port in the container is 3000, and the access port corresponding to the external host is 15000.
- gitea_db: live mysql
mysql information
user | password |
---|---|
root | guide |
guide | guide |
mysql source: gitea
2. Download
cd /home/user/mydocker/docker_gitea/
docker-compose up # 或 docker-compose up -d
After is downloaded, the and folders will be automatically generated in the /home/user/mydocker/docker_gitea/
directory. data
mysql
3. Start
cd /home/user/mydocker/docker_gitea/
# 启动
docker-compose start
####### 或者 #######
docker start gitea_server
docker start gitea_db
# 停止
docker-compose stop
####### 或者 #######
docker stop gitea_server
docker stop gitea_db
After startup, open the browser and visithttp://localhost:15000
Click "Register" in the upper right corner to register an account, but the site will be configured for the first time, as follows.
4. Site configuration
After clicking "Install Now", you can register an account and log in to use it.
5. Migration (only applicable to the same CPU architecture and the same system)
Because this method docker-compose.yml installs the gitea binary file automatically compiled according to the current environment, so the migration is only applicable to the same CPU architecture and the same system. If you want to apply it to other environments, you need to enter compilation parameters and compile manually. Refer to Section 3 below
What about migrating to other servers?
# 当前服务器,保存
docker commit gitea_server gitea:v1
docker commit gitea_db gitea_db:v1
docker save -o ./gitea.tgz gitea:v1
docker save -o ./gitea_db.tgz gitea_db:v1
# 另一台服务器,导入
docker load -i gitea.tgz
docker load -i gitea_db.tgz
docker create -it --name gitea_db mysql:8.0
attached
For more functions, please refer to the official manual:https://docs.gitea.io/zh-cn/install-from-source/