jam 블로그

[linux] centos 6.5 64bit server에서 gitlab 설치하기. 본문

시스템/리눅스

[linux] centos 6.5 64bit server에서 gitlab 설치하기.

kid1412 2014. 4. 8. 12:01
728x90
1. centos 설치시에 basic server로 설치
2. 첫번째 스크립트를 돌립니다. hostname에 주소를 넣어줍니다.
 
#!/bin/sh

hostname = ""

cd /usr/local/src
wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 https://www.fedoraproject.org/static/0608B895.txt
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
touch /etc/yum.repos.d/PUIAS_6_computational.repo
echo "[PUIAS_6_computational]" >> /etc/yum.repos.d/PUIAS_6_computational.repo
echo "name=PUIAS computational Base \$releasever - \$basearch" >> /etc/yum.repos.d/PUIAS_6_computational.repo
echo "mirrorlist=http://puias.math.ias.edu/data/puias/computational/\$releasever/\$basearch/mirrorlist" >> /etc/yum.repos.d/PUIAS_6_computational.repo
echo "enabled=1" >> /etc/yum.repos.d/PUIAS_6_computational.repo
echo "gpgcheck=1" >> /etc/yum.repos.d/PUIAS_6_computational.repo
echo "gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puias" >> /etc/yum.repos.d/PUIAS_6_computational.repo
wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-puias http://springdale.math.ias.edu/data/puias/6/x86_64/os/RPM-GPG-KEY-puias
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-puias
yum -y update
yum -y groupinstall 'Development Tools'
yum -y install vim-enhanced readline readline-devel ncurses-devel gdbm-devel glibc-devel tcl-devel openssl-devel curl-devel expat-devel db4-devel byacc sqlite-devel gcc-c++ libyaml libyaml-devel libffi libffi-devel libxml2 libxml2-devel libxslt libxslt-devel libicu libicu-devel system-config-firewall-tui redis sudo wget crontabs logwatch logrotate perl-Time-HiRes git patch libicu-devel ruby-devel
yum-config-manager --enable rhel-6-server-optional-rpms
chkconfig redis on
service redis start
yum -y remove git
yum install zlib-devel perl-CPAN gettext curl-devel expat-devel gettext-devel openssl-devel
curl --progress https://git-core.googlecode.com/files/git-1.9.0.tar.gz | tar xz
cd git-1.9.0/
./configure
make
make prefix=/usr/local install
cd /usr/local/src
wget http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.1.tar.gz
tar xvfz ruby-2.1.1.tar.gz
cd ruby-2.1.1
./configure --disable-install-rdoc
make
make prefix=/usr/local install
cd /usr/local/src
echo "export PATH=/usr/local/bin:\$PATH" >> /etc/bashrc
source /etc/bashrc
gem install bundler --no-ri --no-rdoc
adduser --system --shell /sbin/nologin --comment 'GitLab' --create-home --home-dir /home/git/ git
sed -i 's/\/sbin\:\/bin\:\/usr\/sbin\:\/usr\/bin/\/sbin\:\/bin\:\/usr\/sbin\:\/usr\/bin\:\/usr\/local\/bin/g' /etc/sudoers
cd /home/git
sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-shell.git -b v1.9.1
cd gitlab-shell
sudo -u git -H cp config.yml.example config.yml
sudo -u git -H sed -i 's/localhost/'$hostname'/g' config.yml
sudo -u git -H /usr/local/bin/ruby ./bin/install
yum install -y mysql-server mysql-devel
chkconfig mysqld on
service mysqld start

echo "setting mysql"
echo "/usr/bin/mysql_secure_installation"
echo "mysql -u root -p"
echo "CREATE USER 'git'@'localhost' IDENTIFIED BY 'password';"
echo "CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;"
echo "GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'git'@'localhost';"
echo "\q"
echo "mysql -u git -p -D gitlabhq_production"
echo "\q"
echo "install1.sh"
3. 스크립트 마지막에 나온 mysql settnig을 진행합니다.
4. 두번째 스크립트를 돌립니다. dbpw에는 git의 mysql 암호, hostname에는 주소를 넣어줍니다.


