自建nginx部署gitlab和openproject

最近看到openproject软件挺好用的,想试试看。

服务器已经安装了gitlab,80/443端口,域名访问。

想要搞两个子域名分别访问个itlab和openproject。

要用代理软件。

gitlab自带了nginx,看了一些前人写的blog,基本都是安装一个nginx,把gitlab自带的nginx禁用掉,gitlab和openproject都接到自建的nginx,通过域名转发到两个系统里面,初步确定这个方案,我来试试看。

1、先备份gitlab中的数据。

gitlab-rake gitlab:backup:create

2020-11-12 13:38:39 +0800 -- done
2020-11-12 13:38:39 +0800 -- Dumping uploads ...
2020-11-12 13:38:39 +0800 -- done
2020-11-12 13:38:39 +0800 -- Dumping builds ...
2020-11-12 13:38:39 +0800 -- done
2020-11-12 13:38:39 +0800 -- Dumping artifacts ...
2020-11-12 13:38:39 +0800 -- done
2020-11-12 13:38:39 +0800 -- Dumping pages ...
2020-11-12 13:38:39 +0800 -- done
2020-11-12 13:38:39 +0800 -- Dumping lfs objects ...
2020-11-12 13:38:39 +0800 -- done
2020-11-12 13:38:39 +0800 -- Dumping container registry images ...
2020-11-12 13:38:39 +0800 -- [DISABLED]
Creating backup archive: 1605159519_2020_11_12_13.5.1_gitlab_backup.tar ... done
Uploading backup archive to remote storage  ... skipped
Deleting tmp directories ... done
done
done
done
done
done
done
done
Deleting old backups ... skipping
Warning: Your gitlab.rb and gitlab-secrets.json files contain sensitive data
and are not included in this backup. You will need these files to restore a backup.
Please back them up manually.
Backup task is done.

备份完成后,提示两个敏感数据文件需要手动备份,一个gitlab-secrets.json,一个gitlab.rb,在目录/etc/gitlab/下,手动备份到其他地方。

gitlab-secrets.json文件存储的是密钥

gitlab.rb是gitlab的配置数据

同时,参照其他网友的blog,也备份了

  • /etc/gitlab/gitlab.rb
  • /var/opt/gitlab/nginx/conf 下的配置文件

由于我没有配置邮件功能,所以不存在文件/etc/postfix/main.cfpostfix

将以上配置文件汇总到一个目录下。

关闭gitlab

gitlab-ctl stop
ok: down: alertmanager: 0s, normally up
ok: down: gitaly: 0s, normally up
ok: down: gitlab-exporter: 1s, normally up
ok: down: gitlab-workhorse: 0s, normally up
ok: down: grafana: 1s, normally up
ok: down: logrotate: 0s, normally up
ok: down: nginx: 1s, normally up
ok: down: node-exporter: 0s, normally up
ok: down: postgres-exporter: 0s, normally up
ok: down: postgresql: 1s, normally up
ok: down: prometheus: 0s, normally up
ok: down: puma: 1s, normally up
ok: down: redis: 0s, normally up
ok: down: redis-exporter: 0s, normally up
ok: down: sidekiq: 0s, normally up

 

2、安装nginx。

参考官网nginx.org的说明,安装。

Install the prerequisites:

sudo yum install yum-utils

To set up the yum repository, create the file named /etc/yum.repos.d/nginx.repo with the following contents:

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

By default, the repository for stable nginx packages is used. If you would like to use mainline nginx packages, run the following command:

sudo yum-config-manager --enable nginx-mainline

To install nginx, run the following command:

sudo yum install nginx

When prompted to accept the GPG key, verify that the fingerprint matches 573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62, and if so, accept it.

过程中两次yes完成安装。

systemctl start nginx 启动

systemctl status nginx 查看运行状态

在浏览器输入服务器ip,出现了熟悉的Welcom to nginx!

 

3、将gitlab切换到自建nginx。

修改gitlab配置文件gitlab.rb

# 添加nginx用户
web_server['external_users'] = ['nginx','gitlab-www']
web_server['username'] = 'nginx'
web_server['group'] = 'nginx'
# 关闭gitlab的nginx
nginx['enable'] = false

输入gitlab-ctl reconfigure重新配置gitlab

将gitlab的配置文件/var/opt/gitlab/nginx/conf/gitlab-http.conf文件拷贝到 /etc/nginx/conf.d/目录下,添加ssl文件。

