目录
1. 安装额外的包仓库
2. 安装必需的软件包
3. 安装git 1.8版本。
4. 设置redis自动启动
5. 安装ruby
6. 创建git系统用户
7. 安装GitLab shell
8. 安装MySQL数据库
9. 安装GitLab
下载
配置
配置GitLab数据库链接
安装Gems
初始化数据库并激活高级特性
安装init脚本
检查应用程序状况
启动gitlab
再次检查应用程序状态
10. 配置Apache
创建SSL证书
创建虚拟主机
11. 配置防火墙
12. 完成!
因开发需要,我需要安装一个Git服务器供公司内部做代码托管之用。当前最著名的Git服务器就是GitLab。Scientific Linux是重新编译的Red Hat Enterprise Linux,由费米国家加速器实验室、欧洲核研究组织以及世界各地的大学和实验室共同开发。
下面记录下我在Scientific Linux 6.4版上安装GitLab 6.0.2的过程。
1. 安装额外的包仓库
sudo wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 https://Fedoraproject.org/static/0608B895.txt
sudo rpm –import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
sudo rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
sudo yum-config-manager –enable epel
sudo rpm -ivh http://li.nux.ro/download/nux/dextop/el6/x86_64/nux-dextop-release-0-2.el6.nux.noarch.rpm
2. 安装必需的软件包
su –
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 Python-devel redis sudo wget crontabs logwatch logrotate perl-Time-HiRes python27 python27-devel
如果一些软件包(例如gdbm-devel, libffi-devel和libicu-devel)未能安装,运行下面的命令:
yum-config-manager –enable rhel-6-server-optional-rpms
然后重新安装上面的软件包。
3. 安装git 1.8版本。
su –
cd /tmp
yum -y install git perl-ExtUtils-MakeMaker
git clone git://github.com/git/git.git
cd /tmp/git/
git checkout v1.8.4
autoconf
./configure –prefix=/usr/local
make && make install
rm -rf /tmp/git/
yum erase git
4. 设置redis自动启动
sudo chkconfig redis –level 235 on
sudo service redis start
5. 安装ruby
curl –progress ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p247.tar.gz | tar xz
mkdir /tmp/ruby && cd /tmp/ruby
curl –progress ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p247.tar.gz | tar xz
cd ruby-2.0.0-p247
./configure –prefix=/usr/local/
make && make install
sudo gem install bundler –no-ri –no-rdoc
6. 创建git系统用户
su –
adduser –system –shell /bin/bash –comment ‘GitLab’ –create-home –home-dir /home/git/ git
su –
echo adminlogs@example.com > /root/.forward
chown root /root/.forward
chmod 600 /root/.forward
restorecon /root/.forward
echo adminlogs@example.com > /home/git/.forward
chown git /home/git/.forward
chmod 600 /home/git/.forward
restorecon /home/git/.forward
7. 安装GitLab shell
su –
su – git
git clone https://github.com/gitlabhq/gitlab-shell.git
cd gitlab-shell
git checkout v1.7.0
cp config.yml.example config.yml
vim config.yml
修改gitlab_url为http://git.linuxidc.com/
./bin/install
8. 安装MySQL数据库
su –
yum install -y mysql-server mysql-devel
chkconfig mysqld –level 235 on
service mysqld start
登录MySQL
mysql -u root -p
CREATE USER ‘gitlab’@’localhost’ IDENTIFIED BY ‘supersecret’;
CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO ‘gitlab’@’localhost’;
\q
GitLab 的详细介绍:请点这里
GitLab 的下载地址:请点这里
相关阅读:
在 Ubuntu 12.04 上安装 GitLab http://www.linuxidc.com/Linux/2012-12/75249.htm
GitLab 5.3 升级注意事项 http://www.linuxidc.com/Linux/2013-06/86473.htm
在 CentOS 上部署 GitLab (自托管的Git项目仓库) http://www.linuxidc.com/Linux/2013-06/85754.htm
9. 安装GitLab
下载
su –
su – git
git clone https://github.com/gitlabhq/gitlabhq.git gitlab
cd /home/git/gitlab
git checkout 6-0-stable
配置
cp config/gitlab.yml.example config/gitlab.yml
sed -i ‘s|localhost|git.linuxidc.com|g’ config/gitlab.yml
sed -i ‘s|/usr/bin/git|/usr/local/bin/git|’ config/gitlab.yml
chown -R git log/
chown -R git tmp/
chmod -R u+rwX log/
chmod -R u+rwX tmp/
mkdir /home/git/gitlab-satellites
mkdir tmp/pids/
mkdir tmp/sockets/
chmod -R u+rwX tmp/pids/
chmod -R u+rwX tmp/sockets/
mkdir public/uploads
chmod -R u+rwX public/uploads
cp config/unicorn.rb.example config/unicorn.rb
如果希望负载均衡可开启集群模式
vi config/unicorn.rb
将8080改为9292
git config –global user.name “GitLab”
git config –global user.email “gitlab@git.linuxidc.com”
git config –global core.autocrlf input
配置GitLab数据库链接
cp config/database.yml{.mysql,}
vim config/database.yml
修改数据库用户帐号和口令
chmod o-rwx config/database.yml
安装Gems
su –
gem install charlock_holmes –version ‘0.6.9.4’
exit
cd /home/git/gitlab/
bundle install –deployment –without development test postgres puma aws
初始化数据库并激活高级特性
cd /home/git/gitlab
bundle exec rake gitlab:setup RAILS_ENV=production
安装init脚本
su –
cp lib/support/init.d/gitlab /etc/init.d/gitlab
chmod +x /etc/init.d/gitlab
chkconfig –add gitlab
chkconfig gitlab –level 235 on
检查应用程序状况
su – git
cd gitlab/
bundle exec rake gitlab:env:info RAILS_ENV=production
exit
启动gitlab
service gitlab start
再次检查应用程序状态
su – git
cd gitlab/
bundle exec rake gitlab:check RAILS_ENV=production
如果所有的项目都是绿色的,就表明安装成功了。
10. 配置Apache
创建SSL证书
mkdir /etc/httpd/ssl.crt/
cd /etc/httpd/ssl.crt/
openssl genrsa -out git.linuxidc.com.key 1024
openssl req -new -key git.linuxidc.com.key -out git.linuxidc.com.csr
根据提示输入证书信息。
创建虚拟主机
su –
yum -y install httpd mod_ssl
chkconfig httpd on
wget -O /etc/httpd/conf.d/gitlab.conf https://raw.github.com/gitlabhq/gitlab-recipes/master/web-server/apache/gitlab.conf
vim /etc/httpd/conf.d/gitlab.conf
将git.example.org改为git.linuxidc.com(或你的域名)。
将8080改为9292。
在 /etc/httpd/conf/httpd.conf中加入LoadModule ssl_module /etc/httpd/modules/mod_ssl.so
vim /etc/httpd/conf/httpd.conf,加入下面内容:
NameVirtualHost *:80
2 <IfModule mod_ssl.c>
3 NameVirtualHost *:443
4 Listen 443
5 </IfModule>
在SELinux上开放http访问
setsebool -P httpd_can_network_connect on
service httpd restart
11. 配置防火墙
修改/etc/sysconfig/iptables,设置下面的内容:
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 443 -j ACCEPT
-A INPUT -j REJECT –reject-with icmp-host-prohibited
-A FORWARD -j REJECT –reject-with icmp-host-prohibited
COMMIT
重启iptables:
service iptables restart
12. 完成!
可以用浏览器通过http://git.linuxidc.com访问。