Gitlab-ce Server 이전시 발생 문제와 해결 (backup and restore, pg_dump, version upgrade, 500 에러

2019.08.20. 기준 문서


(1) Docker Container 로 올라가있는 기존 Gitlab-ce (v.11.7) 서버를 새로운 서버로 이전을 시도

중에..이를 위해 백업 데이터를 생성해야 하는데 여기서 첫번째 문제 발생한다.

souce build (이미지 빌드) 버전이기 때문에 아래와 같은 명령어로 백업 수행 시도
$ gitlab-rake gitlab:backup:create RAILS_ENV=production

에러 메시지는 아래와 같았다.
pg_dump: aborting because of server version mismatch
[FAILED]
rake aborted!

딱 봐도 버전이 안맞는다는 에러이지만, 아무리 명령어를 쳐봐도 동일한 버전이였다.
서버 버전이 문제가 아닐까? 했지만, 그 문제는 아니였다.

알고보니 DB 서버 버전과 gitlab 내부에서 사용하는 "pg_dump"의 client 버전이 달라서 발생한 문제
/# postgres --version
postgres (PostgreSQL) 9.6.11
root@8256e59e3eae:/# /opt/gitlab/embedded/bin/pg_dump --version
pg_dump (PostgreSQL) 9.6.11

아래와 같은 순서로 수행하여 해결했다.
1. 서버에 가서 $find / -name pg_dump 명령어로 pg_dump 실행파일을 찾음
2. 해당 파일을 gitlab 서버에 복사, 위치는 대략 /opt/gitlab/embedded/postgresql/{version}/bin
3. 복사한 실행파일을 심볼릭 링크로 /opt/gitlab/embedded/bin 안에 넣어줌

그런데, 아래와 같이 다시 새로운 에러가 떴다.
Dumping PostgreSQL database gitlab
...
pg_dump: error while loading shared libraries: libpq.so.5: cannot open shared object file: No such file or directory

딱 봐도 라이브러리가 없다는 얘기로 보였다, 
그래서 다시 DB 서버에 해당 라이브러리를 찾아봤다.

위와 동일하게 심볼릭 링크를 아~무리 지정해서 넣어도 찾지를 못했다 (동일 에러 발생). 많은 검색 끝에, "LD_LIBRARY_PATH" 이 경로 지정이 문제라는걸 알게 되었다...(칼퇴를 위한 몸부림)

아래와 같이 라이브러리를 넣은 위치를 지정해주면, 정상적으로 진행이 된다.
LD_LIBRARY_PATH={libpq.so.5 라이브러리가 위치한 디렉토리}

.so 로 끝나는 라이브러리의 위치를 알려줘야하는 문제였다. 이렇게 백업을 완료하고...


(2) 11.7 버전에서 12.1 버전으로 업그레이드

이전 Gitlab 서버 버전은 11.7.x, 이전하려는 서버에 백업 데이터를 넣어야하기 때문에 우선 동일한 버전으로 docker image를 지정하여 올렸다.

테스트 시 너무나도 잘 작동해서 기쁜 마음에 바로 버전을 latest 로 올려보았다. (절대 이러면 안된다. 테스트 서버이기 때문에 가능한 일이다,)

역시! Container가 2분마다 한번씩 사망선고를 받고 다시 태어나기를 반복하고 있었다. Stack Overflow 검색했더니 충격적인 내용을 보고야 말았다.

대략, Gitlab 서버 버전 업그레이드는 major 버전 한단계씩 하는게 좋다는 이야기.
"We recommend that you first upgrade to the latest available minor version within your major version. By doing this, you can address any deprecation messages that could change behavior in the next major release."

"It is considered safe to jump between patch versions and minor versions within one major version."

* You can only upgrade 1 minor release at a time. So from 9.1 to 9.2, not to 9.3.

from:https://stackoverflow.com/questions/54993966/do-i-have-to-update-gitlab-through-each-minor-version

현재 안정 버전이 12.1.0-ce.0 이니깐....
11.7.0-ce.0 > 11.8.0-ce.0 > 11.9.0-ce.0 > 11.10.0-ce.0 > 11.11.0-ce.0 > 12.0.0-ce.0 > 12.1.0-ce.0

이정도 쯤이야......



(3) Gitlab server 백업 데이터 이전 및 버전 업그레이드 후... Settings - CI/CD 항목 진입시 500 에러

모든게 잘 작동하는 것 같았고, 모든 데이터가 너무나도 잘 살아있던 그 때. CI/CD 항목을 들어가는 순간, 야생의 500 에러 페이지가 나타났다. 모든 프로젝트의 Settings 메뉴에 CI/CD 항목만 들어가면 500 에러 페이지가 나왔다.

웹 서버의 경우 500 번대 에러가 나는 경우, 아무리 콘솔을 봐도 답을 찾긴 어렵다. 서버 에러는 서버 로그를 봐야한다.

gitlab-ctl tail 명령어는 gitlab 서버의 로그를 실시간으로 보여준다. 
너무나도 잘 만들었다.

명확하게 보이는 에러였지만, 해결 방법이 좀 길었다.
==> /var/log/gitlab/gitlab-rails/production.log <==
Started GET "/hslee/test-k8s-cicd/-/settings/ci_cd" for 172.18.0.1 at 2019-08-20 02:18:16 +0000
Processing by Projects::Settings::CiCdController#show as HTML
Parameters: {"namespace_id"=>"hslee", "project_id"=>"test-k8s-cicd"}
Completed 500 Internal Server Error in 315ms (ActiveRecord: 58.6ms)


ActionView::Template::Error ():
25: project_clusters_path(@project),
26: class: 'btn btn-info'
27: %hr
28: = render partial: 'ci/runner/how_to_setup_runner',
29: locals: { registration_token: @project.runners_token,
30: type: 'specific',
31: reset_token_url: reset_registration_token_namespace_project_settings_ci_cd_ path }

lib/gitlab/crypto_helper.rb:27:in `aes256_gcm_decrypt'
app/models/concerns/token_authenticatable_strategies/encrypted.rb:45:in `get_token'
app/models/concerns/token_authenticatable_strategies/base.rb:33:in `ensure_token!'
app/models/concerns/token_authenticatable.rb:45:in `block in add_authentication_token_field'
app/models/project.rb:1590:in `runners_token'
app/views/projects/runners/_specific_runners.html.haml:28:in `_app_views_projects_runners__specific_runn ers_html_haml___4200129141666358982_69883394124780'
....(중략)....

==> /var/log/gitlab/gitlab-rails/production_json.log <==
{"method":"GET","path":"blarblar","format":"html","controller":"Projects::S ettings::CiCdController","action":"show","status":500,"error":"ActionView::Template::Error: ","duration" :315.46,"view":0.0,"db":58.61,"time":"2019-08-20T02:18:17.333Z","params":[{"key":"namespace_id","value": "hslee"},{"key":"project_id","value":"blarblar"}],"remote_ip":"172.18.0.1","user_id":17,"username": "blarblar","ua":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75 .0.3770.142 Safari/537.36","queue_duration":15.8,"gitaly_calls":1,"gitaly_duration":20.4,"correlation_id ":"blarblar"}


문제 해결 방법이 두가지가 있었는데, 첫번째 방법은 통하지 않았다. (해당 문제가 아니였다.)
  • 첫번째. db migrate 상태를 보고, on 되어있지 않으면 수동으로 켜주는 방법.
docker exec -it gitlab gitlab-rake db:migrate:status
#... 결과가 on 이 아니라면, ---
docker exec -it gitlab gitlab-rake db:migrate

-- db server 접속
su - postgres
psql -d postgres -U postgres

-- db 리스트 확인
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+---------+-------+-----------------------
gitlab | postgres | UTF8 | C | C | =Tc/postgres +
| | | | | postgres=CTc/postgres+
| | | | | gitlab=CTc/postgres

-- db 사용 선택
postgres=# \c gitlab
You are now connected to database "gitlab" as user "postgres".

-- db 내 프로젝트 테이블 정보 확인
gitlab=# \dti projects
List of relations
Schema | Name | Type | Owner | Table
--------+----------+-------+--------+-------
public | projects | table | gitlab |
(1 row)

-- 프로젝트 테이블 조회
gitlab=# select * from projects;
.... (테이블 결과, 너무 많아서 생략)....

-- 주요 부분 --
-- Clear project tokens
UPDATE projects SET runners_token = null, runners_token_encrypted = null;
-- Clear group tokens
UPDATE namespaces SET runners_token = null, runners_token_encrypted = null;
-- Clear instance tokens
UPDATE application_settings SET runners_registration_token_encrypted = null;
-- Clear runner tokens
UPDATE ci_runners SET token = null, token_encrypted = null;
  • 이러고 나면 Runner 토큰이 변경되므로 Runner 에 해당하는 서버에서 모두 토큰을 변경해주는 작업이 필요하다....ㅠㅠ


+ Recent posts