其他分享
首页 > 其他分享> > gitlab安装

gitlab安装

作者:互联网

依赖安装配置

  sudo yum install curl policycoreutils openssh-server openssh-clients
  sudo systemctl enable sshd
  sudo systemctl start sshd
  sudo yum install postfix
  sudo systemctl enable postfix
  sudo systemctl start postfix

gitlab 安装

curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
sudo yum install -y gitlab-ce
或者下载https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-11.10.4-ce.0.el7.x86_64.rpm
rpm -ivh gitlab-ce-11.10.4-ce.0.el7.x86_64.rpm

vi /etc/gitlab/gitlab.rb
external_url 'http://yourip:port'
nginx['listen_port'] = 9010
unicorn['port'] = 9011
sudo gitlab-ctl reconfigure

gitlab-ctl start

登录

http://yourip:port
账号  root 密码  初始化设定

gitlab 汉化

https://www.jianshu.com/p/2400d9e57fd1

先查看gitlab版本

cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
或者
rpm -q gitlab-ee

下载汉化包

wget https://gitlab.com/xhang/gitlab/repository/11-10-stable-zh/archive.tar.bz2 -O gitlab-11-10-stable-zh.tar.bz2

解压下载文件

tar -jxvf gitlab-11-10-stable-zh.tar.bz2

先备份,避免汉化失败后gitlab瘫痪

cp -r /opt/gitlab/embedded/service/gitlab-rails{,.ori}

复制并覆盖

