Programming language :
# vim hello.c
#include <stdio.h>
int main(void){
printf("Hello World!\n");
return 0;
}
# gcc -o hello hello.c
# ./hello
graph LR
dev( The programmer )-- push -->git(git server)
ci(jenkins)-- Pull -->git
app( application server )-- Pull -->ci
Hosting plan :
All in 192.168.4.5 Implemented on .
SCM: Software configuration management , Such as git / svn
# Basic configuration
[[email protected] ~]# yum install -y git
# Basic configuration of environment
[[email protected] ~]# git config --global user.name "Mr.Zhang"
[[email protected] ~]# git config --global user.email "[email protected]"
[[email protected] ~]# git config --global core.editor vim
[[email protected] ~]# git config --list
[[email protected] ~]# cat ~/.gitconfig
git Three important areas of
graph LR
work( work area )--git add-->stage( Temporary storage area )
stage--git commit-->ver( Version Library )
[[email protected] ~]# git init mytest
Initialize empty Git Version Library in /root/mytest/.git/
[[email protected] ~]# ls -A mytest/
.git
[[email protected] ~]# mkdir myweb
[[email protected] ~]# cd myweb/
[[email protected] myweb]# echo '<h1>my web site</h1>' > index.html
[[email protected] myweb]# ls
index.html
[[email protected] myweb]# git init .
Initialize empty Git Version Library in /root/myweb/.git/
[[email protected] myweb]# ls -A
.git index.html
Join the trace
[[email protected] myweb]# git status
# In a branch master
#
# Initial submission
#
# Untracked files :
# ( Use "git add <file>..." To include content to submit )
#
# index.html
Submission is empty , But there are files that have not been tracked ( Use "git add" Set up tracking )
[[email protected] myweb]# git status -s
?? index.html # A question mark indicates that the status is unknown
# establish .gitignore Ignore files that you do not want to add to the repository
[[email protected] myweb]# vim .gitignore
*.swp
.gitignore
# Add all files in the directory to the trace
[[email protected] myweb]# git add .
[[email protected] myweb]# git status
# In a branch master
#
# Initial submission
#
# Changes to be submitted :
# ( Use "git rm --cached <file>..." Get out of the staging area )
#
# A new file : index.html
#
[[email protected] myweb]# git status -s
A index.html
Get out of the staging area
[[email protected] myweb]# git rm --cached index.html
rm 'index.html'
[[email protected] myweb]# git status -s
?? index.html
Confirm to the version library
[[email protected] myweb]# git add .
[[email protected] myweb]# git status -s
A index.html
[[email protected] myweb]# git commit
[[email protected] myweb]# git status
# In a branch master
No documents to submit , Clean work area
Modify file , Continue to submit
[[email protected] myweb]# echo '<h2>2nd version</h2>' >> index.html
[[email protected] myweb]# git status
# In a branch master
# Changes that have not been staged for submission :
# ( Use "git add <file>..." Update content to submit )
# ( Use "git checkout -- <file>..." Discard workspace changes )
#
# modify : index.html
#
The modification has not been added to the submission ( Use "git add" and / or "git commit -a")
[[email protected] myweb]# git status -s
M index.html
[[email protected] myweb]# git add .
[[email protected] myweb]# git commit -m "2nd version"
[[email protected] myweb]# git status
# In a branch master
No documents to submit , Clean work area
Delete the workspace file and restore
[[email protected] myweb]# cp /etc/hosts .
[[email protected] myweb]# git status -s
?? hosts
[[email protected] myweb]# git add .
[[email protected] myweb]# git commit -m "add hosts"
[master 3145cda] add hosts
[[email protected] myweb]# git status
# In a branch master
No documents to submit , Clean work area
[[email protected] myweb]# rm -rf *
[[email protected] myweb]# git status
# In a branch master
# Changes that have not been staged for submission :
# ( Use "git add/rm <file>..." Update content to submit )
# ( Use "git checkout -- <file>..." Discard workspace changes )
#
# Delete : hosts
# Delete : index.html
#
The modification has not been added to the submission ( Use "git add" and / or "git commit -a")
[[email protected] myweb]# git checkout -- *
[[email protected] myweb]# ls
hosts index.html
Change of name 、 Delete the files in the version library
[[email protected] myweb]# cp /etc/passwd .
[[email protected] myweb]# git add .
[[email protected] myweb]# git commit -m "add passwd"
[[email protected] myweb]# git mv passwd mima
[[email protected] myweb]# git status
# In a branch master
# Changes to be submitted :
# ( Use "git reset HEAD <file>..." Get out of the staging area )
#
# rename : passwd -> mima
#
[[email protected] myweb]# git commit -m "mv passwd mima"
[master e84a1ea] mv passwd mima
1 file changed, 0 insertions(+), 0 deletions(-)
rename passwd => mima (100%)
[[email protected] myweb]# git rm hosts
rm 'hosts'
[[email protected] myweb]# ls
index.html mima
[[email protected] myweb]# git status
# In a branch master
# Changes to be submitted :
# ( Use "git reset HEAD <file>..." Get out of the staging area )
#
# Delete : hosts
#
[[email protected] myweb]# git commit -m "rm hosts"
[master 3c281fc] rm hosts
1 file changed, 260 deletions(-)
delete mode 100644 hosts
[[email protected] myweb]# git status
Switch to the specified submission location
[[email protected] myweb]# git log # View the submission history
# Switch to historical commit
[[email protected] myweb]# git checkout 92385f5778c954d683c5d32537cf41d4da8c07e6
# Return to the nearest location
[[email protected] myweb]# git checkout master
Branch management
# View all branches
[[email protected] myweb]# git branch
* master
# Create a branch , Make sure the work area is clean
[[email protected] myweb]# git branch b1
[[email protected] myweb]# git branch
b1
* master # * The sign indicates the current branch
# Switch branches
[[email protected] myweb]# git checkout b1
Switch to branch 'b1'
[[email protected] myweb]# git branch
* b1
master
# Execute commit in the current branch
[[email protected] myweb]# cp /etc/motd /etc/redhat-release .
[[email protected] myweb]# git add .
[[email protected] myweb]# git commit -m "add motd rh-release"
# Merging branches
[[email protected] myweb]# git checkout master
Switch to branch 'master'
[[email protected] myweb]# ls
index.html mima
[[email protected] myweb]# git merge b1
[[email protected] myweb]# ls
index.html mima motd redhat-release
# Delete the branch
[[email protected] myweb]# git branch -d b1
Branch deleted b1( For the 0639c44).
--- After creating the virtual machine , install docker Then restart the service
# systemctl start docker
# systemctl enable docker
# docker load < gitlab_zh.tar # Import gitlab Chinese mirror
because gitlab The container needs to be 22 port , Modify the ssh port
[[email protected] ~]# vim /etc/ssh/sshd_config
Port 2022
[[email protected] ~]# systemctl restart sshd
# When logging out and connecting again , Port number needs to be specified
[[email protected] phase5]# ssh -p2022 192.168.1.137
Start the container
[[email protected] ~]# docker run -d -h gitlab --name gitlab -p 443:443 -p 80:80 -p 22:22 --restart always -v /srv/gitlab/config:/etc/gitlab -v /srv/gitlab/logs:/var/log/gitlab -v /srv/gitlab/data:/var/opt/gitlab gitlab_zh:latest
# gitlab Containers require more resources , Therefore, a long startup time is required
[[email protected] ~]# docker ps # The status is displayed as healthy Only when , It'll take a few minutes
Create a devops Group , Type disclosure .
Create user . You cannot set a password when creating a new user , But you can set the password by clicking the edit user interface .
Create project myweb, Type disclosure , As group devops establish . Authorize the new user to be its primary programmer .
[[email protected] myweb]# ssh-keygen -t rsa -C "[email protected]" -b 4096
[[email protected] myweb]# cat ~/.ssh/id_rsa.pub
# Click on gitlab In the personal settings of the user's Avatar , The left navigation bar has SSH secret key , Paste the generated public key code , You can upload code without secret .
# Push code
[[email protected] myweb]# git remote rename origin old-origin
# The following errors can be ignored
error: Cannot rename configuration section 'remote.origin' To 'remote.old-origin'
[[email protected] myweb]# git remote add origin [email protected]:devops/myweb.git
[[email protected] myweb]# git push -u origin --all
[[email protected] myweb]# git push -u origin --tags
tag Mark
[[email protected] myweb]# git tag 1.0
[[email protected] myweb]# cp /etc/selinux/config .
[[email protected] myweb]# git add .
[[email protected] myweb]# git commit -m "add selinux config"
[[email protected] myweb]# git tag 2.0
[[email protected] myweb]# git tag
1.0
2.0
[[email protected] myweb]# git push
[[email protected] myweb]# git push --tag
Download code
[[email protected] tmp]# git clone http://192.168.1.137/devops/myweb.git