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

Gitlab migration practice

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Due to the network adjustment of the office environment, it is planned to move gitlab from the intranet computer room to the public cloud in the near future. A simple record of the migration process has been made, which I hope will be helpful to all of you.

Old server Acentos6.910.1.2.10gitlab-ce-8.16.0-ce.0.el6.x86_64 new server Bcentos6.9192.168.100.10gitlab-ce-8.16.0-ce.0.el6.x86_64

First, the basic ideas of migration

1. Purchase public CVM, bring your own public network IP, and join the onlyyou security group.

2. The security group opens port 80 (all office network exits, v tunnel / road n (public)), port 9000 (all office network exits, v tunnel / road n (public), and Jks, other test service public network IP).

3. Build the same version of Git service.

4. Issue an announcement to suspend the git service

5. Import the full backup into the new Git.

6. Use iptables to map port 9000 to 3303 (iptables-t nat-A PREROUTING-p tcp-- dport 9000-j REDIRECT-- to-ports 3303). (note: 9000 is the remote port of the previous frp, and 3303 is the ssh port of server B)

7. DNS parsing (git.bd.com): delete the resolution record of the office network DNS, and modify the public network DNS resolution record to server B public network IP.

II. Operation steps

2.1, backup

1. Backup git data in server A, specific backup operation commands

[root@serverA ~] # gitlab-rake gitlab:backup:create STRATEGY=copy

Backup files are under / var/opt/gitlab/backups/, assuming that the prepared files are 1568659149_2019_03_17_10.6.4_gitlab_backup.tar

Note: any operation on gitlab should be prohibited during backup.

2.2. Build gitlab on a new server

To make backups available, use the same version on the new server as the original server. If the old server is the latest version, you can install it directly using yum on the new server. If you install the latest version, you can install `[ root@serverB ~] # yum install gitlab- CE` in the following way. I used the same version specified for installation. Because it is not the latest version, you need to download the required version from https://packages.gitlab.com/gitlab/gitlab-ce, here because the installation system is centos6 So download the el6 version or use the yum source file `[root@serverB ~] # cat / etc/yum.repos.d/gitlab_gitlab- ce.repo` [gitlab_gitlab-ce] name=gitlab_gitlab-ce baseurl= https://packages.gitlab.com/gitlab/gitlab-ce/el/6/$basearch repo_gpgcheck=1 gpgcheck=0 enabled=1 gpgkey= https://packages.gitlab.com/gpg.key sslverify=1 sslcacert=/etc/pki/tls in server A / certs/ca-bundle.crt [gitlab_gitlab-ce-source] name=gitlab_gitlab-ce-source baseurl= https://packages.gitlab.com/gitlab/gitlab-ce/el/6/SRPMS repo_gpgcheck=1 gpgcheck=0 enabled=1 gpgkey= https://packages.gitlab.com/gpg.key sslverify=1 sslcacert=/etc/pki/tls/certs/ca-bundle.crt 2. Install git [root@serverB ~] # `yum-y install Git` 3. Install gitlib [root@serverB ~] # ```EXTERNAL_URL= "http://gitlab.example.com" yum install-y gitlab-ce-10.6.4-ce.0.el6.x86_64 ````4, modify the configuration and install it Modify all the http://gitlab.example.com on / etc/gitlab/gitlab.rb external_url 'http://gitlab.example.com' to the gitlab address you want to use. Modify the required port in / var/opt/gitlab/nginx/conf/gitlab-http.conf and add include / var/opt/gitlab/nginx/conf/custom.conf in / var/opt/gitlab/nginx/conf/nginx.conf. The port is to be consistent with the original environment, for example, the original one is 54444, and then custom.conf is a self-defined whitelist, such as: allow 110.110.110.110; deny all; server {server_name default; listen *: 80 Location / {proxy_pass http://127.0.0.1:54444;}} reconfigure Enhancement [root@serverB ~] # gitlab-ctl reconfigure

2.3. Copy backup

Copy the backup from server A to the new server B under / var/opt/gitlab/backups/, and do this from server A.

[root@serverA ~] # scp / var/opt/gitlab/backups/1568659149_2019_03_17_10.6.4_gitlab_backup.tar root@192.168.100.10:/var/opt/gitlab/backups/ modify backup file permissions Avoid insufficient permissions when restoring backups [root@serverB ~] # chown git:git 1568659149_2019_03_17_10.6.4_gitlab_backup.tar [root@serverB ~] # chmod 777 1568659149_2019_03_17_10.6.4_gitlab_backup.tar

2.4. Restore backup

