CentOS7下源码方式安装gitlab
环境描述
操作系统: centos7
redis: >=2.8
mysql >=5.5.14
git >=2.7.4
架构设计
一台gitlab服务器 gitlab-master
一台gitlab数据备份 gitlab-backup
一台数据库主库 data-master
一台数据库从库 data-slave
升级yum源与安装依赖 ++所有的机器都需要的安装步骤++
安装mysql+redis ++数据库服务器需要的安装步骤++
data-master
data-slave
安装mysql+redis
升级yum源与安装依赖
yum -y update
yum -y groupinstall "Development Tools"
yum install -y cmake python-docutils libarchive python-pillow libwebp zlib zlib-devel libyaml libyaml-devel openssl-devel openssl libffi libffi-devel curl curl-devel openssh-server libxml2 libxml2-devel libxslt libxslt-devel libicu libicu-devel logrotate python-docutils perl-devel vim
reboot
++所有的机器都需要的安装步骤++
安装mysql+redis
安装数据库服务器.安装gitlab会用到.
也可以把所有的软件都安装到一台机器.
备份的时候可以把备份包上传到其他服务器上.
因为我们把mysql与redis分开分别安装到data-master
与data-slave
上
两台安装步骤一模一样
安装redis
rpm -i https://mirrors.tuna.tsinghua.edu.cn/epel//epel-release-latest-7.noarch.rpm
sudo yum install redis
systemctl enable redis
systemctl start redis
安装完后
需要将配置文件/etc/redis.conf
bind 127.0.0.1注释掉或者改成gitlab的ip地址
安装mysql
rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
yum install mysql-community-server mysql-community-client
systemctl enable mysqld
systemctl start mysqld
创建gitlab需要的表结构
CREATE USER 'git'@'%' IDENTIFIED BY 'git';
CREATE USER 'git'@'localhost' IDENTIFIED BY 'git';
CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, CREATE TEMPORARY TABLES, DROP, INDEX, ALTER, LOCK TABLES, REFERENCES ON `gitlabhq_production`.* TO 'git'@'%';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, CREATE TEMPORARY TABLES, DROP, INDEX, ALTER, LOCK TABLES, REFERENCES ON `gitlabhq_production`.* TO 'git'@'localhost';
创建完成可以gitlab服务器上
在命令行中用git账号访问mysql数据库测试是否可用
++数据库服务器需要的安装步骤++
- - -
安装mysql依赖包
rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
yum install mysql-community-client mysql-community-devel
安装nodejs
rpm -i https://mirrors.tuna.tsinghua.edu.cn/epel//epel-release-latest-7.noarch.rpm
yum -y install nodejs
安装git
yum install asciidoc xmlto texinfo docbook2X perl-devel
cd /usr/bin
ln -s db2x_docbook2texi docbook2x-texi
cd /tmp
curl --remote-name --progress https://www.kernel.org/pub/software/scm/git/git-2.7.4.tar.gz
tar -xzf git-2.7.4.tar.gz
cd git-2.7.4/
./configure --with-curl=/usr/include/curl
make prefix=/usr install install-doc install-html install-info
make install
安装邮件服务器
yum install postfix
systemctl enable postfix
systemctl start postfix
安装ruby2.3
mkdir /tmp/ruby && cd /tmp/ruby
curl --remote-name --progress https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.1.tar.gz
tar xzf ruby-2.3.1.tar.gz
cd ruby-2.3.1
./configure --disable-install-rdoc
make && make install
设置环境变量
vim /etc/bashrc
最后一行添加
export PATH="$PATH:/usr/local/bin"
关闭selinux
vim /etc/sysconfig/selinux
最后重启机器
reboot
安装 Bundler Gem:
gem install bundler --no-ri --no-rdoc
安装go语言
mkdir /tmp/go && cd /tmp/go
curl --remote-name --progress https://storage.googleapis.com/golang/go1.5.3.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.5.3.linux-amd64.tar.gz
ln -sf /usr/local/go/bin/{go,godoc,gofmt} /usr/bin
添加git账号
adduser -s /bin/false -m -d /home/git git
下载gitlab源码包
cd /home/git/gitlab
8-9目前可以汉化的最高版本
git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 8-9-stable gitlab
配置gitlab
chown -R git:git /home/git/gitlab/
cd /home/git/gitlab
切换到git账号
sudo su git
生成配置文件
cp config/gitlab.yml.example config/gitlab.yml
生成secret文件
cp config/secrets.yml.example config/secrets.yml
chmod 0600 config/secrets.yml
chown -R git log/
chown -R git tmp/
chmod -R u+rwX,go-w log/
chmod -R u+rwX tmp/
chmod -R u+rwX tmp/pids/
chmod -R u+rwX tmp/sockets/
mkdir public/uploads/
chmod 0700 public/uploads
chmod -R u+rwX builds/
生成unicorn文件
cp config/unicorn.rb.example config/unicorn.rb
cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
git config --global core.autocrlf input
git config --global gc.auto 0
git config --global repack.writeBitmaps true
cp config/resque.yml.example config/resque.yml
更改redis链接地址
vim config/resque.yml
production: redis://172.16.24.127:6379
连接mysql 取消注释host 更改password为git
cp config/database.yml.mysql config/database.yml
vim config/database.yml
安装Gems
bundle config mirror.https://rubygems.org https://gems.ruby-china.org
bundle install --deployment --without development test postgres aws kerberos -V
安装GitLab Shell
bundle exec rake gitlab:shell:install REDIS_URL=redis://redis的ip地址:端口 RAILS_ENV=production SKIP_STORAGE_VALIDATION=true
确认一下redis地址正确性
vim /home/git/gitlab-shell/config.yml
安装gitlab-workhorse
cd /home/git
git clone https://gitlab.com/gitlab-org/gitlab-workhorse.git
cd gitlab-workhorse
git checkout v0.8.4
make
初始化数据库与高级功能
只需在git-master服务器上执行一次 gitlab-backup无需再次执行该命令.
cd /home/git/gitlab
bundle exec rake gitlab:setup RAILS_ENV=production
# Type 'yes' to create the database tables.
输入yes
# When done you see 'Administrator account created:'
表示初始化成功
exit
安装启动脚本
sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab
sudo chkconfig gitlab on
安装logrotate
sudo cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
检测应用状态 编译 Assets
su git
bundle exec rake gitlab:env:info RAILS_ENV=production
bundle exec rake assets:precompile RAILS_ENV=production
exit
启动GitLab
servicce gitlab start
安装nginx
sudo yum install -y nginx
sudo cp lib/support/nginx/gitlab /etc/nginx/conf.d/gitlab.conf
将端口改成8088
sudo vim /etc/nginx/nginx.conf
vim /etc/nginx/conf.d/default.conf
sudo nginx -t
更改selinux
sudo vim /etc/sysconfig/selinux
sudo service nginx restart
sudo chmod 775 /home/git
vim /etc/group
git组添加nginx
最后检测
su git
bundle exec rake gitlab:check RAILS_ENV=production
备份与恢复
备份恢复
bundle exec rake gitlab:backup:create RAILS_ENV=production SKIP=uploads,db
bundle exec rake gitlab:backup:restore RAILS_ENV=production BACKUP=timestamp_of_backup
备份时候默认是备份数据库的 不需要时候添加参数SKIP=db
备份会在gitlab/tmp目录下 以时间戳为前缀生成压缩包 恢复同样需要放置在tmp目录下
恢复时候BACKUP=timestamp_of_backup timestamp_of_backup表示是时间前缀 默认恢复最新一次的备份
ldap认证
修改 config/gitlab.yml
~~~
ldap设置
enabled: true
host: '172.16.24.55'
port: 389
uid: 'cn' #需要去ldap服务器上看一下uid是什么 可能是uid 可能是cn
method: 'tls' # "tls" or "ssl" or "plain"
bind_dn: 'cn=Manager,dc=xkdx,dc=com'
password: ''
base: 'ou=People,dc=xkdx,dc=com'
~~~
发送邮件
修改 config/gitlab.yml
两种方式
一种是使用系统的postfix
一种是使用smtp服务器发送
默认是使用第一种配置比较简单
先说明第一种方式的配置
首先
echo "Test mail from postfix" | mail -s "Test Postfix" bravelib@163.com
然后查看邮件的发件人需要用到 我这边的是root@xkdx.cn
接着 修改 config/gitlab.yml
## Email settings
# Uncomment and set to false if you need to disable email sending from GitLab (default: true)
email_enabled: true
# Email address used in the "From" field in mails sent by GitLab
email_from: root@xkdx.cn #上边163邮箱收到的邮件的发件人地址
email_display_name: GitLabMaster #显示的收件人昵称
email_reply_to:
怎么测试我们配置的内容成功了呢
每次修改配置文件需要重启gitlab程序
service gitlab restart
监控日志文件
tail -f /home/git/gitlab/log/*.log
tail -f /var/log/maillog
然后测试我们的配置
bundle exec rails console production
查看发邮件的方法有sendmail 与smtp(第二种方法)
irb(main):016:0* ActionMailer::Base.delivery_method
=> :sendmail
显示邮件配置
irb(main):017:0> ActionMailer::Base.smtp_settings
=> {:address=>"localhost", :port=>25, :domain=>"localhost.localdomain", :user_name=>nil, :password=>nil, :authentication=>nil, :enable_starttls_auto=>true}
给自己邮箱发送测试文件
irb(main):018:0> Notify.test_email('bravelib@163.com', 'Hello World', 'This is a test message').deliver_now
第二种方式smtp邮件服务器发送
首先修改gitlab.yml的email_from
然后修改
/home/git/gitlab/config/environments/production.rb
config.action_mailer.delivery_method = :sendmail
改成smtp
config.action_mailer.delivery_method = :smtp
最后
cp /home/git/gitlab/config/initializers/smtp_settings.rb.sample /home/git/gitlab/config/initializers/smtp_settings.rb
这个也可用上边的测试方法测试
发邮件时候遇到的问题
很多时候日志只显示已插入到队列 但是邮件收不到
最后终于发现了一个管理页面
http://ip/admin/sidekiq
能显示任务队列的情况
虽然有时候也有邮件发送不成功 至少能看到结果与失败结果了
参考资料
https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/install/installation.md
http://docs.gitlab.com/ce/administration/troubleshooting/debug.html
http://wiki.jikexueyuan.com/project/rails-practice/Chapter_6/6.3.html