使用gitlab在服務器上搭建私服git倉庫并上傳項目的操作方法
官網:The DevSecOps Platform | GitLab
1.安裝gitlab軟件:
安裝相關依賴:
yum install -y policycoreutils policycoreutils-python openssh-server open-clients postfix ca-certificates # ca-certificates: 不安裝下載gitlab包報錯--no-check-certificate
設置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服務:
gitlab-ctl restart
登陸頁面:http://192.168.174.201:82,修改root用戶密碼
使用root用戶登陸:
2.配置ssh公鑰:
ssh-keygen -t rsa -b 1024 -C "用戶名/郵箱" # 如果不指定用戶名和郵箱,將默認使用主機的用戶名和主機名 # ssh-keygen - 生成、管理和轉換認證密鑰,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
添加遠程倉庫路徑:倉庫地址是服務器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"
查看本地分支:
git branch
拉取一下遠程的空倉庫:
# 最好拉取一下空倉庫,不然可能導致推送錯誤 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
推送到遠程倉庫:
git push -u origin master # master是分支
到此這篇關于使用gitlab在服務器上搭建私服git倉庫,并且上傳項目的文章就介紹到這了,更多相關gitlab在服務器上搭建私服git倉庫內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
CentOS 6.3 Rsync客戶端與Win2003 cwRsyncServer服務端實現數據同步
這篇文章主要介紹了CentOS 6.3 Rsync客戶端與Win2003 cwRsyncServer服務端實現數據同步,需要的朋友可以參考下2015-07-07Microi 吾碼低代碼解鎖服務器虛擬化無限潛能(最新推薦)
在當今數字化轉型加速的時代背景下,服務器虛擬化技術已成為信息技術領域的關鍵驅動力之一,這篇文章主要介紹了Microi 吾碼低代碼解鎖服務器虛擬化無限潛能(最新推薦),需要的朋友可以參考下2024-12-12kubernetes使用kubeadm創(chuàng)建集群實操教程(全)
安裝kubernetes的方式,分別是kubeadm引導集群、kOps、Kubespray,本文采用kubeadm引導集群的方式,主要運用了安裝kubeadm、對kubeadm進行故障排查、使用kubeadm創(chuàng)建集群,目標是要安裝單個控制平面的Kubernetes集群,在集群上安裝Pod網絡,以便Pod可以相互連通2024-06-06windows服務器之win2003,win2008R2,win2012,win2016,win2019系統(tǒng)版本區(qū)別
windows服務器版有window2003,windows server2008,windows server2012 R2,windows server2016,windows 2019他們有什么不同,如何選擇適合自己的服務器系統(tǒng),需要的朋友可以參考下2020-02-02