@cyysu
        
        2017-09-27T06:24:17.000000Z
        字数 14683
        阅读 1271
    环境搭建
作为本博客的第一次的,也同时作为对网络上博客的抄袭而不加以注意做一次贡献,就网络上源码安装Gitlab教程不多,并且很坑,特此整理一份。还请大家持续关注我的博客,转载请注明出处。谢谢
   [来自]:(http://www.cyysu.cn "运维技术")
文章依赖 
1. 官方博客 
2. 配置网络yum仓库    提取密码ak1v 
3. centos下安装gitlab 
4. centos7下源码安装gitlab
出现错误解决方案依赖
1. 提示没有找不到 Specified 'mysql2' 
2. bundle更换源问题 
3. no tmp uploads folder yet
便捷安装
1. Bitnami安装 
2. 安装工具    提取密码:xb4e
[root@localhost ~]# service iptables stop #关闭防火墙[root@localhost ~]# setenforce 0 #暂时关闭Selinux
wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 https://getfedora.org/static/0608B895.txtrpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6#验证密钥安装成功rpm -qa gpg*#安装软件包,不区分32和64位rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-remi http://rpms.famillecollet.com/RPM-GPG-KEY-remirpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-remi##验证密钥安装成功rpm -qa gpg*#安装软件包rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm#查看上述仓库是否启动yum repolistrepo id repo name statusbase CentOS-6 - Base 6696epel Extra Packages for Enterprise Linux 6 - x86_64 12125extras CentOS-6 - Extras 61remi-safe Safe Remi's RPM repository for Enterprise Linux 6 - x86_64 827updates CentOS-6 - Updates 137repolist: 19846
yum -y update#安装需要的开发的工具yum -y groupinstall 'Development Tools'yum -y install readline readline-devel ncurses-devel gdbm-devel glibc-devel tcl-devel openssl-devel curl-devel expat-devel db4-devel byacc sqlite-devel libyaml libyaml-devel libffi libffi-devel libxml2 libxml2-devel libxslt libxslt-devel libicu libicu-devel system-config-firewall-tui redis sudo wget crontabs logwatch logrotate perl-Time-HiRes git cmake libcom_err-devel.i686 libcom_err-devel.x86_64 nodejsyum -y install python-docutils
#在这里自行可以自行去配置,官方推荐的是postfix。有机会的话,笔者会研究一下,后续更新上来博客yum install postfixservice postfix restartchkconfig postfix on#修改postfix的主配置文件vim /etc/postfix/main.cfmyhostname = sample.test.com ← 设置系统的主机名mydomain = test.com ← 设置域名(我们将让此处设置将成为E-mail地址“@”后面的部分)myorigin = $mydomain ← 将发信地址“@”后面的部分设置为域名(非系统主机名)inet_interfaces = all ← 接受来自所有网络的请求mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain ← 指定发给本地邮件的域名home_mailbox = Maildir/ ← 指定用户邮箱目录#修改gitlab相关的配置文件 修改内容如下:vim /home/git/gitlab/config/gitlab.ymlemail_enabled: trueemail_from: root@cyysu.cn # 发件人的地址email_display_name: GitLabMaster # 显示的收件人昵称email_reply_to:#配置上面的hostname的时候要注意修改一个/etc/hosts文件vim /etc/hosts#生效hostname your_hostname#配置完成之后记得要重启服务/etc/init.d/postfix restart/etc/init.d/gitlab restart#检查是否配置成功,开启三个shell窗口tail -f /home/git/gitlab/log/*.logtail -f /var/log/maillog#执行命令进入测试bundle exec rails console production#接下来就变成下面的界面#输入以下命令:sendmail#显示配置ActionMailer::Base.smtp_settings#给自己邮箱发送测试文件#这里测试最好用163邮箱测试,QQ邮箱测试不是太好使Notify.test_email('cyysu@163.com', 'Hello World', 'This is a test message').deliver_now
#必须要确定git的版本高于2.7.4或更高版本。如果系统安装了git那么需要卸载yum -y remove git#安装git编译需求的软件yum install zlib-devel perl-CPAN gettext curl-devel expat-devel gettext-devel openssl-devel#下载源码并安装mkdir /tmp/git && cd /tmp/gitcurl --progress https://www.kernel.org/pub/software/scm/git/git-2.9.0.tar.gz | tar xzcd git-2.9.0./configuremakemake prefix=/usr/local install
#删除旧的Ruby 1.8软件包(如果存在)。GitLab只支持Ruby 2.1版本系列yum remove ruby#下载并编译mkdir /tmp/ruby && cd /tmp/rubycurl --progress https://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.9.tar.gz | tar xzcd ruby-2.1.9./configure --disable-install-rdocmakemake prefix=/usr/local install#安装Bundler Gemgem install bundler --no-doc# 检测信息,如果输出信息就代表没错which rubyruby -v
#从GitLab 8.0开始,Git HTTP请求由gitlab-workhorse(以前称为gitlab-git-http-server)处理。这是一个在Go写的小守护进程。要安装gitlab-workhorse,我们需要一个Go编译器。yum install -y golang golang-bin golang-src
#Gitlab 创建一个用户adduser --system --shell /bin/bash --comment 'GitLab' --create-home --home-dir /home/git/ git#修改sudoers文件visudoDefaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
#官方推荐用PostgreSQL,这里我们用Mysql来安装#安装软件yum install -y mysql-server mysql-develchkconfig mysqld onservice mysqld start#这里Mysql的版本保持这个样子就可以,亲测可用mysql --version#mysql Ver 14.14 Distrib 5.1.73, for redhat-linux-gnu (x86_64) using readline 5.1#首先对数据库进行一下设置mysql_secure_installation#登陆系统mysql -u root -p#为gitlab创建用户CREATE USER 'git'@'localhost' IDENTIFIED BY 'your passwd';#添加InnoDB引擎SET storage_engine=INNODB;#下面先不创建Gitlab生产数据库,后面有个命令可以创建这里先不创建(不执行)#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'@'localhost';#退出数据库\q
#Gitlab要求Redis版本不低于2.8,系统默认安装版本为2.4.1,卸载当前版本并采用remi源安装最新版本:#卸载当前redis:yum -y remove redis#采用remi源安装最新版本:yum --enablerepo=remi install redis#确保redis在启动时启动:chkconfig redis on#将redis配置为使用套接字:cp /etc/redis.conf /etc/redis.conf.orig#通过将'port'设置为0,禁止在TCP上侦听Redis:sed 's/^port .*/port 0/' /etc/redis.conf.orig | sudo tee /etc/redis.conf#为默认CentOS路径启用Redis套接字:echo 'unixsocket /var/run/redis/redis.sock' | sudo tee -a /etc/redis.confecho -e 'unixsocketperm 0770' | sudo tee -a /etc/redis.conf#创建包含套接字的目录mkdir /var/run/redischown redis:redis /var/run/redischmod 755 /var/run/redis#保留包含套接字的目录(如果适用)if [ -d /etc/tmpfiles.d ]; thenecho 'd /var/run/redis 0755 redis redis 10d -' | sudo tee -a /etc/tmpfiles.d/redis.conffi#修改配置文件vim /etc/redis.conf#bind 127.0.0.1#重启服务:service redis restart#如果遇到以下问题#>>> 'vm-enabled no'#Bad directive or wrong number of arguments[FAILED]只需要注释以下内容:#vm-enabled yes#vm-swap-file /tmp/redis.swap#vm-max-memory 0#vm-page-size 32#vm-pages 134217728#vm-max-threads 4#hash-max-zipmap-entries 512#hash-max-zipmap-value 64#将git添加到redis组:usermod -aG redis git
#存放gitlab等相关软件集合cd /home/git#下载sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 8-9-stable gitlab#配置,从这里开始直接复制即可,主要就是创建目录,赋予权限# Go to GitLab installation foldercd /home/git/gitlab# Copy the example GitLab configsudo -u git -H cp config/gitlab.yml.example config/gitlab.yml# Update GitLab config file, follow the directions at top of filesudo -u git -H editor config/gitlab.yml# Copy the example secrets filesudo -u git -H cp config/secrets.yml.example config/secrets.ymlsudo -u git -H chmod 0600 config/secrets.yml# Make sure GitLab can write to the log/ and tmp/ directoriessudo chown -R git log/sudo chown -R git tmp/sudo chmod -R u+rwX,go-w log/sudo chmod -R u+rwX tmp/# Make sure GitLab can write to the tmp/pids/ and tmp/sockets/ directoriessudo chmod -R u+rwX tmp/pids/sudo chmod -R u+rwX tmp/sockets/# Create the public/uploads/ directorysudo -u git -H mkdir public/uploads/# Make sure only the GitLab user has access to the public/uploads/ directory# now that files in public/uploads are served by gitlab-workhorsesudo chmod 0700 public/uploadssudo chmod ug+rwX,o-rwx /home/git/repositories/# Change the permissions of the directory where CI build traces are storedsudo chmod -R u+rwX builds/# Change the permissions of the directory where CI artifacts are storedsudo chmod -R u+rwX shared/artifacts/# Copy the example Unicorn configsudo -u git -H cp config/unicorn.rb.example config/unicorn.rb# 查看核心数nproc# 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 coressudo -u git -H editor config/unicorn.rb# Copy the example Rack attack configsudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb# Configure Git global settings for git user# 'autocrlf' is needed for the web editorsudo -u git -H git config --global core.autocrlf input# Disable 'git gc --auto' because GitLab already runs 'git gc' when neededsudo -u git -H git config --global gc.auto 0# Configure Redis connection settingssudo -u git -H cp config/resque.yml.example config/resque.yml# 这里保持默认sudo -u git -H vim config/resque.yml
#配置数据库文件sudo -u git cp config/database.yml.mysql config/database.yml#编辑数据库文件sudo -u git -H vim config/database.ymlproduction:adapter: mysql2encoding: utf8collation: utf8_general_cireconnect: falsedatabase: gitlabhq_productionpool: 10username: gitlabpassword: "gitlab"# host: localhost# socket: /tmp/mysql.sock#赋予权限sudo -u git -H chmod o-rwx config/database.yml
cd /home/git/gitlabsudo -u git -H bundle config build.pg --with-pg-config=/usr/pgsql-9.3/bin/pg_configsudo -u git -H bundle install --deployment --without development test mysql aws kerberossudo -u git -H bundle install --deployment --without development test postgres aws kerberos#提示出现这个错误:#Gem::Ext::BuildError: ERROR: Failed to build gem native extension.#/usr/local/bin/ruby extconf.rb --with-pg-config=/usr/pgsql-9.3/bin/pg_config#Using config values from /usr/pgsql-9.3/bin/pg_config#sh: /usr/pgsql-9.3/bin/pg_config: No such file or directory#sh: /usr/pgsql-9.3/bin/pg_config: No such file or directory#解决方法:#卸载yum remove postgresql#安装pgdg仓库:rpm -Uvh http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-centos93-9.3-2.noarch.rpm#安装postgresql93-server,postgreqsql93-devel和postgresql93-contrib库:yum install postgresql93-server postgresql93-devel postgresql93-contrib#重命名服务脚本:mv /etc/init.d/{postgresql-9.3,postgresql}# 服务启动service postgresql initdbservice postgresql startchkconfig postgresql on#这个时候就不会报错了,提示以下信息#-------------------------------------------------#Thank you for installing html-pipeline!#You must bundle Filter gem dependencies.#See html-pipeline README.md for more details.#https://github.com/jch/html-pipeline#dependencies#-------------------------------------------------#这里我们修改一个Gemfile文件,刚刚编辑的数据库配置文件我们看到了Mysql2,我们执行的上述步骤是没有安装的,检查的方法可以使用如下#查看mysql2是否安装bundle show mysql2#当前目录在Gitlab目录下,编辑Gemfile文件,修改成如下内容vim Gemfilegem "mysql2", '~> 0.3.18'#在执行以下语句bundle install --no-deployment#执行时间根据网速和电脑配置而言,下面查看以下结果[root@localhost gitlab]# bundle show mysql2/usr/local/lib/ruby/gems/2.1.0/gems/mysql2-0.3.20
#安装sudo -u git -H bundle exec rake gitlab:shell:install[v3.0.0] REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production#编辑文件 这个文件主要就是提供gitlab API 接口的sudo -u git -H vim /home/git/gitlab-shell/config.yml#修改内容如下gitlab_url: "http://localhost:8000/"#这个文件主要提供ruby的服务端口和ip[root@localhost gitlab]# vim config/unicorn.rb#修改内容如下listen "127.0.0.1:8080", :tcp_nopush => true#这个文件主要提供gitlab服务的端口,ip[root@localhost gitlab]# vim config/gitlab.yml#修改内容如下gitlab:host: localhostport: 8000git:bin_path: /usr/local/bin/git#如果后面的操作会提示git找不到那么需要执行以下操作ln -s /usr/local/bin/git /usr/bin/gitrestorecon -Rv /home/git/.ssh
#这个不多说了,很简单cd /home/gitsudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-workhorse.gitcd gitlab-workhorsesudo -u git -H git checkout v0.7.5sudo -u git -H make
cd /home/git/gitlabsudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production#这里会提示如下“错误”#Couldn't drop gitlabhq_production#Access denied for user 'gitlab'@'localhost' (using password: YES)Please provide the root password for your MySQL installation>输入你设定的mysql密码#之后就会提示如下内容# -> 0.0104s#-- add_foreign_key("u2f_registrations", "users")# -> 0.0085s#-- initialize_schema_migrations_table()# -> 0.0188s#Adding limits to schema.rb for mysql#-- change_column(:merge_request_diffs, :st_commits, :text, {:limit=>2147483647})# -> 0.0218s#-- change_column(:merge_request_diffs, :st_diffs, :text, {:limit=>2147483647})# -> 0.0107s#-- change_column(:snippets, :content, :text, {:limit=>2147483647})# -> 0.0134s#-- change_column(:notes, :st_diff, :text, {:limit=>2147483647})# -> 0.0149s#-- change_column(:events, :data, :text, {:limit=>2147483647})# -> 0.0096s#== Seed from /home/git/gitlab/db/fixtures/production/001_admin.rb#Administrator account created:#login: root#password: You'll be prompted to create one on your first visit.#当你进行登陆的时候就会提示你更改密码的操作
#安装了这么长时间终于快结束了,心情有没有开心!!!!#当前目录在/home/git/gitlabcp lib/support/init.d/gitlab /etc/init.d/gitlabchkconfig gitlab oncp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab#检查程序的版本#System information#System: CentOS 6.8#Current User: git#Using RVM: no#Ruby Version: 2.1.9p490#Bundler Version:1.14.6#Rake Version: 10.5.0#Sidekiq Version:4.1.2#GitLab information#Version: 8.9.11#Revision: 9a05855#Directory: /home/git/gitlab#DB Adapter: mysql2#URL: http://localhost:8000#HTTP Clone URL: http://localhost:8000/some-group/some-project.git#SSH Clone URL: git@localhost:some-group/some-project.git#Using LDAP: no#Using Omniauth: no#GitLab Shell#Version: 3.0.0#Repositories: /home/git/repositories/#Hooks: /home/git/gitlab-shell/hooks/#Git: /usr/bin/git#生成网页需要的资源sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production#启动实例service gitlab start#如果看到以下信息,就代表你已经成功安装了Gitlab#Starting GitLab Unicorn#Starting GitLab Sidekiq#Starting Gi充电tLab Workhorse#The GitLab Unicorn web server with pid 80821 is running.#The GitLab Sidekiq job dispatcher with pid 80870 is running.#The GitLab Workhorse with pid 80852 is running.#GitLab and all its components are up and running.#下面在浏览器开始c访问http://localhost:8000#开始就会弹出让你修改密码的界面,之后就提示登陆界面#http://localhost:8000/users/password/edit?reset_password_token=DjzQ-AcPsgdkhx4ckUBg#初始的时候你可以用root和你刚刚设定的密码进行登陆#http://localhost:8000/users/sign_in#如果发现不能登陆,请确保服务启动成功,然后在重点检查以下配置文件#当前目录 /home/git/gitlabvim config/gitlab.ymlvim config/unicorn.rbvim ../gitlab-shell/config.yml#如果提示以下信息,那么需要检测Redis,mysql是否启动/etc/init.d/gitlab restartThe GitLab Unicorn web server is not running.#查看/home/git/gitlab/log/unicorn.stderr.log,最新的日志在末尾。/home/git/gitlab/config/environments/production.rb:82: syntax error#进入命令模式set nu显示行号,找到82行所在。#如果发现启动不了服务,可以尝试重新创建一下数据库sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production#检测一下程序状态#这里可以看出你的版本是否达到要求,不过笔者一切比较正常。#前几次装的时候出现过版本不对,不过也没有影响使用#可能这是个bug吧 如果那位大神了解这个还请给我留言,谢谢sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production#Checking GitLab Shell ...##GitLab Shell version >= 3.0.0 ? ... OK (3.0.0)#Repo base directory exists? ... yes#Repo base directory is a symlink? ... no#Repo base owned by git:git? ... yes#Repo base access is drwxrws---? ... yes#hooks directories in repos are links: ... can't check, you have no projects#Running /home/git/gitlab-shell/bin/check#Check GitLab API access: OK#Check directories and files:# /home/git/repositories/: OK# /home/git/.ssh/authorized_keys: OK#Send ping to redis server: gitlab-shell self-check successful##Checking GitLab Shell ... Finished##Checking Sidekiq ...##Running? ... yes#Number of Sidekiq processes ... 1##Checking Sidekiq ... Finished##Checking Reply by email ...##Reply by email is disabled in config/gitlab.yml##Checking Reply by email ... Finished##Checking LDAP ...##LDAP is disabled in config/gitlab.yml##Checking LDAP ... Finished##Checking GitLab ...##Git configured with autocrlf=input? ... yes#Database config exists? ... yes#All migrations up? ... yes#Database contains orphaned GroupMembers? ... no#GitLab config exists? ... yes#GitLab config outdated? ... no#Log directory writable? ... yes#Tmp directory writable? ... yes#Uploads directory setup correctly? ... skipped (no tmp uploads folder yet)#Init script exists? ... yes#Init script up-to-date? ... yes#projects have namespace: ... can't check, you have no projects#Redis version >= 2.8.0? ... yes#Ruby version >= 2.1.0 ? ... yes (2.1.9)#Your git bin path is "/usr/local/bin/git"#Git version >= 2.7.3 ? ... yes (2.9.0)#Active users: 1##Checking GitLab ... Finished
#说在前头: 这里的web服务器可以选择性安装,就是可以通过外网正常访问你的GitLab,这里web服务器可以选择Nginx或这Apachesudo yum install -y nginxsudo cp lib/support/nginx/gitlab /etc/nginx/conf.d/gitlab.conf#这里默认不修改端口 默认是80vim /etc/nginx/conf.d/gitlab.confvim /etc/nginx/conf.d/default.confvim /etc/nginx/nginx.conf#测试语法sudo nginx -t#启动服务sudo service nginx restartchkconfig nginx onsudo chmod 775 /home/git#在本地电脑访问对于的IP。如果以上均配置正确,就会看到登陆页面http://192.168.223.140:80