前回の「【第3回】ConoHaとCentOS7でDBサーバー構築」の続きです。
今回はGitLabの構築を行いたいと思います。
環境
OS/ミドルウェア | バージョン |
---|---|
CentOS | 7.2.1511 |
Apache | 2.4.6 |
PHP | 5.4.16 |
MySQL | 5.7.17 |
OpenSSH | 6.6.1p1 |
Postfix | 2.10.1 |
1.関連ツールのインストールと起動設定
openssh-server:
通信データーを暗号化してリモートアクセスを安全に行うためのプロトコル SSH(Secure SHell)を利用するためのソフトウェア
postfix:
オープンソースソフトウェアのメール転送エージェント
gitlabの動作で使用している「openssh-server」「postfix」がインストールされているか確認。
1 |
# yum list installed |
※私の場合は、インストール済みでした。
1 2 |
openssh-server.x86_64 6.6.1p1-25.el7_2 @updates postfix.x86_64 2:2.10.1-6.el7 @anaconda |
※インストールされていなかったらインストールする。
[インストールコマンド]
1 2 |
# yum install openssh-server # yum install postfix |
[openssh-serverの起動・再起動時の起動設定をonにします]
1 2 |
# systemctl enable postfix # systemctl start postfix |
[Postfixの起動・再起動時の起動設定をonにします]
1 2 |
# systemctl enable sshd # systemctl start sshd |
[OpenSSHバージョン確認]
1 |
# ssh -V |
[表示結果]
1 |
OpenSSH_6.6.1p1, OpenSSL 1.0.1e-fips 11 Feb 2013 |
[Postfixバージョン確認]
1 |
# postconf | grep mail_version |
[表示結果]
1 2 |
mail_version = 2.10.1 milter_macro_v = $mail_name $mail_version |
2.gitlabインストール
[gitlabのrpmファイルをダウンロード]
1 |
# curl -O https://downloads-packages.s3.amazonaws.com/centos-7.1.1503/gitlab-ce-7.10.1~omnibus.2-1.x86_64.rpm |
[表示結果]
1 2 3 |
% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 292M 100 292M 0 0 3630k 0 0:01:22 0:01:22 --:--:-- 3981k |
[インストール(rpm実行)]
1 |
# rpm -i gitlab-ce-7.10.1~omnibus.2-1.x86_64.rpm |
[表示結果]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
gitlab: Thank you for installing GitLab! gitlab: Configure and start GitLab by running the following command: gitlab: gitlab: sudo gitlab-ctl reconfigure gitlab: gitlab: GitLab should be reachable at http://150-95-151-20 gitlab: Otherwise configure GitLab for your system by editing /etc/gitlab/gitlab.rb file gitlab: And running reconfigure again. gitlab: gitlab: For a comprehensive list of configuration options please see the Omnibus GitLab readme gitlab: https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md gitlab: gitlab: gitlab: If you just upgraded from GitLab 7.9 or earlier, please run the following gitlab: command: gitlab: gitlab: sudo ln -sf /opt/gitlab/bin/gitlab-ctl /opt/gitlab/bin/gitlab-rake /opt/gitlab/bin/gitlab-rails /opt/gitlab/bin/gitlab-ci-rake /opt/gitlab/bin/gitlab-ci-rails /usr/bin/ |
3.設定ファイルの編集
gitlabの設定ファイル「/etc/gitlab/gitlab.rb」を編集し、各設定を行います。
公式ドキュメントの手順に抜けているが、これがないと「gitlab-ctl reconfigure」がうまくいかない?と思います。
cdコマンドで/etc/gitlab ディレクトリに移動し、cpコマンドでgitlab.rbのバックアップをとっておき、vimコマンドでgitlab.rbを編集します。
1 2 3 |
# cd /etc/gitlab # cp gitlab.rb gitlab.rb.old # vim gitlab.rb |
編集&追加する内容は下記
1 2 3 4 5 6 7 |
// 編集 external_url 'http://☓☓☓.☓☓.☓☓☓.☓☓:8000' // 新規で追加 # gitlab_rails['gravatar_plain_url'] = 'http://www.gravatar.com/avatar/%{hash}?s=%{size}&d=identicon' # gitlab_rails['gravatar_ssl_url'] = 'https://secure.gravatar.com/avatar/%{hash}?s=%{size}&d=identicon' gitlab_rails['gravatar_enabled'] = false |
8000番ポートにしておく。80の場合apacheとかぶるため。
gitlab_rails[‘gravatar_enabled’] = falseはgravatar(グローバルに扱われるアバター)を無効にします。
[vimエディタ検索方法]
gitlab.rbはたくさんの設定が記載されていますので、目的の設定場所を探すのに時間がかかります。
ここは、検索をうまく使ってすばやく目的の設定箇所を見つけましょう。
vimで ‘/’ をタイプしてください。検索モードになり、画面の一番下にフォーカスが移りますので、検索語句”◯◯◯“を入力してエンターを押します。
設定を変更したら、:wqでvimを終了します。
4.ファイアウォール設定
ファイアウォールを切っている場合はとくに不要です。
CentOS7になってiptablesの設定にはfirewalldを使用するようになっています。
[設定追加]
1 |
# firewall-cmd --add-port=8000/tcp --permanent |
[success]と表示される
[ファイアウォール再起動]
1 |
# firewall-cmd --reload |
[success]と表示される
[プロセスが使用しているポートを表示するコマンド]
1 |
# lsof -i |
[ポート番号から使用しているプログラムを表示するコマンド]
1 |
# lsof -i:ポート番号 |
5.設定ファイルの反映と関連処理の実行
gitlabではchefというプロビジョニングを実行してgitlabに必要なnginxのインストールや環境設定などいろいろ行っています。
「3.設定ファイルの編集」で設定した情報もここで設定値を反映します。
[設定ファイルの反映]
1 |
# gitlab-ctl reconfigure |
6.gitlab起動
1 2 3 4 5 6 7 8 |
// 起動 # gitlab-ctl start // 停止 # gitlab-ctl stop // ステータス確認 # gitlab-ctl status |
7.ブラウザよりgitlabページの表示
http://ipアドレス/ホスト名:8000
でアクセスします
[Gitlabのバージョンを確認する方法]
1.ブラウザから確認する
ブラウザから確認する場合は、GitlabのURL末尾に「/help」を付与すればよい。
「http://GitlabのIPアドレスorホスト名/help」でバージョンを確認できる。
2.コンソールからコマンドで確認する
もしくは、コンソールから以下のコマンドで確認ができる。
1 |
# gitlab-rake gitlab:env:info |
[表示結果]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
System information System: Current User: git Using RVM: no Ruby Version: 2.1.6p336 Gem Version: 2.2.1 Bundler Version:1.5.3 Rake Version: 10.4.2 Sidekiq Version:3.3.0 GitLab information Version: 7.10.1 Revision: d5c71c8 Directory: /opt/gitlab/embedded/service/gitlab-rails DB Adapter: postgresql URL: http://150-95-151-20:8000 HTTP Clone URL: http://150-95-151-20:8000/some-project.git SSH Clone URL: git@150-95-151-20:some-project.git Using LDAP: no Using Omniauth: no GitLab Shell Version: 2.6.2 Repositories: /var/opt/gitlab/git-data/repositories Hooks: /opt/gitlab/embedded/service/gitlab-shell/hooks/ Git: /opt/gitlab/embedded/bin/git |
[ログイン情報]
ログインユーザとパスはドキュメントに記載している通りです
1 2 |
Username: root Password: 5iveL!fe |
ログイン後、パスワード変更画面になるので、パスワードを変更します。
パスワードを入力後[Set new password]クリック
ログイン出来ました。
8.Gitのインストール
今の状態でgitコマンドをしてもうまくいきません。
1 |
# git --version |
[表示結果]
1 |
-bash: git: コマンドが見つかりません |
なのでgitのインストールをします。
[gitインストール]
1 |
# yum -y install git |
最後に「完了しました!」と表示されればOKです。
[gitバーション確認]
1 |
# git --version |
[表示結果]
1 |
git version 1.8.3.1 |
今度はうまくいきました。これでgitのコマンドが使用できる状態になりました。
9.patchのインストール
[patchがインストールされているか確認]
1 |
# which patch |
[patchのインストールコマンド]
1 2 3 4 |
# yum install patch 総ダウンロード容量: 110 k インストール容量: 210 k Is this ok [y/d/N]: y |
Is this ok [y/d/N]:
が表示されたら「y」
「完了しました!」
が表示されたらOKです。
10.GitLabを日本語化する
[gitにあるパッチをコピー]
1 |
# git clone https://github.com/ksoichiro/gitlab-i18n-patch.git |
[表示結果]
1 2 3 4 5 |
Cloning into 'gitlab-i18n-patch'... remote: Counting objects: 7625, done. remote: Total 7625 (delta 0), reused 0 (delta 0), pack-reused 7625 Receiving objects: 100% (7625/7625), 19.60 MiB | 4.65 MiB/s, done. Resolving deltas: 100% (4011/4011), done. |
[ディレクトリ移動]
1 |
# cd /opt/gitlab/embedded/service/gitlab-rails |
[パッチコマンド]
1 |
# patch -d < /home/ユーザー名/gitlab-i18n-patch/patches/v7.9.4/app_ja.patch |
[表示結果]
1 2 |
patch: option requires an argument -- 'd' patch: Try 'patch --help' for more information. |
上記のような結果になったら日本語対応になっているはずです。
[設定ファイルの反映]
1 |
# gitlab-ctl reconfigure |
[ブラウザから確認する]
日本語で表示されます。
11.GitLabユーザー登録
[ユーザー登録手順]
ユーザーを新規に登録するには、root で GitLab にログインした状態から、ダッシュボード右上の [Admin Area ]をクリックします。
[新しいユーザ]をクリック
新規に登録するユーザーの名前、ユーザー名(ログインID)、そしてメールアドレスを入力して[ユーザを作成] ボタンでユーザーを作成します。
※この時点ではパスワードは登録しません
確認画面が表示されます。
メールサーバーが正しく設定されていて、メール認証が有効になっている場合は、指定したメールアドレスにメールが送られ、その本文内のリンクからパスワード設定を含めた本登録を行うことになります。
[注意]
ここでいったんrootユーザからログアウトして下さい。(※ログアウトしていない状態で次の「 [新規ユーザ] GitLab配信メールの確認」を行うと、他ユーザにてログインしているためエラーとなります。)
確認画面が表示されます。
新しいユーザのパスワードを入力して、[Change your password]をクリックする。
画面が表示されます。
ログアウト[sign out]をクリックして、作成したユーザーでログインしてみる。
作成したユーザーのログイン後の画面
表示される項目が違っているはずです。
[root]
[作成したユーザー]
確認できたら、ユーザー登録は完了です。
※「GitLab配信メールの確認」のメールが届かない場合は、rootでログインし、作成したユーザから編集ボタンをクリックして、パスワードを入力して下さい。入力したら保存してログアウトし、作成したユーザでログインして下さい。
12.プロジェクト追加手順
一般ユーザーでプロジェクトを追加してみます。ソースコードの管理をするにもまずはそのプロジェクトを作成する必要があります。
GitLab ダッシュボードに一般ユーザーでログインした後に、Project「初期状態でここが選ばれているはずです」
[新しいプロジェクト] ボタンをクリックします。
プロジェクトの作成画面が表示されます。
「プロジェクトパス」「説明」「可視性レベル(?)」を入力&選択し、[プロジェクトを作成]をクリックします。
- プロジェクトパス:プロジェクトの名前
- 説明:プロジェクトの説明
- 可視性レベル(?):アクセスレベル
GitLab 上にプロジェクト my-first-project が新規に作成できました。
※ssh鍵の登録をしていないと下記のように表示されます。
画面を下にスクロールすると、この後のコマンド操作方法についての簡単なガイドが紹介されています。必要に応じて参照してください。
13.プロジェクトの Git リポジトリを git クライアントから操作する手順
ターミナルの起動。
sshでサーバーに接続。
[Gitのグローバルなセットアップ]
1 2 |
git config --global user.name "ユーザー名" git config --global user.email "メールアドレス" |
下記参考。
ファイルの作成される場所:~/.gitconfig
[.gitconfig]ファイルが作成される。
1 |
-rw-rw-r-- 1 ユーザー名 ユーザー名 22 1月 20 13:01 .gitconfig |
[.gitconfigファイルの中身を確認]
1 2 3 |
[user] name = ◯◯◯ email = ☓☓☓☓☓☓☓☓☓☓☓@gmail.com |
[.gitconfigファイルを変更]
1 2 3 4 5 6 7 8 9 10 |
[user] name = ◯◯◯ email = ☓☓☓☓☓☓☓☓☓☓☓@gmail.com // 追加 [alias] ci = commit co = checkout st = status diff = diff --cached br = branch |
[alias]にgitコマンドを記述して置くと、gitコマンドを記述した内容で使用できる。
[.gitignoreファイルを作成]
1 |
$ touch .gitignore |
[.gitignoreファイルの確認]
1 |
-rw-rw-r-- 1 ユーザー名 ユーザー名 0 1月 20 14:36 .gitignore |
[.gitignoreファイルの記述]
1 2 3 4 5 6 7 8 |
"*.log" "*.pdf" "*.xls" "*.xlsx" "*.csv" files/ logs/ tmp/ |
人によって内容が異なる。
※.gitignoreを使うと無視する(Gitのトラッキングの対象外とする)ファイル or ディレクトリを指定できる。
この設定は最初からやることをオススメします。途中からだと厄介です。
コマンドを打つたびにパスを聞かれるから聞かれないように設定
[ディレクトリの移動]
1 |
$ cd /home/ユーザー名/プロジェクト名/.git |
[ファイルの編集]
1 |
$ vi config |
[ファイルの中身]
1 2 3 4 5 6 |
[remote "origin"] url = http://☓☓☓.☓☓.☓☓☓.☓☓:☓☓☓☓/ユーザー名/my-first-project.git [remote "origin"] // [ユーザ名:パスワード@]を追加 url = http://ユーザ名:パスワード@☓☓☓.☓☓.☓☓☓.☓☓:☓☓☓☓/ユーザー名/my-first-project.git |
※ユーザー名:パスワードに@が含まれている場合は%40にする
コマンドの文字に色付けを行なう
[ディレクトリの移動]
1 |
$ cd /home/ユーザー名/プロジェクト名/.git |
[ファイルの編集]
1 |
$ vi config |
[ファイルの中身]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true [remote "origin"] url = http://ユーザー名:パスワード@☓☓☓.☓☓.☓☓☓.☓☓:☓☓☓☓/ユーザー名/my-first-project.git fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master // 追加する [color] ui = auto |
リポジトリを新しく作成する方法
下記参考。
[ディレクトリの作成]
1 |
$ mkdir my-first-project |
[作成したディレクトリに移動]
1 |
$ cd my-first-project |
[.git作成]
1 |
$ git init |
[表示結果]
1 |
Initialized empty Git repository in /home/◯◯◯/my-first-project/.git/ |
.gitが作成されます。
[.git確認]
1 |
drwxrwxr-x 7 ユーザー名 ユーザー名 4096 1月 21 15:48 .git |
[ファイル作成]
1 |
$ touch README.md |
[インデックスに貼り付け(コミットを出来るように準備)]
1 |
$ git add README.md |
[コミット(ファイルの保存)]
1 |
$ git commit -m "first commit" |
[表示結果]
1 2 3 |
[master (root-commit) b7da6f2] first commit 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 README.md |
[リモートを指定]
※HTTPを使用
1 |
$ git remote add origin http://☓☓☓-☓☓-☓☓☓-☓☓:◯◯◯◯/◯◯◯/my-first-project.git |
[プッシュ(ファイルをリモートにアップ)]
1 |
$ git push -u origin master |
以上で、GitLabの構築が完了です。
【第1回】ConoHa申し込み手順〜CentOS7でサーバー構築
【第5回】ConoHaとCentOS7でCakePHPインストール方法