转自http://www.cnblogs.com/jim-hwg/p/4754880.html 官网环境要求
参见:https://github.com/gitlabhq/gitlabhq
GitLab is a Ruby on Rails application that runs on the following software:
Ubuntu/Debian/CentOS/RHEL
Ruby (MRI) 2.1
Git 1.7.10+
Redis 2.0+
MySQL or PostgreSQL
For more information please see the architecture documentation.
##########################################
关闭防火墙,关闭SELinux 一、安装采用环境
CREATE USER 'git'@'localhost'>#替换$password设定自己的密码
CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
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
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:
九、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用户
sudo -u git -H editor config/gitlab.yml; # Enable keep_time in the backup section to automatically delete old backups
keep_time参数默认是604800(单位是秒),因此会保留最近7天内的备份
sudo -u git crontab -e # Edit the crontab for the git user
将如下内容添加到文件末尾
# Create a full backup of the GitLab repositories and SQL database every day at 2am
0 2 * * * cd /home/git/gitlab && PATH=/usr/local/bin:/usr/bin:/bin bundle exec rake gitlab:backup:create RAILS_ENV=production CRON=1
每天凌晨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.
重新启动
sudo service gitlab start;
sudo service nginx restart;