cp -rf gitlab-11-10-stable-zh/* /opt/gitlab/embedded/service/gitlab-rails/

这里的错误,忽略,因为之前已经设置gitlab的root密码了
重新配置gitlab

gitlab-ctl reconfigure

重启gitlab

gitlab-ctl restart 

日志查看

查看所有的logs; 按 Ctrl-C 退出

sudo gitlab-ctl tail

拉取/var/log/gitlab下子目录的日志

sudo gitlab-ctl tail gitlab-rails

拉取某个指定的日志文件

sudo gitlab-ctl tail nginx/gitlab_error.log

卸载gitlab

gitlab-ctl stop
rpm -e gitlab-ce
ps aux | grep gitlab
#杀死进程
kill -9 18777
ps -ef | grep gitlab | xargs kill -s 9 
find /{opt,etc,var} -name gitlab | xargs rm -rf
重新配置时出现卡死的情况的解决方案
sudo systemctl restart gitlab-runsvdir

gitlab 迁移

https://www.cnblogs.com/crysmile/p/9505527.html

备份原有服务器上文件信息:

1、/etc/gitlab/gitlab.rb:该文件配置了gitlab的域名、邮件发送信息、白名单等相关信息。
2、/etc/gitlab/gitlab-secrets.json:该文件存储了gitlab的db secret信息。

将原有服务器上的以上两个文件复制到新服务器上对应目录下。

备份原有服务器上gitlab数据信息:

使用以下命令进行备份。
/usr/bin/gitlab-rake gitlab:backup:create
/var/opt/gitlab/backups/1560110605_2019_06_10_11.10.4_gitlab_backup.tar
默认备份完成的文件存放目录为:/var/opt/gitlab/backups。若该目录下不存在,则需要查看/etc/gitlab/gitlab.rb配置中对应的gitlab_rails['backup_path']选项所指定的目录。

新服务器配置

rpm -ivh gitlab-ce-11.10.4-ce.0.el7.x86_64.rpm
#scp gitlab仓库备份拷贝
scp -p 192.168.1.153:/etc/gitlab/gitlab.rb /etc/gitlab/gitlab.rb 
scp -p 192.168.1.153:/etc/gitlab/gitlab-secrets.json /etc/gitlab/gitlab-secrets.json
scp -p  192.168.1.153:/var/opt/gitlab/backups/1560112293_2019_06_10_11.10.4_gitlab_backup.tar /var/opt/gitlab/backups/1560112293_2019_06_10_11.10.4_gitlab_backup.tar
gitlab-ctl reconfigure
gitlab-rake gitlab:backup:restore BACKUP=1560112293_2019_06_10_11.10.4
其中1560110605_2019_06_10_11.10.4对应的为gitlab备份tar包的版本号。

保守起见,先进行gitlab-ctl reconfigure,然后启动服务。
gitlab-ctl restart

ldap 配置

gitlab_rails['ldap_enabled'] = true

###! **remember to close this block with 'EOS' below**
gitlab_rails['ldap_servers'] = YAML.load <<-'EOS'
    main: # 'main' is the GitLab 'provider ID' of this LDAP server
     label: 'LDAP'
     host: 'localhost'
     port: 389
     uid: 'uid'
     bind_dn: 'cn=Manager,dc=luoye,dc=site'
     password: '123456'
     encryption: 'plain' # "start_tls" or "simple_tls" or "plain"
#     verify_certificates: true
#     smartcard_auth: false
     active_directory: true
     allow_username_or_email_login: false
#     lowercase_usernames: false
#     block_auto_created_users: false
     base: 'ou=People,dc=luoye,dc=site'
     user_filter: ''
#     ## EE only
#     group_base: ''
#     admin_group: ''
#     sync_ssh_keys: false
#
#   secondary: # 'secondary' is the GitLab 'provider ID' of second LDAP server
#     label: 'LDAP'
#     host: '_your_ldap_server'
#     port: 389
#     uid: 'sAMAccountName'
#     bind_dn: '_the_full_dn_of_the_user_you_will_bind_with'
#     password: '_the_password_of_the_bind_user'
#     encryption: 'plain' # "start_tls" or "simple_tls" or "plain"
#     verify_certificates: true
#     smartcard_auth: false
#     active_directory: true
#     allow_username_or_email_login: false
#     lowercase_usernames: false
#     block_auto_created_users: false
#     base: ''
#     user_filter: ''
#     ## EE only
#     group_base: ''
#     admin_group: ''
#     sync_ssh_keys: false
EOS

重新配置 检查

gitlab-ctl reconfigure                               #重载配置文件
gitlab-rake gitlab:ldap:check                        #检查是否能够正常获取用户信息

邮件设置

gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = 'luoyemoon@foxmail.com'
gitlab_rails['gitlab_email_display_name'] = 'luoyemoon'
gitlab_rails['smtp_address'] = "smtp.qq.com" 
gitlab_rails['smtp_port'] = 465 
gitlab_rails['smtp_user_name'] = "邮箱地址" 
gitlab_rails['smtp_password'] = "password" 
gitlab_rails['smtp_authentication'] = "login" 
gitlab_rails['smtp_enable_starttls_auto'] = true 
gitlab_rails['smtp_tls'] = true 
gitlab_rails['smtp_domain'] = "smtp.qq.com" 

测试配置是否成功

执行 gitlab-rails console进入控制台。 然后在控制台提示符后输入下面的命令 发送一封测试邮件:Notify.test_email('收件人邮箱', '邮件标题', '邮件正文').deliver_now

gitlab.rb配置简要解析:

external_url 'http://gitlab.xxx.com'                                #gitlab域名
gitlab_rails['gitlab_email_enabled'] = true                         #gitlab启用email通知
gitlab_rails['gitlab_email_from'] = 'xxx-gitlab@xxx.com'            #gitlab email来源
gitlab_rails['gitlab_email_display_name'] = 'gitlab-servce'         #email展示名称
gitlab_rails['gitlab_email_reply_to'] = 'xxx-gitlab@xxx.com'        #gitlab返回邮箱地址
gitlab_rails['gitlab_email_subject_suffix'] = ''
gitlab_rails['manage_backup_path'] = true                           #启用backup路径配置 
gitlab_rails['backup_path'] = "/NFS"                                #设置gitlab备份路径
gitlab_rails['gitlab_shell_ssh_port'] = xxxx                        #设置gitlab ssh端口
gitlab_rails['git_max_size'] = 20971520
gitlab_rails['git_timeout'] = 10
gitlab_rails['gitlab_shell_git_timeout'] = 800
gitlab_rails['rack_attack_git_basic_auth'] = {
   'enabled' =&gt; true,
   'ip_whitelist' =&gt; ["192.168.8.118"],                             #设置gitlab白名单列表
   'maxretry' =&gt; 300,
   'findtime' =&gt; 5,
   'bantime' =&gt; 60
}
gitlab_rails['initial_root_password'] = "xxxxxxx"                   #gitlab初始化root密码
gitlab_rails['smtp_enable'] = true                                  #设置gitlab 发送邮件smtp服务器信息
gitlab_rails['smtp_address'] = "smtp.xxx.xxx.com"                   #设置smtp服务器地址             
gitlab_rails['smtp_port'] = xxx                                     #设置smtp服务器端口
gitlab_rails['smtp_user_name'] = "xxx-gitlab@xxx.com"               #设置smtp用户名
gitlab_rails['smtp_password'] = "xxxxxx"                            #设置smtp密码
gitlab_rails['smtp_domain'] = "smtp.xxx.com"                        #设置smtp域名
gitlab_rails['smtp_authentication'] = "login"       
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_from'] = 'xxx-gitlab@xxx.com'
git_data_dir "/data/gitlab-data"                                    #设置gitlab数据目录


gitlab_rails['ldap_enabled'] = true                                 #设置gitlab ldap认证

gitlab_rails['ldap_servers'] = YAML.load &lt;&lt;-&#039;EOS&#039;
  main: # &#039;main&#039; is the GitLab &#039;provider ID&#039; of this LDAP server
	label: &#039;LDAP&#039;
	host: &#039;xx.xx.xx.xx&#039;                                             #设置ldap服务器地址
	port: xxx                                                       #设置ldap服务器端口
	uid: &#039;cn&#039;
	method: &#039;plain&#039; # &quot;tls&quot; or &quot;ssl&quot; or &quot;plain&quot;
	bind_dn: &#039;cn=xxx,dc=xxx,dc=com&#039;                                 #ldap bind dn
	password: &#039;xxx&#039;                                                 #ldap bind dn用户对应的密码
	active_directory: true
	allow_username_or_email_login: true                             #允许用户名和邮箱登录
	block_auto_created_users: false
	base: &#039;dc=xxx,dc=com&#039;                                           #ldap base dn信息,即搜索域
	attributes:
	  username: [&#039;cn&#039;, &#039;uid&#039;]
	  email:    [&#039;mail&#039;, &#039;email&#039;]
EOS

错误

1、There was an error running gitlab-ctl reconfigure:

execute[clear the gitlab-rails cache] (gitlab::gitlab-rails line 401) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received ‘1’
---- Begin output of /opt/gitlab/bin/gitlab-rake cache:clear ----
STDOUT:
STDERR: rake aborted!
Errno::ENOENT: No such file or directory - No file specified as Settingslogic source
解决方案:
2 导入时权限不足
Unpacking backup … tar: 1562389210_2019_07_06_11.10.4_gitlab_backup.tar: Cannot open: Permission denied
chown git:git /var/opt/gitlab/backups

标签:xxx,&#,gitlab,smtp,rails,039,安装
来源: https://blog.csdn.net/pcjk8866/article/details/104782207