gitlab的介紹
gitlab的安裝:
首次登陸的密碼:
輸入:root/5iveL!fe 登錄!
——————————————————————————————————————————————————————
一鍵安裝
------------------------------------
1.安裝配置依賴關系
yum install curl openssh-server openssh-clients postfix cronie wget lokkit -y
service postfix start 郵件服務的開通
lokkit -s http -s ssh #配置iptables開放http和ssh端口
iptables -L 查看iptables的規則
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:80
----------------------------------------------------------------------------
下載RPM包:
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el6/gitlab-ce-8.9.9-ce.0.el6.x86_64.rpm 清華大學開源軟件鏡像站
rpm -ivh gitlab-ce-8.9.9-ce.0.el6.x86_64.rpm
啟動GitLab
gitlab-ctl reconfigure
------------------------------------------------------------------------------
另一種方法:(官方文檔)
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash
yum install gitlab-ee
gitlab-ctl reconfigure
-------------------------------------------------------------------------------
http://ip
root/5iveL!fe
重啟:
gitlab-ctl restart
-----------------------------------------------------
502錯誤
是內存不足導致
dd if=/dev/zero of=/var/swap bs=1024 count=2048000
mkswap /var/swap
swapon /var/swap 激活虛擬內存
vim /etc/fstab
/var/swap swap swap defaults 0 0
mount -a
------------------------------------------------------------
修改端口:
vim /etc/gitlab/gitlab.rb
## Advanced settings
unicorn['listen'] = '127.0.0.1'
# unicorn['port'] = 8080
unicorn['port'] = 8082
# nginx['ssl_dhparam'] = nil # Path to dhparams.pem, eg. /etc/gitlab/ssl/dhparams.pem
nginx['listen_addresses'] = ['*']
nginx['listen_port'] = 82 # override only if you use a reverse proxy: https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/doc/settings/nginx.md#setting-the-nginx-listen-port
vim /var/opt/gitlab/gitlab-rails/etc/unicorn.rb
listen "127.0.0.1:8082", :tcp_nopush => true
listen "/var/opt/gitlab/gitlab-rails/sockets/gitlab.socket", :backlog => 1024
vim /var/opt/gitlab/nginx/conf/gitlab-http.conf
server {
# listen *:80;
listen *:82;
server_name localhost;
server_tokens off;
gitlab-ctl restart 重啟gitlab
nginx做代理進行修改:
vim /usr/local/nginx/conf/conf.d/gitlab.conf
server {
listen 80;
server_name gitlab.123.123.cn;
location / {
#rewrite ^(.*) http://127.0.0.1:8082;
proxy_pass http://127.0.0.1:8082;
}
}
修改gitlab-shell
vim /var/opt/gitlab/gitlab-shell/config.yml
# Url to gitlab instance. Used for api calls. Should end with a slash.
#gitlab_url: "http://127.0.0.1:9090"
gitlab_url: "http://127.0.0.1:82"
gitlab-ctl restart 重啟服務
---------------------------------------------------------------------------
創建私鑰公鑰:
ssh-keygen -t rsa -C "xxxx@163.com" 生成私鑰公鑰
git config --global user.name "tom" 設置username
git config --global user.email "alice" 設置user的email地址
上傳公鑰:
cat id_rsa.pub 把公鑰復制到web頁面相應位置上
創建新的項目:
git clone git@localhost:root/project.git 克隆一個項目
cd project/
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master
==========================================================================================
gitlab的備份
gitlab的備份
1.必須是root用戶執行
vim /opt/gitlab-6.6.5-0/apps/gitlab/htdocs/config/gitlab.yml
backup:
path: "/tmp/backups" # Relative paths are relative to Rails.root (default: tmp/backups/) 路徑可以自定義
keep_time: 604800 # default: 0 (forever) (in seconds)
cd /opt/gitlab-6.6.5-0/apps/gitlab/htdocs/
/opt/gitlab-6.6.5-0/ruby/bin/bundle exec bin/rake gitlab:backup:create RAILS_ENV=production
ll /tmp/backups
-rw-r--r--. 1 root root 40960 Jun 1 16:10 1496304653_gitlab_backup.tar
成功
gitlab的數據恢復
cd /opt/gitlab-6.6.5-0/apps/gitlab/htdocs/
/opt/gitlab-6.6.5-0/ruby/bin/bundle exec bin/rake gitlab:backup:restore RAILS_ENV=production
如果有多個備份文件則在RAILS_ENV=production 后制定恢復哪個文件 BACKUP=1496304653_gitlab_backup.tar
備份腳本
#!/bin/bash
#if [ `id -u` -ne 0 ];then
# echo "this backup script must be exec as root."
# exit
#fi
#date
PATH="/opt/gitlab-6.6.5-0/apps/gitlabci/gitlabci-runner/bin:/opt/gitlab-6.6.5-0/apps/gitlab/gitlab-shell/bin:/opt/gitlab-6.6.5-0/redis/bin:/opt/gitlab-6.6.5-0/sqlite/bin:/opt/gitlab-6.6.5-0/python/bin:/opt/gitlab-6.6.5-0/perl/bin:/opt/gitlab-6.6.5-0/git/bin:/opt/gitlab-6.6.5-0/ruby/bin:/opt/gitlab-6.6.5-0/mysql/bin:/opt/gitlab-6.6.5-0/apache2/bin:/opt/gitlab-6.6.5-0/common/bin:$PATH"
echo "backup gitlab to local storage begin.. "
cd /opt/gitlab-6.6.5-0/apps/gitlab/htdocs
/opt/gitlab-6.6.5-0/ruby/bin/bundle exec bin/rake gitlab:backup:create RAILS_ENV=production
echo "rsync -avzP --delete /tmp/backups 192.168.1.100:/gitlab/back"
rsync -avzP --delete /tmp/backups 192.168.1.100:/gitlab/back
date
echo "this job is end."
=======================================================================================
git的上傳文件和代碼
創建私鑰公鑰:
ssh-keygen -t rsa -C "xxxx@163.com" 生成私鑰公鑰
上傳公鑰:
cat /root/.ssh/id_rsa.pub 把公鑰復制到web頁面相應位置上
git config --global user.name "tom" 設置username
git config --global user.email "alice" 設置user的email地址
創建新的項目:
git clone git@localhost:root/project.git 克隆一個項目
cd project/
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master
git init 創建可管理的倉庫
git clone ssh:git@192.168.1.132:good/test.git 克隆線上倉庫
git status 查看是否有文件需要提交
git add -A or git add . 把文件添加到暫存區里面去 -A和. 是全部
git status 查看狀態
git commit -m "first push" 提交文件到倉庫 ""是注釋
git log 查看日志
git remote add origin [git@192.168.1.132:good/test.git] 填寫項目的url地址 這樣做可以默認推送到遠端master分支
git push -u origin master 把本地倉庫分支推送到元倉庫(遠程)
git pull origin master 接收數據 (不能應用多分支Pull的情況)
git branch 查看當前分支
git checkout -b dev dev是分支名 創建并切換到分支
git checkout dev 切換分支
git branch dev 創建分支
git branch -d dev 刪除分支
git merge dev 合并分支
====================================================================================
一鍵安裝
chmod +x bitnami-gitlab-6.6.5-0-linux-x64-installer.run
./ bitnami-gitlab-6.6.5-0-linux-x64-installer.run
GitLab CI [Y/n] :Y
Is the selection above correct? [Y/n]: Y
Select a folder [/opt/gitlab-6.6.5-0] 安裝目錄(默認在/opt/gitlab-6.6.5-0)
Email Address [user@example.com]: zhangxiandong@e-eduspace.com 郵件地址
Login [user]: tom 登陸名
Password: 默認是8位字符以上
Please confirm your password :
Domain [127.0.0.1]: 192.168.1.131 域名地址
Do you want to configure mail support? [y/N]: N 是否支持郵件
Default email provider:
[1] GMail 谷歌郵箱
[2] Custom 自定義
Please choose an option [1] : 2
Configure SMTP Settings
This data is stored in the application configuration files and may be visible to
others. For this reason, it is recommended that you do not use your personal
account credentials.
Username []: zhangxiandong 郵箱名
Password : 郵箱密碼
Re-enter : 重復輸入
SMTP Host []: e-eduspace@.com
SMTP Port []: 25
Secure connection 安全連接
[1] None
[2] SSL
[3] TLS
Please choose an option [3] : 1
Setup is now ready to begin installing Bitnami Gitlab Stack on your computer.
Do you want to continue? [Y/n]: Y
Please wait while Setup installs Bitnami Gitlab Stack on your computer.
Installing
0% ______________ 50% ______________ 100%
#########################################
----------------------------------------------------------------------------
Setup has finished installing Bitnami Gitlab Stack on your computer.
Info: To access the Bitnami Gitlab Stack, go to
http://192.168.1.131:80 from your browser.
Press [Enter] to continue :
開啟服務的命令:
cd /opt/gitlab-6.6.5-0/
./ctlscript.sh
也可以單獨服務的重啟和關閉
./ctlscript.sh mysql or redis
============================================================================================
apache mysql和redis的端口修改文件
httpd的默認端口的修改
vim /opt/gitlab-6.6.5-0/apache2/conf/httpd.conf apache的配置文件
Listen 8080
ServerName localhost:8080
vim /opt/gitlab-6.6.5-0/apache2/conf/bitnami/bitnami.conf
NameVirtualHost *:8080
<VirtualHost _default_:8080>
vim /opt/gitlab-6.6.5-0/apache2/scripts/ctl.sh
echo "$0 $ARG: httpd started at port 8080"
vim /opt/gitlab-6.6.5-0/apache2/conf/extra/httpd-vhosts.conf
<VirtualHost *:8080>
<VirtualHost *:8080>
vim /opt/gitlab-6.6.5-0/apps/gitlabci/conf/httpd-vhosts.conf
<VirtualHost *:8080>
vim /opt/gitlab-6.6.5-0/redis/etc/redis.conf redis的配置文件
mysql默認端口的修改
vim /opt/gitlab-6.6.5-0/mysql/my.cnf mysqld的配置文件
port=3306
vim /opt/gitlab-6.6.5-0/mysql/scripts/ctl.sh 修改mysql的端口
--port=3306
echo "$0 $ARG: mysql started at port 3306"
vim /opt/gitlab-6.6.5-0/apps/gitlabci/htdocs/config/database.yml
port: 3306 修改端口號
redis默認端口的修改
vim /opt/gitlab-6.6.5-0/redis/etc/redis.conf
port 6379
vim /opt/gitlab-6.6.5-0/redis/scripts/ctl.sh
REDIS_PORT=6379
REDIS_PORT=6379
==================================================================================
vim /opt/gitlab-6.6.5-0/apps/gitlab/htdocs/config/gitlab.yml 郵件發送的配置
# Email address used in the "From" field in mails sent by GitLab
email_from: 15100126734@163.COM
# Email address of your support contact (default: same as email_from)
support_email: 15100126734@163.COM
## GitLab settings
gitlab:
## Web server settings (note: host is the FQDN, do not include http://)
host: 192.168.1.132 改成域名 例如:pepstack.com
port: 80
https: false
# Uncomment and customize the last line to run in a non-root path
# WARNING: We recommend creating a FQDN to host GitLab in a root path instead of this.
# Note that four settings need to be changed for this to work.
# 1) In your application.rb file: config.relative_url_root = "/gitlab"
# 2) In your gitlab.yml file: relative_url_root: /gitlab
# 3) In your unicorn.rb: ENV['RAILS_RELATIVE_URL_ROOT'] = "/gitlab"
# 4) In ../gitlab-shell/config.yml: gitlab_url: "http://127.0.0.1/gitlab"
# To update the path, run: sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production
#
relative_url_root: /gitlab
==================================================================================
vim /opt/gitlab-6.6.5-0/apps/gitlab/htdocs/config/environments/production.rb 發送郵件的配置
cp /opt/gitlab-6.6.5-0/apps/gitlab/htdocs/config/initializers/{smtp_settings.rb.sample,smtp_settings.rb}
vim /opt/gitlab-6.6.5-0/apps/gitlab/htdocs/config/initializers/smtp_settings.rb 郵件的配置文件
=====================================================================================================
vim /opt/gitlab-6.6.5-0/apps/gitlab/conf/httpd-app.conf 置于nginx后面使用
<Directory "/opt/gitlab-7.8.1-0/apps/gitlab/htdocs/public">
Options -MultiViews
AllowOverride All
<IfVersion < 2.3 >
Order allow,deny
Allow from all
</IfVersion>
<IfVersion >= 2.3>
Require all granted
</IfVersion>
SetEnv RAILS_RELATIVE_URL_ROOT "/gitlab"
PassengerEnabled on
PassengerAppRoot "/opt/gitlab-7.8.1-0/apps/gitlab/htdocs/"
<IfModule pagespeed_module>
ModPagespeedDisallow "*"
</IfModule>
PassengerUser git
PassengerGroup git
SetEnv MAGIC "/opt/gitlab-7.8.1-0/ruby/lib/ruby/gems/2.0.0/gems/charlock_holmes-0.6.9.4/ext/charlock_holmes/src/file-5.08/magic/magic.mgc"
SetEnv PATH "/opt/gitlab-7.8.1-0/python/bin:${PATH}"
</Directory>
PassengerPreStart http://127.0.0.1:80/gitlab
不同之處在于:
SetEnv RAILS_RELATIVE_URL_ROOT "/gitlab"
PassengerPreStart http://127.0.0.1:80/gitlab
vim /opt/gitlab-6.6.5-0/apps/gitlab/gitlab-shell/config.yml
gitlab_url: "http://192.168.1.132:80/" 改成 http://pepstack.com/ 改成域名,和上面gitlab.yml中的
host保持一致
vim /opt/gitlab-6.6.5-0/apps/gitlabci/htdocs/config/database.yml 定義數據庫的密碼和用戶名
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: bitnami_gitlabci
pool: 5
username: bitnami
password: "1a36ddf4bb"
# host: localhost
socket: /opt/gitlab-6.6.5-0/mysql/tmp/mysql.sock
port: 3306
# socket: /tmp/mysql.sock

浙公網安備 33010602011771號