Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Set up git server, install gitlab, backup and restore using gitlab and gitlab

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

First, set up git server

After all, github is public, and private warehouses cost money. So we can find a way to build a private one that is only used by our own company. Gitlab is a good choice. Before I introduce it, let's talk about the command line git server.

To find a server, first install git, where a new machine is opened to install git.

# yum install-y git

Add git users and set shell to / usr/bin/git-shell in order to prevent git users from logging in remotely

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

The first step is to put the public key on the client in the git server / home/git/.ssh/authorized_keys file.

Create an authorized_keys file and change the owner, group, and permissions to store the public key on the client machine.

# mkdir .ssh # touch / authorized_keys# chown-R git:git .ssh # chmod 600.ssh / authorized_ Keys [root @ MRX ~] # cat .ssh / id_rsa.pub / / copy [root@wbs git] # vi .ssh / authorized_keys / / paste the public key on the first machine into the file just created on the new machine (server) [root@MRX ~] # ssh git@192.168.197.133 to the client to try logging in Seeing such a prompt means that there is no problem, indicating that the verification is successful. The authenticity of host '192.168.197.133 (192.168.197.133)' can't be established.ECDSA key fingerprint is SHA256:PZXNkWqC/6h5hUQYkfOM9AMj82OTskLMIB4qLkgeajU.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)? YesWarning: 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.

Define a directory on the server side to store the git repository, such as / data/gitroot

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

/ / A naked warehouse is created, which does not have a workspace, because the Git repository on the server is purely for sharing, so users are not allowed to log in directly to the server to change the workspace, and the Git warehouse on the server usually ends with .git.

# chown-R git.git sample.git

The above operations are done on the git server. Usually, the git server does not require developers to log in to modify the code, it just acts as a server, just like github, the usual operations are done on our own pc.

Clone a remote repository on the client (self-pc)

Git clone git@ip:/data/gitroot/sample.git# git clone git@192.168.197.133:/data/gitroot/sample.git is cloning to 'sample'...warning: you seem to have cloned an empty version library.

At this point, you can generate a sample directory under the current directory, and this is the remote repository we cloned. When you go inside, you can develop some code, and then push it remotely.

# cp / etc/init.d/mysqld. [root@MRX sample] # lsmysqld [root@MRX sample] # git add. [root@MRX sample] # git commit-m "add new file" [master (1d1a5a0) 1d1a5a0] add new file 1 file changed, 378 insertions (+) create mode 100755 mysqld [root@MRX sample] # git push / / because it is a bare warehouse with no branches, it is pushed directly, and you do not know which branch it is remotely, so you need to specify a branch. Warning: push.default is not set, its default value will be changed from 'matching'' to 'simple'' in Git 2.0. To no longer display this information and maintain the current usage habits after its default value is changed, make the following settings: git config-- global push.default matching if you want to stop displaying this information and adopt the new usage habits from now on, set: git config-- global push.default simple see 'git help config' and look for' push.default' for more information. (the 'simple' mode was introduced by Git version 1.7.11. If you sometimes want to use an older version of Git, to maintain compatibility, use '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 unexpectedlyerror: cannot push some references to the 'git@192.168.197.133:/data/gitroot/sample.git'# git push origin master / / specified master branch. You can git push directly the second time. Counting objects: 3, done.Delta compression using up to 2 threads.Compressing objects: 100% (2 delta 2), done.Writing objects: 100% (3 delta 3), 3.84 KiB | 0 bytes/s, done.Total 3 (delta 0) Reused 0 (delta 0) To git@192.168.197.133:/data/gitroot/sample.git * [new branch] master-> master # cd / tmp # git clone git@192.168.197.133:/data/gitroot/sample.git # ls sample/1.txt mysqld [root@MRX tmp] # cd sample/ [root@MRX sample] # vim 1.txt / / A pair of file content changes # git add 1.txt# git commit-m "ch 1.txt" # git push# cd / root/sample / / if another user is also connected Then git pull can pull down the changes # git pull / / what you just changed is pulled down.

This is a very simple way to build a git server.

Second, install gitlab

In addition to self-built servers, you can also use online code hosting platforms, such as coding.net, Code City, and Code Cloud, which are good code management platforms in China, which are easy to worry and do not need maintenance.

In addition to this method, you can also build a code management platform for web interface browsing management control, preferably using gitlab.

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

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

The server memory is required to be no less than 2g. Due to the slow download of the official image, a domestic image is used here, which is a server of Tsinghua University.

# vim / etc/yum.repos.d/gitlab.repo / / add the following [gitlab-ce] name=Gitlab CE Repositorybaseurl= https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/gpgcheck=0enabled=1# yum install-y gitlab-ce# gitlab-ctl reconfigure / / this command will start all the services involved in gitlab. ... Chef Client finished, 524/1419 resources updated in 14 minutes 08 secondsgitlab Reconfigured!

At this point, gitlab is installed, although it is relatively easy to install, but if something goes wrong, it will be difficult to do change and maintenance, so this gitlab server suggests not to do other applications, just run the git server. Usually do a good backup of data, gitlab has official tools to back up data.

Stop Nginx before installing gitlab.

# netstat-lntp / / check the listening port. Both lines are generated by gitlab. Tcp 0 0127.0.0.1 LISTEN 1439/puma 8080 0.0.0.0 * LISTEN 1621/unicorn master tcp 0 0127.0.0.1 LISTEN 1439/puma 3.12.0

# gitlab-ctl stop/restart/start/status / / status, check the status

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

Browser access gitlab, enter ip to access, before access, check to see if there are any iptables rules, if so, add a port 80.

The default administrator root, which has no password, allows us to define a password.

Once set up, you can sign in.

Third, use gitlab

It can also be accessed with a domain name. If you want to use a domain name, you must first find out who provides the web service on this server. For example, the location of the configuration file of Nginx,Nginx contains nginx.conf in / var/opt/gitlab/nginx/conf/, which is the main configuration file. Gitlab-http.conf is the corresponding gitlab-related configuration file. If you want to bind a domain name or change the listening port, you can edit this configuration file.

# vim / var/opt/gitlab/nginx/conf/gitlab-http.confserver {listen *: 80; / / define the listening port server_name gitlab.example.com; / / define the domain name

If this server does not have to run other services, only a gitlab, then do not need to move at all.

First use the browser to enter gitlab, first create a group, customize the group name, and set the permission to private Private.

To create another project, you can select the group you just created and set the project name.

After the creation is complete, a "You won't be able to pull or push project code via SSH until you add an SSH key to your profile" is displayed at the top, saying that no ssh key has been created.

Create ssh key: at the exit point of the avatar settings, you can see the ssh keys on the left. Put the public key (/ root/.ssh/id_rsa.pub) in it and you can create it.

Create a user: click the small wrench (Admin Area), new user, user name zhangsan,email:zhangsan@111.com above, and the password setting prompt will send the link to set the password to the user's mailbox to create. After the creation is completed, click the Edit at the top right to edit the settings password, and then save the settings. Then log in to zhangsan, and the first time you log in, you will be asked to set a new password.

IV. Gitlab backup and recovery

Gitlab backup

# gitlab-rake gitlab:backup:create

The backup directory is in / var/opt/gitlab/backups

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

After the backup, you can see the file name, timestamp + date + version number from this sentence.

When gitlab recovery stops service and recovers data, the version of the data needs to be the same as that of the current gitlab.

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

Unicorn is a ruby-related webserver,sidekiq that is a message queue and is also based on ruby. The purpose of stopping these two services is not to make changes to the data for the time being.

# gitlab-rake gitlab:backup:restore BACKUP=1569829062_2019_09_30_12.3.1 (here is a number, that is, the prefix of the backup file)

Restart the service gitlab-ctl star

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report