Refer to the official document https://docs.gitlab.com/ce/raketasks/backup_restore.html#restore-for-omnibus-installations for this step.

1. Stop the data phase service

[root@serverB] # gitlab-ctl stop unicorn [root@serverB] # gitlab-ctl stop sidekiq [root@serverB] # gitlab-ctl status 2. Restore backup the file name copied above is used at the end of the command here, but not the full name. Take the name before _ gitlab. At the beginning, you will be prompted to enter yes, and you can enter [root@serverB ~] # gitlab-rake gitlab:backup:restore BACKUP=1568659149_2019_03_17_10.6.4 Unpacking backup. Done Before restoring the database, we will remove all existing tables to avoid future upgrade problems. Be aware that if you have custom tables in the GitLab database these tables and all data will be removed. ```* * Do you want to continue (yes/no)? Yes** ```Removing all tables. Press `Ctrl- C` within 5 seconds to abort Cleaning the database... Done Restoring database... Restoring PostgreSQL database gitlabhq_production... SET. Put GitLab hooks in repositories dirs [DONE] done Restoring uploads... Done Restoring builds... Done Restoring artifacts... Done Restoring pages... Done Restoring lfs objects... Done This will rebuild an authorized_keys file. You will lose any data stored in authorized_keys file. * * Do you want to continue (yes/no)? No # # if you retain the old permissions here, enter no * * Quitting... 3. Reset service [root@serverB ~] # gitlab-ctl restart [root@serverB ~] # gitlab-rake gitlab:check SANITIZE=true

III. Confirmation of mail function

You need to confirm whether gitlab can send email normally.

In the old environment, the configuration in serverA uses port 25, but the public CVM blocks port 25 by default. The following error occurs when sending email.

Initially configured as:

[root@serverB ~] # grep-v "#" / etc/gitlab/gitlab.rb | grep-v "^ $"

External_url 'http://git.bd.com'

Nginx ['listen_port'] = 54444

Gitlab_rails ['time_zone'] =' Asia/Shanghai'

Gitlab_rails ['gitlab_shell_ssh_port'] = 9000

Gitlab_rails ['smtp_enable'] = true

Gitlab_rails ['smtp_address'] = "smtp.exmail.qq.com"

Gitlab_rails ['smtp_port'] = 25

Gitlab_rails ['smtp_user_name'] = "git@bd.com"

Gitlab_rails ['smtp_password'] = "88888888"

Gitlab_rails ['smtp_domain'] = "exmail.qq.com"

Gitlab_rails ['smtp_authentication'] = "login"

Gitlab_rails ['smtp_enable_starttls_auto'] = true

Gitlab_rails ['gitlab_email_from'] =' git@bd.com'

User ["git_user_email"] = "git@bd.com"

Nginx ['custom_nginx_config'] = "include / var/opt/gitlab/nginx/conf/custom.conf;"

Gitlab_ci ['backup_path'] = "/ gitlab_backup"

[root@serverB ~] #

Test the ability to send mail

[root@serverB ~] # gitlab-rails console

Loading production environment (Rails 4.2.10)

Irb (main): 001ch@bd.com 0 > Notify.test_email ("ch@bd.com", "title", "gitlab"). Deliver_now

Notify#test_email: processed outbound mail in 180.0ms

Sent mail to ch@bd.com (1885.3ms)

Date: Thu, 19 Sep 2019 19:05:27 + 0800

From: GitLab

Reply-To: GitLab

To: ch@bd.com

Message-ID:

Subject: title

Mime-Version: 1.0

Content-Type: text/html

Charset=UTF-8

Content-Transfer-Encoding: 7bit

Auto-Submitted: auto-generated

X-Auto-Response-Suppress: All

Gitlab

Net::OpenTimeout: execution expired

From / opt/gitlab/embedded/lib/ruby/2.3.0/net/smtp.rb:542:in initialize'from / opt/gitlab/embedded/lib/ruby/2.3.0/net/smtp.rb:542:inopen'

From / opt/gitlab/embedded/lib/ruby/2.3.0/net/smtp.rb:542:in tcp_socket'from / opt/gitlab/embedded/lib/ruby/2.3.0/net/smtp.rb:552:inblock in do_start'

From / opt/gitlab/embedded/lib/ruby/2.3.0/timeout.rb:101:in timeout'from / opt/gitlab/embedded/lib/ruby/2.3.0/net/smtp.rb:551:indo_start'

From / opt/gitlab/embedded/lib/ruby/2.3.0/net/smtp.rb:521:in start'from / opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/mail-2.7.0/lib/mail/network/delivery_methods/smtp.rb:109:instart_smtp_session'

From / opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/mail-2.7.0/lib/mail/network/delivery_methods/smtp.rb:100:in deliverables from / opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/mail-2.7.0/lib/mail/message.rb:2160:indo_delivery'

From / opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/mail-2.7.0/lib/mail/message.rb:260:in block in deliver'from / opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/actionmailer-4.2.10/lib/action_mailer/base.rb:543:inblock in deliver_mail'

From / opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/activesupport-4.2.10/lib/active_support/notifications.rb:164:in block ininstrument' from / opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/activesupport-4.2.10/lib/active_support/notifications/instrumenter.rb:20:ininstrument'

From / opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/activesupport-4.2.10/lib/active_support/notifications.rb:164:in instrument'from / opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/actionmailer-4.2.10/lib/action_mailer/base.rb:541:indeliver_mail'

From / opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/mail-2.7.0/lib/mail/message.rb:260:in deliver'from / opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/actionmailer-4.2.10/lib/action_mailer/message_delivery.rb:85:indeliver_now'

From (irb): 1

From / opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/railties-4.2.10/lib/rails/commands/console.rb:110:in start'from / opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/railties-4.2.10/lib/rails/commands/console.rb:9:instart'

From / opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:68:in console'from / OptUniverse Gemby GemsUniverse 2.3.0 GemsUniverse RailtiesMuffle 4.2.10 from / RTR / OptUnix GemsUniverse commandsChardsLebUnix commands tasks.rbRB _ RB _ RV

From / opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/railties-4.2.10/lib/rails/commands.rb:17:in 'from bin/rails:9:inrequire'

From bin/rails:9:in `'

After investigation and analysis, port 25 has been uniformly closed, so it is necessary to use secure transport layer protocol to send mail.

Modify the configuration to

[root@serverB ~] # grep-v "#" / etc/gitlab/gitlab.rb | grep-v "^ $"

External_url 'http://git.bd.com'

Nginx ['listen_port'] = 54444

Gitlab_rails ['time_zone'] =' Asia/Shanghai'

Gitlab_rails ['gitlab_shell_ssh_port'] = 9000

Gitlab_rails ['smtp_enable'] = true

Gitlab_rails ['smtp_address'] = "smtp.exmail.qq.com"

Gitlab_rails ['smtp_tls'] = true

Gitlab_rails ['smtp_port'] = 465

Gitlab_rails ['smtp_user_name'] = "git@bd.com"

Gitlab_rails ['smtp_password'] = "88888888"

Gitlab_rails ['smtp_domain'] = "exmail.qq.com"

Gitlab_rails ['smtp_authentication'] = "login"

Gitlab_rails ['smtp_enable_starttls_auto'] = true

Gitlab_rails ['gitlab_email_from'] =' git@bd.com'

User ["git_user_email"] = "git@bd.com"

Nginx ['custom_nginx_config'] = "include / var/opt/gitlab/nginx/conf/custom.conf;"

Gitlab_ci ['backup_path'] = "/ gitlab_backup"

[root@serverB ~] #

Execute gitlab-ctl reconfigure after modification

Confirm that you can send an email:

[root@serverB ~] # gitlab-rails console

Loading production environment (Rails 4.2.10)

Irb (main): 001ch@bd.com 0 > Notify.test_email ("ch@bd.com", "title", "gitlab"). Deliver_now

Notify#test_email: processed outbound mail in 180.0ms

Sent mail to ch@bd.com (1885.3ms)

Date: Thu, 19 Sep 2019 19:05:27 + 0800

From: GitLab

Reply-To: GitLab

To: ch@bd.com

Message-ID:

Subject: title

Mime-Version: 1.0

Content-Type: text/html

Charset=UTF-8

Content-Transfer-Encoding: 7bit

Auto-Submitted: auto-generated

X-Auto-Response-Suppress: All

Gitlab

= > #

Irb (main): 002purl 0

If the transmission is not successful, please check whether user ['git_user_email'] is configured. If all the above are configured, check whether port 465 is open in the CVM security group.

Fourth, the verification method:

The office network environment verifies the command line operation of ssh protocol and the opening of Web pages. # # pass

Office network v tunnel / channel n environment verifies the command line operation of ssh protocol and the opening of Web pages. # # pass

The public network environment verifies the command line operation of ssh protocol and the forbidden access and opening of Web pages. # # Yes, access is prohibited on public network

The public network v tunnel p channel n environment verifies the command line operation of ssh protocol and the opening of Web pages. # # pass

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