1. Prepare in advance
1.1 Install dependent tools
yum install -y curl policycoreutils-python openssh-server
systemctl start sshd
systemctl enable sshd
1.2 Install Postfix mail server
#安装 postfix
yum install -y postfix
#启动 postfix 并设置为开机启动
systemctl enable postfix
systemctl start postfix
1.3 Turn off the firewall
systemctl stop firewalld
systemctl disable firewalld
2. Installation
2.1 Add domestic gitlab mirror source
The --no-check-certificate parameter means not to check the ssl certificate
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-13.1.2-ce.0.el7.x86_64.rpm --no-check-certificate
Install
rpm -ivh gitlab-ce-13.1.2-ce.0.el7.x86_64.rpm
2.2 Modify the configuration file
Change the port number to 8081
2.3 Login
Account: root
Password: lgblgblgb (this is the password I set, it does not need to be the same)
Check the password in the file /etc/gitlab/initial_root_password. If the file does not exist, the page will guide you to change the new root password directly, so you don’t need to check it.
cat /etc/gitlab/initial_root_password
2.4 Related commands
gitlab-ctl start // 启动所有 gitlab 组件;
gitlab-ctl stop // 停止所有 gitlab 组件;
gitlab-ctl restart // 重启所有 gitlab 组件;
gitlab-ctl status // 查看服务状态;
gitlab-ctl reconfigure // 刷新配置文件;
vim /etc/gitlab/gitlab.rb // 修改默认的配置文件;
gitlab-rake gitlab:check SANITIZE=true --trace // 检查gitlab;
gitlab-ctl tail // 查看日志;
2.5 Set Chinese
Click the avatar icon, select "Settings", select " Preferences " in the "Perferences" column, pull down to find the "Localization" area, change the "English" option to "Chinese, Simplifoed-Simplified Chinese", and click "Save changes".
3. Upload java project
condition:
The host has installed jdk and idea
The host has installed git
The host machine has a complete test project that can be uploaded
2.1 win10 install jdk1.8 and idea2019
2.2 install git
2.3 idea to create a java project
2.4 Check time server
date #在giatlab服务器终端执行,如果时间为北京时间进行下一步,如果是美国时间,先安装时间同步服务。
yum -y install chrony
cp -a /etc/chrony.conf /etc/chrony.conf.bak
sed -i 's/server/#server/g' /etc/chrony.conf
sed -i '/#server 3.centos.pool.ntp.org iburst/a\server ntp1.aliyun.com iburst' /etc/chrony.conf
systemctl restart chronyd
systemctl enable chronyd
systemctl enable chronyd #重启gitlab
2.5 The Gitlab administrator creates a new LuoGuiBin user
Create a new GuoGuiBin account under the root user
Fill in the information, email is required
2.6 gitlab new warehouse
Note that you need to log in to change the newly created LuoGuiBin account,
2.7 Set user and mailbox, get ssh key
Right-click on the host's project folder E:\java\java_test, select "Git Bash Here", and a pop-up window will appear. Be careful not to go into the project folder.
After changing the user and mailbox, there will be no prompt after entering the command, indicating that the command is executed successfully.
git config --global user.name “xxx”
git config --global user.email “[email protected]”
ssh-keygen -t rsa -C “[email protected]” #连按三次enter获得秘钥
After entering the .ssh folder, open the id_rsa.pub file with Notepad, copy it, and add the SSH key in Gitlab.
有些博客使用ssh -T [email protected]测试是否成功,即使失败也不影响,这张图就是失败效果。
2.8初始化init
git init
出现提示后文件夹会生成一个.git的隐藏文件夹,且会出现(master)分支。
克隆仓库地址
#git remote add origin 仓库地址
git remote add origin http://192.168.136.51:8081/LuoGuiBin/hello_world.git
ip、端口、用户名可能会不同,需要留意自己的。
我现在以file.txt为例子,
上传前file.txt内容为123。
2.9开始上传
2.9.1上传测试file
file原本的内容三123,将file更改成12345,上传gitlab,查看是否上传成功。
git status #查看提交状态
git add file.txt
#该文件添加入track中,使用git add . 命令可以将当前文件夹下的所有文件添加到stack中。
git commit -m "change_file_12345" #上传注释
git push -u origin master
再次查看gitlab上的file.txt文件,已经更新成12345,上传完成,其他项目文件夹上传都是相同的步骤。