CentOS7下gitlab的搭建


gitlab的搭建

  • 安裝基礎包
yum -y install curl policycoreutils openssh-server openssh-clients

 

  • 啟動sshd
systemctl enable sshd
systemctl start sshd

 

  • 安裝postfix
yum -y install postfix
systemctl enable postfix
systemctl start postfix

 

  • 添加防火牆規則
firewall-cmd --permanent --add-service=http
systemctl reload firewalld

 or

yum install firewalld
systemctl unmask firewalld

 

  • 下載並安裝軟件包(軟件包下載較慢)
curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
yum install gitlab-ce

 

添加國內的鏡像源

執行上面的命令,會一直 time out ,所以我們要換成國內的源.

以下操作針對CentOS 7 ,其他的請戳 https://mirror.tuna.tsinghua.edu.cn/help/gitlab-ce/

vi /etc/yum.repos.d/gitlab-ce.repo
[gitlab-ce]
name=gitlab-ce
baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7
repo_gpgcheck=0
gpgcheck=0
enabled=1
gpgkey=https://packages.gitlab.com/gpg.key

注意,如果對應配置文件下有文件gitlab_gitlab-ce.repo,重命名一下,不然會默認加載這個導致上面的文件不起作用.

查看目前的yum進程,並殺死

ps -a
  PID TTY          TIME CMD
18781 pts/0    00:00:00 sudo
18783 pts/0    00:00:00 bash
18796 pts/0    00:00:00 yum
18855 pts/0    00:00:00 sudo
18856 pts/0    00:00:00 yum
18871 pts/0    00:00:00 ps

kill -9 18796
kill -9 18856

然后安裝:

sudo yum makecache
sudo yum install gitlab-ce 

上面執行完了,是這樣的展示結果

sudo gitlab-ctl reconfigure

gitlab: GitLab should be reachable at http://iZ2851te7e5Z
gitlab: Otherwise configure GitLab for your system by editing /etc/gitlab/gitlab.rb file
gitlab: And running reconfigure again.
gitlab: 
gitlab: For a comprehensive list of configuration options please see the Omnibus GitLab readme
gitlab: https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md
gitlab: 
It looks like GitLab has not been configured yet; skipping the upgrade script.
  驗證中      : gitlab-ce-8.7.6-ce.0.el7.x86_64                                                                                         1/1 

已安裝:
  gitlab-ce.x86_64 0:8.7.6-ce.0.el7                                                                                                         

完畢!

 

默認安裝的是最新的gitlab-ce的包,如果需要特定的版本可以在官網去下載特定的版本 地址:

https://packages.gitlab.com/gitlab/gitlab-ce/

 

  • 配置並啟動gitlab
 gitlab-ctl reconfigure

 

  • 默認賬戶密碼是
Username: root 
Password: 5iveL!fe

 測試地址(默認80端口):

http://127.0.0.1/

 

2、 gitlab的備份

  • 備份命令
gitlab-rake gitlab:backup:create

 

默然的備份目錄為:    /var/opt/gitlab/backups 備份文件名類似:       1393513186_gitlab_backup.tar

  • 備份目錄的修改
vi /etc/gitlab/gitlab.rb
gitlab_rails['backup_path'] = '/mnt/gitlab_backups'

 

3、gitlab數據的恢復或還原

提示:gitlab數據的恢復或者遷移成功的前提——兩台服務器的gitlab的版本必須相同,若不相同則可能遷移或者恢復失敗

  • 將備份文件放在gitlab的默認備份目錄

比如/var/opt/gitlab/backups下的1458217074_gitlab_backup.tar

  • 設置自動備份
0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create 

 

  • 恢復或者還原

停服務

 gitlab-ctl stop unicorn
 gitlab-ctl stop sidekiq

 

恢復數據

gitlab-rake gitlab:backup:restore BACKUP=1458213020

 

BACKUP后面跟的是備份文件的時間戳,比如恢復備份文件1458217074_gitlab_backup.tar

gitlab-rake gitlab:backup:restore BACKUP=1458217074

 

  • 恢復完啟動服務
 gitlab-ctl start

 

gitlab nginx 修改

  • 配置文件 /var/opt/gitlab/nginx/conf/gitlab-http.conf。這個文件是gitlab內置的nginx的配置文件,里面可以影響到nginx真實監聽端口號。
server {
  listen *:82;

  server_name gitlab.123.123.cn;
  server_tokens off; ## Don't show the nginx version number, a security best practice
  • 修改完成后,重啟下,就可以放82端口的gitlab了。
gitlab-ctl restart
 
        

gitlab redis 修改啟用

默認情況下gitlab是沒有啟用自帶的redis的(雖然redis已經和gitlab一起啟動):
ok: run: gitlab-workhorse: (pid 14263) 1s
ok: run: logrotate: (pid 14271) 0s
ok: run: nginx: (pid 14278) 1s
ok: run: node-exporter: (pid 14284) 0s
ok: run: postgres-exporter: (pid 14288) 1s
ok: run: postgresql: (pid 14303) 0s
ok: run: prometheus: (pid 14312) 1s
ok: run: redis: (pid 14317) 0s
ok: run: redis-exporter: (pid 14320) 0s
ok: run: sidekiq: (pid 14330) 1s
ok: run: unicorn: (pid 14336) 0s

啟用自帶的redis,修改/etc/gitlab/gitlab.rb:

redis['port'] = 6379
redis['bind'] = '127.0.0.1'
[root@localhost ~]# gitlab-ctl reconfigure

可以看到redis-server和端口6379,redis已經開始工作了:

Running handlers:
Running handlers complete
Chef Client finished, 15/397 resources updated in 25 seconds
gitlab Reconfigured!

[root@localhost ~]# gitlab-ctl restart

[root@localhost ~]# ps -ef|grep redis
root 639 632 0 14:54 ? 00:00:00 runsv redis
root 649 632 0 14:54 ? 00:00:00 runsv redis-exporter
root 653 639 0 14:54 ? 00:00:00 svlogd -tt /var/log/gitlab/redis
root 668 649 0 14:54 ? 00:00:00 svlogd -tt /var/log/gitlab/redis-exporter
gitlab-+ 14317 639 0 16:36 ? 00:00:00 /opt/gitlab/embedded/bin/redis-server 127.0.0.1:6379
gitlab-+ 14320 649 0 16:36 ? 00:00:00 /opt/gitlab/embedded/bin/redis_exporter -web.listen-address=localhost:9121 -redis.addr=unix:///var/opt/gitlab/redis/redis.socket
root 14376 8935 0 16:36 pts/2 00:00:00 grep --color=auto redis

訪問一下gitlab主頁和各頁面,然后查看redis里的緩存清況,已經出現緩存內容了:

[root@localhost ~]# /opt/gitlab/embedded/bin/redis-cli 
127.0.0.1:6379> keys *
  1) "resque:gitlab:cron_job:admin_email_worker"
  2) "resque:gitlab:cron_job:repository_archive_cache_worker"
  3) "resque:gitlab:limit_fetch:probed:repository_import"
  4) "cache:gitlab:last_commit_id_for_path:2af1c3ff162bb2...................

詳細文檔:https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/doc/settings/redis.md




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM