とりあえずGitLab使ってみたかった。
サーバー機調達
DELLの18000円くらいの500GB HDDのPCを購入
GitLabの最低要件が4コアだったので、そこに注意されたし。
サーバー機にUbuntu導入
だいたいここに書いてある。
https://diagnose-fix.com/topic2-003/
別PCにてUbuntu用の起動USBを作成する。
Rufusというアプリを使用し、BIOSが起動できるUSBにする必要がある。
手間取った点は、BIOSの設定で、USBを読み込まない設定、セキュアブート、USBを認識しない。等の問題が発生した。解決方法は省略
Ubuntu起動後設定
日本語にしたり、とりあえずログインしたらコマンドラインが表示される状態にする。
だいたいの設定はデフォルト通り、パスワードは適当に設定した。
GitLabのインストール
オンラインの状態を確認する(有線でやった)
GitLabのインストール手順は以下の通りです。
サポートされている環境を確認する: GitLabは特定の環境でのみ動作します。インストールする前に、GitLabがサポートする環境を確認してください。詳細については、GitLabの公式ドキュメントを参照してください。
必要なパッケージをインストールする: GitLabをインストールするには、必要なパッケージをインストールする必要があります。以下のコマンドを使用して、必要なパッケージをインストールしてください。
sudo apt-get update
sudo apt-get install -y curl openssh-server ca-certificates tzdata perl
GitLabパッケージをインストールする: GitLabパッケージをインストールするには、以下のコマンドを使用してGitLabのリポジトリを追加し、GitLabパッケージをインストールしてください。
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.deb.sh | sudo bash
sudo apt-get install gitlab-ee
上記の例では、GitLab EE(エンタープライズエディション)のパッケージをインストールする方法を示しています。GitLab CE(コミュニティエディション)をインストールする場合は、以下のコマンドを使用してください。
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
sudo apt-get install gitlab-ce
GitLabの設定を行う: GitLabのインストールが完了したら、設定を行う必要があります。設定ファイルは、/etc/gitlab/gitlab.rbにあります。以下のコマンドを使用して、設定ファイルを編集してください。
sudo vi /etc/gitlab/gitlab.rb
必要に応じて、サーバー名、IPアドレス、ポート番号、SSL証明書などの設定を変更できます。
GitLabを再構成する: 設定を変更したら、以下のコマンドを使用してGitLabを再構成してください。
sudo gitlab-ctl reconfigure
GitLabを起動する: GitLabを起動するには、以下のコマンドを使用してGitLabを再起動してください。
sudo gitlab-ctl restart
以上の手順に従って、GitLabをインストールして設定することができます。また、GitLabのインストール手順の詳細については、公式ドキュメントを参照してください。
rootユーザーのパスワードを変更する
// gitlabサーバー機にログインする。(他機からSSHログインでもよい)
gitlab-rails console production
// 少し待つと、
irb(main):001:0>
// の表示を待つ
// 以下のコマンドを実行する。
user = User.where(id: 1).first
user.password = 'p@ssw0rd'
user.password_confirmation = 'p@ssw0rd'
user.save!
Railsコンソールについて
"gitlab-rails console"は、GitLabのRailsコンソールで、GitLabのデータベースに直接アクセスするためのコマンドラインツールです。Railsアプリケーションのコンソールと同様に、Rubyのコードを実行することができます。また、データベースのクエリを実行することもできます。
[root@BS-PUB-GITLAB ~]# gitlab-rails console production
Loading production environment (Rails 4.2.6)
irb(main):001:0> user = User.where(id: 1).first
=> #<User id: 1, email: "admin@example.com", encrypted_password: "$2a$10$RLIb1nhSE98E.kmtklRwV.29ty3kf8MdB4.Egxf9x9k...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, created_at: "2016-05-29 23:35:29", updated_at: "2017-10-28 20:40:13", name: "Administrator", admin: true, projects_limit: 10, skype: "", linkedin: "", twitter: "", authentication_token: "mGH1k4eNx1a3jVsUFwsh", theme_id: 2, bio: nil, failed_attempts: 2, locked_at: nil, username: "root", can_create_group: true, can_create_team: false, state: "active", color_scheme_id: 1, notification_level: 1, password_expires_at: nil, created_by_id: nil, last_credential_check_at: nil, avatar: nil, confirmation_token: nil, confirmed_at: "2016-05-29 23:35:29", confirmation_sent_at: nil, unconfirmed_email: nil, hide_no_ssh_key: false, website_url: "", notification_email: "admin@example.com", hide_no_password: false, password_automatically_set: false, location: nil, encrypted_otp_secret: nil, encrypted_otp_secret_iv: nil, encrypted_otp_secret_salt: nil, otp_required_for_login: false, otp_backup_codes: nil, public_email: "", dashboard: 0, project_view: 0, consumed_timestep: nil, layout: 0, hide_project_limit: false, unlock_token: nil, otp_grace_period_started_at: nil, ldap_email: false, external: false>
irb(main):002:0> user.password = 'P@ssw0rd'
=> "P@ssw0rd"
irb(main):003:0> user.password_confirmation = 'P@ssw0rd'
=> "P@ssw0rd"
irb(main):004:0> user.save!
=> true
ローカルネットワークで入ってみる。
同じルーターからであればローカルIPアドレスで入ることができそう。
以下、IPの確認方法とブラウザで入ったときの画像
ip addr show
以下ところどころ省略
1: lo: <LOOPBACK,UP,LOWER_UP>
inet 127.0.0.1/8 scope host lo
inet6 ------
2: enp0s31f6: <>
inet 192.168.2.116/24 metric 100 brd 192.168.2.225 scope global dynamic enp0s31f6
↑============↑ ここがIPアドレス
inet6 --------
外からアクセスできるようにする。
//GitLabサーバーにSSHログイン(SSHでなくてもいいけど)
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
cd etc/gitlab/
# ssl ディレクトリ作成
mkdir ssl
cd ssl/
# 証明書発行
openssl req -x509 -newkey rsa:4096 -keyout gitlab.key -out gitlab.crt -days 365 -nodes
# コンフィグ再設定
gitlab-ctl reconfigure
# サーバー再起動
sudo gitlab-ctl restart
Gitlabサーバーに関するコマンド
$ sudo gitlab-ctl start
$ sudo gitlab-ctl stop
$ sudo gitlab-ctl restart