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