Fourth, set up git server, install gitlab, use gitlab, gitlab backup and recovery

First, set up git server

github, after all, public, and private warehouses have to spend money. So we can think of ways to build a private, only your company uses. Gitlab is a good choice. Before introducing it to say something about the command line git server

Looking for a server, you must first install git, here we opened a new machine installed git.

# yum install -y git

Git add users, and set the shell to / usr / bin / git-shell, the purpose is to let users remotely log in git

# useradd -s /usr/bin/git-shell git 
# cd /home/git

First, the public key on the client should put on git server /home/git/.ssh/authorized_keys file.

Create authorized_keys file and change the owner, is a group, and permissions for the public key stored on the client machine.

# mkdir .ssh
# touch .ssh/authorized_keys
# chown -R git:git .ssh
# chmod 600 .ssh/authorized_keys
[Root @ MRX ~] # cat .ssh / id_rsa.pub // public key on the first copying machine
File [root @ wbs git] # vi .ssh / authorized_keys // pasted into (server) on the new machine just created
[Root @ MRX ~] # ssh [email protected] client attempts to log in to look, see this prompt represents no problem, indicating that the validation is successful.
The authenticity of host '192.168.197.133 (192.168.197.133)' can't be established.
ECDSA key fingerprint is SHA256:PZXNkWqC/6h4hUQYkfOM9AMj82OTskLMIB4qLkgeajU.
ECDSA key fingerprint is MD5:99:19:04:c5:11:8d:94:ad:9a:86:40:b9:ad:b9:d4:8f.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.197.133' (ECDSA) to the list of known hosts.
fatal: Interactive git shell is not enabled.
hint: ~/git-shell-commands should exist and have read and execute access.
Connection to 192.168.197.133 closed.


Git repository definitions stored in the directory on the server, such as / data / gitroot

# mkdir /data/gitroot
# Cd / data / gitroot
# git init --bare sample.git

// creates a bare warehouse, bare warehouse area did not work, because Git repository on the server is simply to share, so let users log in directly to the server to change up the work area, and Git repository on the server usually end with .git .

# chown -R git.git sample.git

The above operation is done on the server git, git server usually does not require developers to modify the code to log in, it is only to act as a server role, like github, as usual operations are on our own to do pc .

On the client (your own pc) cloning a remote repository

git clone git@ip:/data/gitroot/sample.git
# git clone [email protected]:/data/gitroot/sample.git
Positive clones to 'sample' ...
warning: You seem to clone an empty repository.

At this point you can generate a sample directory in the current directory, this is what we cloned the remote repository. Into there, you can develop some code, then push to the remote.

# cp /etc/init.d/mysqld .
[root@MRX sample]# ls
mysqld
[root@MRX sample]# git add .
[root@MRX sample]# git commit -m "add new file"
[Master (root submit) 1d1a5a0] add new file
 1 file changed, 378 insertions(+)
 create mode 100755 mysqld
 
[Root @ MRX sample] # git push // Because it is a bare warehouse, which has no branches, direct push, remote branch do not know which one, so you need to specify a branch.
warning: push.default not set, its default value will Git 2.0 by the 'matching'
Review of 'simple'. To display this information and no longer maintain the current habits change after its default value,
The following settings:

  git config --global push.default matching

To display this information and no longer from now on adopt new habits, setting:

  git config --global push.default simple

See 'git help config' and look for 'push.default' for more information.
( 'Simple' mode introduced by Git 1.7.11 version. If you sometimes want to use older versions of Git,
To maintain compatibility with the 'current' instead of 'simple' mode)

No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
fatal: The remote end hung up unexpectedly
error: can not push some of the references to '[email protected]: /data/gitroot/sample.git'

# Git push origin master // specify the master branch, and push them up a second time when you can directly git push up.
Counting objects: 3, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 3.84 KiB | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To [email protected]:/data/gitroot/sample.git
 * [new branch]      master -> master
 
 # cd /tmp
 # git clone [email protected]:/data/gitroot/sample.git
 # ls sample/
1.txt  mysqld
[root@MRX tmp]# cd sample/
[Root @ MRX sample] # vim 1.txt // file content changes
# git add 1.txt
# git commit -m "ch 1.txt"
# git push
# Cd / root / sample // if another user is also connected, you can change the git pull to pull down
Content # git pull // just changed pulled down

This is a very simple method to build git server.


Second, the installation gitlab

In addition to self-built server, you can also use the online code hosting platform, such as coding.net, city code, the code cloud is relatively good domestic code management platform, more worry, no maintenance.

In addition to this method, it can be self-built a web browser interface management control of code management platform of choice for use gitlab.

gitlab official website https://about.gitlab.com/gitlab-com/

The official installation documentation https://about.gitlab.com/installation/?version=ce#centos-7 (ce / ee)

Server memory requirements no less than 2g, due to the relatively slow download official mirror, a mirror image of the country is used here, this image is a server Tsinghua University.

