官網(wǎng):The DevSecOps Platform | GitLab
1.安裝gitlab軟件:
-
安裝相關(guān)依賴:
yum install -y policycoreutils policycoreutils-python openssh-server open-clients postfix ca-certificates # ca-certificates: 不安裝下載gitlab包報錯--no-check-certificate
-
設(shè)置postfix開機自啟,并啟動,postfix支持gitlab發(fā)信功能
systemctl start postfix && systemctl enable postfix
-
下載給gitlab包
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-12.4.2-ce.0.el7.x86_64.rpm
-
安裝rpm包:
rpm -ivh gitlab-ce-12.4.2-ce.0.el7.x86_64.rpm
-
修改gitlab的配置:/etc/gitlab/gitlab.rb
# 修改gitlab訪問地址和端口,默認為80,我們改為82 sed -i "s/^external_url.*/external_url 'http:\/\/192.168.66.201:82'/" /etc/gitlab/gitlab.rb
# 第一次修改,nginx監(jiān)聽端口 sed -i "s/^# nginx\['listen_port'\].*/nginx\['listen_port'\] = 82/" /etc/gitlab/gitlab.rb # 后面的修改,nginx監(jiān)聽端口 sed -i "s/^nginx['listen_port'].*/nginx['listen_port'] = 82/" /etc/gitlab/gitlab.rb
# 重新加載配置 gitlab-ctl reconfigure
-
重啟gitlab服務(wù):
gitlab-ctl restart
-
登陸頁面:http://192.168.174.201:82,修改root用戶密碼
-
使用root用戶登陸:
2.配置ssh公鑰:
ssh-keygen -t rsa -b 1024 -C "用戶名/郵箱"
# 如果不指定用戶名和郵箱,將默認使用主機的用戶名和主機名
# ssh-keygen - 生成、管理和轉(zhuǎn)換認證密鑰,t制定類型
# RSA
# window:C:/用戶/user/.ssh/id_rsa.pub公鑰文件,linux:~/.ssh/id_rsa.pub公鑰文件
cat ~/.ssh/id_rsa.pub
3.安裝和配置git:
-
安裝:
yum install -y git
-
配置:
git config --global user.name "qv123" git config --global user.email "qv1095322098@163.com"
# 查看 git config --global user.name git config --global user.email
4.上傳項目:
1.方式一:創(chuàng)建本地項目推送
-
-
初始化項目。將項目添加到工作區(qū),或者直接拉取空倉庫:
cd ~/my_hexo && git init
-
添加遠程倉庫路徑:倉庫地址是服務(wù)器IP
git remote add origin git@192.168.174.201:qv123_group/my_hexo.git # origin遠端名稱 # 查看命令幫助:git remote -help
-
查看遠程倉庫得名稱和地址:
git remote -v show
-
將項目從工作區(qū)添加到暫存區(qū):
git add .
-
將項目從暫存區(qū)提交到本地倉庫:(這里必須配置用戶名和郵箱地址)
git commit -m "one commit"
-
查看本地分支:文章來源:http://www.zghlxwxcb.cn/news/detail-771283.html
git branch
-
拉取一下遠程的空倉庫:
# 最好拉取一下空倉庫,不然可能導(dǎo)致推送錯誤 git pull -u origin master
# 報錯 To git@192.168.174.201:qv123_group/my_hexo.git ! [rejected] ? ? ? master -> master (fetch first) error: failed to push some refs to 'git@192.168.174.201:qv123_group/my_hexo.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first merge the remote changes (e.g., hint: 'git pull') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. [root@gitlab-server qv1234.github.io-master]# git pull --rebase origin fatal: 'origin' does not appear to be a git repository fatal: Could not read from remote repository. ? Please make sure you have the correct access rights and the repository exists.
-
推送到遠程倉庫:
git push -u origin master # master是分支
-
2.方式二:(推薦)
-
-
直接克隆空倉庫:
git clone git@192.168.174.201:qv123_group/my_hexo.git cd my_hexo
-
查看遠程倉庫得名稱和地址:
[root@gitlab-server my_hexo]# git remote -v show origin git@192.168.174.201:qv123_group/my_hexo.git (fetch) origin git@192.168.174.201:qv123_group/my_hexo.git (push)
-
將項目從工作區(qū)添加到暫存區(qū):
git add . --all
-
將項目從暫存區(qū)提交到本地倉庫:(這里必須配置用戶名和郵箱地址)
git commit -m "one commit"
-
查看本地分支:
git branch
-
推送到遠程倉庫:文章來源地址http://www.zghlxwxcb.cn/news/detail-771283.html
git push -u origin master # master是分支
-
到了這里,關(guān)于使用gitlab在服務(wù)器上搭建私服git倉庫,并且上傳項目的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!