#!/bin/sh

dbpw=""
hostname=""

cd /home/git
sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b master gitlab
cd /home/git/gitlab
sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
sudo -u git -H sed -i 's/localhost/'$hostname'/g' config/gitlab.yml
sudo -u git -H sed -i 's/\/usr\/bin\/git/\/usr\/local\/bin\/git/g' config/gitlab.yml
sudo chown -R git log/
sudo chown -R git tmp/
sudo chmod -R u+rwX  log/
sudo chmod -R u+rwX  tmp/
sudo -u git -H mkdir /home/git/gitlab-satellites
sudo -u git -H mkdir tmp/pids/
sudo -u git -H mkdir tmp/sockets/
sudo chmod -R u+rwX  tmp/pids/
sudo chmod -R u+rwX  tmp/sockets/
sudo -u git -H mkdir public/uploads
sudo chmod -R u+rwX  public/uploads
sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
sudo -u git -H git config --global user.name "GitLab"
sudo -u git -H git config --global user.email "gitlab@localhost"
sudo -u git -H git config --global core.autocrlf input
sudo -u git -H cp config/database.yml.mysql config/database.yml
sudo -u git -H sed -i 's/secure password/'$dbpw'/g' config/database.yml
cd /home/git/gitlab
sudo -u git -H /usr/local/bin/bundle install --deployment --without development test postgres aws

cd /home/git/gitlab
echo -e "yes" | sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production

wget -O /etc/init.d/gitlab https://gitlab.com/gitlab-org/gitlab-recipes/raw/master/init/sysvinit/centos/gitlab-unicorn
chmod +x /etc/init.d/gitlab
chkconfig --add gitlab
chkconfig gitlab on
cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
service gitlab start
sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production

#nginx install
yum update
yum -y install nginx
chkconfig nginx on
cp lib/support/nginx/gitlab /etc/nginx/conf.d/gitlab.conf

usermod -a -G git nginx
chmod g+rx /home/git/
5. 마지막으로 nginx 설정을 해줍니다.

upstream gitlab {
  server unix:/home/git/gitlab/tmp/sockets/gitlab.socket;
}

server {
  listen *:80;         # e.g., listen 192.168.1.1:80; In most cases *:80 is a good idea
  server_name 192.168.188.150;     # e.g., server_name source.example.com;
  server_tokens off;     # don't show the version number, a security best practice
  root /home/git/gitlab/public;

  # Increase this if you want to upload large attachments
  # Or if you want to accept large git objects over http
  client_max_body_size 20m;

  # individual nginx logs for this gitlab vhost
  access_log  /var/log/nginx/gitlab_access.log;
  error_log   /var/log/nginx/gitlab_error.log;

  location / {
    # serve static files from defined root folder;.
    # @gitlab is a named location for the upstream fallback, see below
    try_files $uri $uri/index.html $uri.html @gitlab;
  }
  location @gitlab {
    proxy_read_timeout 300; # Some requests take more than 30 seconds.
    proxy_connect_timeout 300; # Some requests take more than 30 seconds.
    proxy_redirect     off;

    proxy_set_header   X-Forwarded-Proto $scheme;
    proxy_set_header   Host              $http_host;
    proxy_set_header   X-Real-IP         $remote_addr;
    proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;

    proxy_pass http://gitlab;
  }

  # Enable gzip compression as per rails guide: http://guides.rubyonrails.org/asset_pipeline.html#gzip-compression
  location ~ ^/(assets)/  {
    root /home/git/gitlab/public;
    gzip_static on; # to serve pre-gzipped version
    expires max;
    add_header Cache-Control public;
  }

  error_page 502 /502.html;
}

접속 시 아이뒤/비번 : admin@local.host / 5iveL!fe
Comments