# Vim /etc/yum.repos.d/gitlab.repo // add the following
[Gitlab it]
name=Gitlab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
gpgcheck=0
enabled=1
# yum install -y gitlab-ce
# Gitlab-ctl reconfigure // This command will involve all gitlab the service starts up.
...
Chef Client finished, 524/1419 resources updated in 14 minutes 08 seconds
gitlab Reconfigured!

At this point, gitlab on the installation finished, although it is relatively easy to install, but if things go wrong, then do change the maintenance when there is a certain degree of difficulty, so that this gitlab server is not recommended to do other applications, just git server running on the line. Usually make a backup of data, gitlab have the tools provided by the official to back up data.

Before installing gitlab, first Nginx stopped.

# Netstat -lntp // listening port view, these two lines are gitlab generated.
tcp        0      0 127.0.0.1:8080          0.0.0.0:*               LISTEN      1621/unicorn master 
tcp        0      0 127.0.0.1:9168          0.0.0.0:*               LISTEN      1439/puma 3.12.0 (t

# Gitlab-ctl stop / restart / start / status // status, check the status of

# gitlab-ctl  status
run: alertmanager: (pid 2563) 10476s; run: log: (pid 1448) 10585s
run: gitaly: (pid 1407) 10586s; run: log: (pid 1406) 10586s
run: gitlab-exporter: (pid 1439) 10585s; run: log: (pid 1438) 10585s
run: gitlab-workhorse: (pid 1426) 10585s; run: log: (pid 1425) 10585s
run: grafana: (pid 1446) 10585s; same: log: (pid 1445) 10585s
run: logrotate: (pid 18743) 3379s; run: log: (pid 1434) 10585s
run: nginx: (pid 25804) 1s; run: log: (pid 1423) 10585s
run: node-exporter: (pid 1433) 10585s; run: log: (pid 1432) 10585s
run: postgres-exporter: (pid 1452) 10585s; run: log: (pid 1451) 10585s
run: postgresql: (pid 1409) 10586s; run: log: (pid 1408) 10586s // postgresql, database
run: prometheus: (pid 1450) 10585s; run: log: (pid 1447) 10585s
run: redis: (pid 1405) 10586s; run: log: (pid 1404) 10586s
run: redis-exporter: (pid 1442) 10585s; run: log: (pid 1441) 10585s
run: sidekiq: (pid 1415) 10586s; run: log: (pid 1414) 10586s
run: unicorn: (pid 1413) 10586s; run: log: (pid 1412) 10586s


Prior browser access gitlab, enter the ip access to, visit, first to see if there iptables rules, if any, plus a 80 port.

The default administrator root, no password, it will enable us to define a password.

1.png

After the set can sign in.


Third, the use gitlab

Can also be accessed using the domain name, the domain name if you want to visit, first to find out who is the web services offered on this server, such as Nginx, Nginx configuration file location in the / var / opt / gitlab / nginx / conf /, which there nginx.conf, which is the main configuration file; gitlab-http.conf is the corresponding gitlab related configuration files, if you want to bind a domain name, or change the listening port, you can edit the configuration file.

# vim /var/opt/gitlab/nginx/conf/gitlab-http.conf
server {
  listen *: 80; // define the listening port

  server_name gitlab.example.com;      //定于域名

这个服务器如果不用跑别的服务,仅仅只一个gitlab,那完全不用动。

先用浏览器进入gitlab,先创建一个组,自定义组名,并设置权限为私有的Private。

2.png

再创建一个项目,可以选择刚才创建的组,并设置项目名。

3.png

创建完成后,最上面显示了一条“You won't be able to pull or push project code via SSH until you add an SSH key to your profile”,说没有创建任何的ssh key。

创建ssh key:在头像出点settings,左边可以看到ssh keys,将公钥(/root/.ssh/id_rsa.pub)放进去就可以创建了。

创建用户:点击上方的小扳手(Admin Area),new user,用户名zhangsan,email:[email protected],密码设置提示会将设置密码的链接发送给用户邮箱,创建。创建完成后,点击右上方的Edit可以编辑设置password,设置完保存。然后登陆zhangsan,第一次登录时,会让你设置新密码。


四、gitlab备份和恢复

gitlab备份

# gitlab-rake gitlab:backup:create

备份目录在/var/opt/gitlab/backups

Creating backup archive: 1569829062_2019_09_30_12.3.1_gitlab_backup.tar ... done

备份完后可以从这一句看到文件名字,时间戳+日期+版本号。


gitlab 恢复  先停服务   恢复数据时,数据的版本需要和当前gitlab的版本一致。

# gitlab-ctl stop unicorn ; gitlab-ctl stop sidekiq

is associated with a ruby ​​unicorn webserver, sidekiq is a message queue, also based on the ruby. Stop these two services aim is to do and not to alter it.

# Gitlab-rake gitlab: backup: restore BACKUP = 1569829062_2019_09_30_12.3.1 (this is a number, i.e., the prefix of the backup file)

And then start the service gitlab-ctl star

Guess you like

Origin blog.51cto.com/13576245/2448895