码迷,mamicode.com
首页 > 其他好文 > 详细

Centos 7下Giteae二进制安装完整教程-适用于生成环境

时间:2020-09-17 12:03:13      阅读:3      评论:0      收藏:0      [点我收藏+]

标签:cte   err   cos   var   service   arc   dir   问题   ant   

一: 安装最新版本的Git

需要下载git的最新源码包,然后进行编译安装

yum install gcc gcc-c++ openssl-devel zlib-devel
cd /usr/local/src
tar zxvf git-2.28.0.tar.gz
cd git-2.28.0
./configure --prefix=/usr/local/git
make && make install

#为了解决环境变量的问题导致gitea无法启动,我们这里暴力解决
ln -s /usr/local/git/bin/git /usr/bin/git
ln -s /usr/local/git/bin/gitk /usr/bin/gitk
ln -s /usr/local/git/bin/git-cvsserver /usr/bin/git-cvsserver
ln -s /usr/local/git/bin/git-receive-pack /usr/bin/git-receive-pack
ln -s /usr/local/git/bin/git-shell /usr/bin/git-shell
ln -s /usr/local/git/bin/git-upload-archive /usr/bin/git-upload-archive
ln -s /usr/local/git/bin/git-upload-pack /usr/bin/git-upload-pack

二: 创建git账户

这里我们可以参考官方文档,百度搜出来的帖子大多都有问题

#https://docs.gitea.io/en-us/install-from-binary/
#不要看中文的,很久都不更新了

adduser    --system    --shell /bin/bash    --gecos Git Version Control    --group    --disabled-password    --home /home/git    git

三: 创建相关目录

mkdir -p /usr/local/gitea/{custom,data,log}
chown -R git:git /usr/local/gitea/

四: 安装MySQL并创建数据库

安装MySQL可参考本人博客的其他帖子,

#官方文档 https://docs.gitea.io/en-us/database-prep/


CREATE DATABASE giteadb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER gitea@192.0.2.10 IDENTIFIED BY gitea;
GRANT ALL PRIVILEGES ON giteadb.* TO gitea@192.0.2.10;
FLUSH PRIVILEGES;

进行验证

mysql -u gitea -h 203.0.113.3 -p giteadb

五:安装并生成配置文件

这里我们可以切换到git用户,手动运行,然后执行安装

USER=git HOME=/home/git GITEA_WORK_DIR=/usr/local/gitea /usr/local/gitea/gitea web --config /usr/local/gitea/custom/conf/app.ini

这里会生成配置文件

六:安装nginx进行反向代理

yum install nginx

主配置文件如下:

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  ‘$remote_addr - $remote_user [$time_local] "$request" ‘
                      ‘$status $body_bytes_sent "$http_referer" ‘
                      ‘"$http_user_agent" "$http_x_forwarded_for"‘;

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;
}

gitea的配置文件如下:

upstream gitea {
        server 127.0.0.1:3000;
}

server {
    listen 80;
    server_name gitea.example.com;
    client_max_body_size 100M;
    charset utf-8;
    proxy_redirect     off;
    proxy_set_header   Host             $host:$server_port;
    proxy_set_header   X-Real-IP        $remote_addr;
    proxy_set_header X-Forwarded-Host $host:$server_port;
    proxy_set_header X-Forwarded-Server $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_next_upstream error timeout invalid_header http_502 http_503 http_504;
    proxy_ignore_client_abort on;
    proxy_read_timeout  180;
    proxy_buffering on;
    proxy_buffer_size 8k;



    location / {
       proxy_pass http://gitea;
       proxy_redirect     default;
       proxy_set_header   Host             $host:$server_port;
       proxy_set_header   X-Real-IP        $remote_addr;
       proxy_set_header X-Forwarded-Host $host:$server_port;
       proxy_set_header X-Forwarded-Server $host;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $scheme;
    }
}

添加nginx到开机启动项

systemctl enable nginx && systemctl start nginx

七:web界面访问安装

此时打开 gitea.example.com 进行安装

http://gitea.example.com/install 

然后填写配置信息,

这里注意的是我们的SSH端口选择的是2202,因为22端口被SSHD服务本身占用,配置数据库以及管理员账户即可点击下一步即可。

如果想要重新安装,需要清除/usr/local/gitea下的所有数据

八:定义开机启动脚本,这里我们可以将git用户的进程关掉,定义systemd开机启动

脚本这里依然采用的是官方提供的

[root@openldap gitea]# cat /usr/lib/systemd/system/gitea.service 
[Unit]
Description=Gitea (Git with a cup of tea)
#After=syslog.target
After=network.target

[Service]
RestartSec=2s
Type=simple
User=git
Group=git
WorkingDirectory=/usr/local/gitea/
ExecStart=/usr/local/gitea/gitea web --config /usr/local/gitea/custom/conf/app.ini
Restart=always
Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/usr/local/gitea
#CapabilityBoundingSet=CAP_NET_BIND_SERVICE
#AmbientCapabilities=CAP_NET_BIND_SERVICE
[Install]
WantedBy=multi-user.target

官方连接:https://github.com/go-gitea/gitea/blob/master/contrib/systemd/gitea.service

然后使用该脚本进行启动,此时发现SSH协议依然无法使用。 这里我们需要修改配置文件

在[server] 段中添加

START_SSH_SERVER = true

然后重启gitea服务即可

systemctl enable gitea && systemctl start gitea

 

Centos 7下Giteae二进制安装完整教程-适用于生成环境

标签:cte   err   cos   var   service   arc   dir   问题   ant   

原文地址:https://www.cnblogs.com/skymyyang/p/13606587.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有 京ICP备13008772号-2
迷上了代码!