将gitlab的nginx 的配置文件,/var/opt/gitlab/nginx/conf/nginx.conf 拷贝到 /etc/nginx/,修改一下日志文件的路径到想要的地方,修改gitlab-http.conf文件的include路径,这样用gitlab生成的nginx配置文件来配置我们自建的nginx。

输入指令 nginx -t 测试配置文件

输入指令 nginx -s reload,重新加载配置文件

输入指令 gitlab-ctl start 启动gitlab

配置完成,在浏览器输入地址,见到了久违的gitlab登录页面。

 

4、配置期间的问题总结

  1. 我的gitlab开始是用了自带nginx,而且ssl等都配置好了,所以gitlab/nginx/下的配置文件比较完整,如果gitlab直接在安装后,第一次配置就没有使用自带nginx,不确定是否可行。
  2. nginx 没有带nginx-module-vts模块,所以原来配置中关于这部分的配置我全部删掉了。
  3. nginx启动时出现过启动超时无法运行,提示high performance web server错误,将配置文件中的 daemon off; 一句去掉即可,还没时间去搞明白是为什么。
  4. 期间尝试用gitlab自带nginx监听本地8088端口,自己的nginx从80转发代理到8088,一直报错没搞成功。
  5. 配置完成启动后,浏览器访问gitlab会报502错误,重新配置和启动gitlab,nginx解决了问题,原因没找到,可能是gitlab内部部分权限的问题。
  6. 最开始对gitlab数据的备份没什么卵用。

5、添加一个虚拟主机

准备好域名 iot.xxx,配置dns解析,购买ssl证书,下载证书文件。

在/etc/nginx/nginx.conf文件中添加 include /etc/nginx/conf.d/default.conf,我用nginx默认生成的配置文件 default.conf来搭建一个虚拟主机,修改default.conf文件

server{
    listen *:80;
    server_name iot.xxx;
    
    access_log xxxx;
    error_log xxx;

    rewrite ^ https://$http_host$request_uri? permenent;
}
server{
    listen *:443 ssl;
    server_name iot.xxx;
    
    access_log xxxx;
    error_log xxx;

    location /{
        root /usr/share/nginx/html;
        index index.html;
    }

    ssl_certificate xxx;
    ssl_certificate_key xxx;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_prefer_server_ciphers on;
}

重新加载配置 nginx -s reload

在浏览器输入iot.xxx,成功显示nginx的欢迎页面。

6、安装openproject。

待完善。

7、将openproject链接到自检nginx。

待完善。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要将外部的 NginxGitLab 集成,需要进行以下步骤: 1. 安装 GitLab 并确保其运行正常。 2. 安装 Nginx 并确保其运行正常。 3. 配置 GitLab 中的 Nginx。 4. 配置 Nginx 中的 GitLab。 以下是每个步骤的详细说明: 1. 安装 GitLab 并确保其运行正常。 安装 GitLab 的过程因为环境不同而有所差异,具体可以参考 GitLab 官方文档进行配置。 2. 安装 Nginx 并确保其运行正常。 安装 Nginx 的过程因为环境不同而有所差异,具体可以参考 Nginx 官方文档进行配置。 3. 配置 GitLab 中的 Nginx。 打开 GitLab 的配置文件 `/etc/gitlab/gitlab.rb`,并添加以下代码: ``` nginx['enable'] = true nginx['client_max_body_size'] = '250m' nginx['redirect_http_to_https'] = true nginx['redirect_http_to_https_port'] = 80 nginx['ssl_certificate'] = "/etc/gitlab/ssl/gitlab.crt" nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/gitlab.key" ``` 这样就可以启用 GitLab 中的 Nginx,并设置一些基本的参数。 4. 配置 Nginx 中的 GitLab。 打开 Nginx 的配置文件 `/etc/nginx/nginx.conf`,并添加以下代码: ``` upstream gitlab { server 127.0.0.1:8080; } server { listen 80; server_name gitlab.example.com; return 301 https://$server_name$request_uri; } server { listen 443 ssl; server_name gitlab.example.com; ssl_certificate /etc/nginx/ssl/gitlab.crt; ssl_certificate_key /etc/nginx/ssl/gitlab.key; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers HIGH:!aNULL:!MD5; location / { proxy_pass http://gitlab; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; } } ``` 这样就可以将外部的 NginxGitLab 集成起来,外部用户就可以通过 Nginx 访问 GitLab 了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值