vim config/gitlab.yml
host:
10.149.153.81
port:
8049
email_from: gitlab@example.com
email_enabled:
false
default_theme:
1
mkdir /home/git/gitlab-satellites
chmod 750 /home/git/gitlab-satellites
cp config/unicorn.rb.example config/unicorn.rb
配置config/unicorn.rb,配置Ruby提供的服务端口,IP
# Find number of cores
#优化系统参数
/etc/security/limits.conf
# Enable cluster mode
if you expect to have a high load instance
# Ex. change amount of workers to
3 for 2GB RAM server
# Set the number of workers to at least the number of cores
vim config
/unicorn.rb
worker_processes
3 # Set the number of workers to at least the number of core listen "127.0.0.1:8081", :tcp_nopush => true #注意端口,避免冲突
cp config/database.yml.mysql config/database.yml
# MySQL and remote PostgreSQL only:
# Update username
/password in config/database.yml.
# You only need to adapt the production settings (first part).
# If you followed the database guide
then please do as follows:
# Change
'secure password' with the value you have given to $password
# You can keep the
double quotes around the password
vim config
/database.yml
修改为正确的用户名和密码
分别修改git用户和root用户
chmod o-rwx config/database.yml
4.Install Gems Note: As of bundler 1.5.2, you can invoke bundle install -jN
(where N the number of your processor cores) and enjoy the parallel gems installation with measurable
difference in completion time (~60% faster). Check the number of your cores with nproc.
For more information check this post.
First make sure you have bundler >= 1.5.2 (run bundle -v) as it addresses some issues
that were fixed in 1.5.2.
cd /home/git/gitlab
# Or
for MySQL (note, the option says "without ... postgres")
修改为淘宝的ruby源
vim Gemfile
修改为
source
'https://ruby.taobao.org/'
bundle
install --deployment --without development test postgres aws
这一步的时间会等很久
5.Install GitLab shell
GitLab Shell is an SSH access and repository management software developed specially for GitLab.
cd /home/git/gitlab bundle exec rake gitlab:shell:install[v2.6.2] REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production
报错:ExecJS::RuntimeUnavailable: Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.
处理:切换到root用户
yum -y install nodejs
配置/home/git/gitlab/Gemfile
vim /home/git/gitlab/Gemfile
#末尾添加
gem
'execjs'
gem
'therubyracer'
cd /home/git/gitlab bundle install --no-deployment
验证:
bundle show execjs
bundle show therubyracer
切回git用户,再次执行
cd /home/git/gitlab bundle exec rake gitlab:shell:install[v2.6.2] REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production
# By default, the gitlab-shell config is generated from your main GitLab config.
# You can review (and modify) the gitlab
-shell config as follows:
vim
/home/git/gitlab-shell/config.yml
6.Initialize Database and Activate Advanced Features
cd /home/git/gitlab/
bundle exec rake gitlab:setup RAILS_ENV
=production
Type yes to create the database.
When done you see Administrator account created:. Note: You can set the Administrator password by supplying it in environmental variable GITLAB_ROOT_PASSWORD, eg.:
如果要修改gitlab管理员的密码,则执行这一句,否则执行上一句
七、Configure the web server
Use either Nginx or Apache, not both. Official installation guide recommends nginx.
Nginx
You will need a new version of nginx otherwise you might encounter an issue like this.
To do so, follow the instructions provided by the nginx wiki and then install nginx with:
最后加上--no-check-certificate不检查证书,这里不使用SSL
Edit /etc/nginx/conf.d/gitlab.conf and replace git.example.com with your FQDN. Make sure to read the comments in order to properly set up SSL.
vim /etc/nginx/conf.d/gitlab.conf
去掉listen后面的default_server,修改为正确的端口号
去掉 listen [::]:
修改server_name 为本机的IP地址
修改client_max_body_size 256m;
否则当推送较多数据到 gitlab 上时,会由于数据过大,而出现错误
fatal: The remote end hung up unexpectedly fatal: The remote end hung up unexpectedly error: RPC failed; result
=22, HTTP code = 413
Add nginx user to git group:
usermod -a -G git nginx
Finally start nginx with:
service nginx start
Test Configuration
Validate your gitlab or gitlab-ssl Nginx config file with the following command:
nginx -t
八、Double-check Application Status
To make sure you didn't miss anything run a more thorough check with:
su - git
cd
/home/git/gitlab
bundle exec rake gitlab:check RAILS_ENV
=production
九、Initial Login
Visit YOUR_SERVER in your web browser for your first GitLab login.
The setup has created an admin account for you. You can use it to log in:
root
5iveL
!fe
#####################以上即完成了Gitlab的搭建################################ 十、后期维护
1.Upgrade GitLab Shell
GitLab Shell might be outdated, running the commands below ensures you're using a compatible version:
2.Upgrade GitLab
One line upgrade command
You've read through the entire guide and probably already did all the steps one by one.
Here is a one line command with step 1 to 5 for the next time you upgrade:
切换到git用户
每天凌晨2点自动备份
The CRON=1 environment setting tells the backup script to suppress all progress output if there are no errors. This is recommended to reduce cron spam.
重新启动