123213 发表于 2015-11-23 10:20:27

CentOS7 安装 Gitlab

GitLab,是一个利用 Ruby on Rails 开发的开源应用程序,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目。它拥有与Github类似的功能,能够浏览源代码,管理缺陷和注释。可以管理团队对仓库的访问,它非常易于浏览提交过的版本并提供一个文件历史库。团队成员可以利用内置的简单聊天程序(Wall)进行交流。它还提供一个代码片段收集功能可以轻松实现代码复用,便于日后有需要的时候进行查找。开源项目地址:https://github.com/gitlabhq/gitlabhq安装步骤1、提供一些必须包,提供epel,关闭防火墙和selinux等操作;2、gitlab依赖的python功能比较多,需要升级python到2.7.X;3、安装redis的内存数据库;4、安装MySQL的关系型数据库;5、为gitlab提供ruby的环境支持;6、提供gitlab-shell来管理git仓库;7、安装gitlab系统;8、安装nginx的web服务,做反向代理。
一、安装扩展源和依赖包

1
2
3
4
5
6
7
8
#安装扩展源
rpm -ivh epel-release-7-5.noarch.rpm   #修改/etc/yum.repo.d/epel.repo
#增加puias源
wget -O /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
#验证是否成功
rpm -qa gpg*




查看仓库源

1
2
3
4
5
6
7
8
9
10
11
12
yum repolist
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* PUIAS_6_computational: www.puias.princeton.edu
* epel: ftp.sjtu.edu.cn
仓库标识                              仓库名称                                                      状态
PUIAS_6_computational               PUIAS computational Base 6 - x86_64                           2,638
base                                  CentOS-6 - Base - 163.com                                     6,518
*epel                                 Extra Packages for Enterprise Linux 6 - x86_64                11,148
extras                              CentOS-6 - Extras - 163.com                                 36
updates                               CentOS-6 - Updates - 163.com                                  727
repolist: 21,067




如果此列表中没有epel和PUIAS_6_computational,请执行以下命令

1
yum-config-manager --enable epel --enable PUIAS_6_computational






二、安装依赖包

1
2
3
yum -y update
yum -y groupinstall 'Development Tools‘
yum -y install readline readline-devel ncurses-devel gdbm-devel glibc-devel tcl-devel openssl-devel curl-devel expat-devel db4-devel byacc sqlite-devel 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 cmake libcom_err-devel libcom_err-devel






三、安装Git

1
2
3
4
5
6
7
8
yum -y remove git
yum -y install zlib-devel perl-CPAN gettext curl-devel expat-devel gettext-devel openssl-devel
mkdir /tmp/git && cd /tmp/git
wget
tarzxvfgit-2.6.0.tar.gz
cd   git-2.6.0
./configure--prefix=/usr/local
make && make install




验证Git

1
git --version





四、安装Ruby

1
2
3
4
5
6
7
yum -y remove ruby
cd /tmp/git
wget
tar zxvfruby-2.2.3.tar.gz
cd ruby-2.2.3
./configure --prefix=/usr/local/ruby --disable-install-rdoc
make && make install




验证Ruby

1
2
ruby -v
ruby 2.2.3p173 (2015-08-18 revision 51636)




修改RubyGames镜像为淘宝,提高下载速度

1
2
vim /home/git/gitlab/Gemfile
   source "#替换为淘宝




安装bundler

1
gem install bundler --no-doc





五、创建系统用户

1
adduser --system --shell /bin/bash --comment 'GitLab' --create-home --home-dir /home/git/ git





六、修改sudo文件,让git用户使用sudo

1
2
3
4
visudo
Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin#替换为这个
#在root    ALL=(ALL)       ALL下增加一行
   git   ALL=(ALL)       ALL





七、安装MySQL

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#卸载CentOS7自带的MaraiaDB
rpm -qa | grep maraiadb
yum -yremove maraiadb
#安装依赖包
yum -y install make gcc-c++ cmake bison-develncurses-devel
#下载MySQL
cd /tmp/git
wget wget
tar zxvfmysql-5.6.20.tar.gz
cd /mysql-5.6.20
#编译MySQL
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
#安装
make && make install
#配置MySQL用户
groupadd mysql
useradd -g mysql mysql
#修改/usr/local/mysql
chown -R mysql:mysql /usr/local/mysql
#初始化MySQL
cd /usr/local/mysql
#执行初始化脚本
scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
#添加服务,设置开机启动
cp support-files/mysql.server /etc/init.d/mysql
chkconfig mysql on
service mysql start--启动MySQL
#配置变量
vim /etc/profile
PATH=/usr/local/mysql/bin:$PATH
export PATH
source/etc/profile




创建数据库、数据库用户和并授权

1
2
3
4
mysql -u root -p
mysql> CREATE USER 'git'@'localhost' IDENTIFIED BY '123.com';
mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
mysql> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'git'@'localhost';




测试能否成功登陆

1
mysql -ugit -p123.com -D gitlabhq_production





八、配置Redis

1
2
3
4
5
6
7
8
9
10
11
chkconfig redis on

cp /etc/redis.conf /etc/redis.conf.orig

#修改监听端口
sed 's/^port .*/port 0/' /etc/redis.conf.orig |tee /etc/redis.conf

#增加内容
echo 'unixsocket /var/run/redis/redis.sock' |tee -a /etc/redis.conf

echo -e 'unixsocketperm 0770' |tee -a /etc/redis.conf




创建目录改权限

1
2
3
4
5
mkdir /var/run/redis

chown redis:redis /var/run/redis

chmod 755 /var/run/redis




启动服务

1
service redis restart




添加git到redis组

1
usermod -aG redis git





九、安装GitLab

1
2
3
4
cd /home/git

#下载源码
sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 7-4-stable gitlab




修改配置

1
2
3
4
5
6
7
8
9
10
cd gitLab/

sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml

sudo -u git -H vim config/gitlab.yml
gitlab:
    ## Web server settings (note: host is the FQDN, do not include http://)
    host: localhost
    port: 80
    https: false




修改目录权限

1
2
3
4
5
6
7
chown -R git log/
chown -R git tmp/
chmod -R u+rwX log/
chmod -R u+rwX tmp/
chmod -R u+rwX tmp/pids/
chmod -R u+rwX tmp/sockets/
chmod -R u+rwXpublic/uploads




创建目录

1
2
sudo -u git -H mkdir /home/git/gitlab-satellites
chmod u+rwx,g=rx,o-rwx /home/git/gitlab-satellites




编辑配置文件unicorn.rb

1
2
3
4
5
6
7
8
9
sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb

#查看系统核心数
nproc
1

#编辑配置
sudo -u git -H vim config/unicorn.rb
worker_processes 1




拷贝配置文件

1
sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb




定义全局用户和邮箱

1
2
3
sudo -u git -H git config --global user.name "GitLab"
sudo -u git -H git config --global user.email "example@example.com"
sudo -u git -H git config --global core.autocrlf input




编辑连接redis配置

1
2
3
4
5
#拷贝配置
sudo -u git -H cp config/resque.yml.example config/resque.yml

#连接redis配置,默认配置,未修改
sudo -u git -H vim config/resque.yml





十、配置GitLab数据库文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
sudo -u git cp config/database.yml.mysql config/database.yml

#编辑配置文件
sudo -u git -H vim config/database.yml
production:
adapter: mysql2
encoding: utf8
collation: utf8_general_ci
reconnect: false
database: gitlabhq_production
pool: 10
username: git
password: "gitpwd"
host: localhost
socket: /var/lib/mysql/mysql.sock

#修改文件权限,只有git用户可读
sudo -u git -H chmod o-rwx config/database.yml





十一、安装gem

1
2
3
cd /home/git/gitLab

sudo -u git -H bundle install --deployment --without development test postgres aws





十二、安装GitLab-shell

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
sudo -u git -H bundle exec rake gitlab:shell:install REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production
#编辑配置
sudo -u git -H vim /home/git/gitlab-shell/config.yml
---
user: git
gitlab_url: https://localhost/
http_settings:
self_signed_cert: true
repos_path: "/home/git/repositories/"
auth_file: "/home/git/.ssh/authorized_keys"
redis:
bin: "/usr/bin/redis-cli"
namespace: resque:gitlab
socket: "/var/run/redis/redis.sock"
log_level: INFO
audit_usernames: false





十三、初始化数据库

1
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production





十四、下载服务脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
wget -O /etc/init.d/gitlab
chmod +x /etc/init.d/gitlab

chkconfig --add gitlab

chkconfig gitlab on

#设置logrotate
cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab

#检测应用状态
sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production

sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production

#给bin/webbin/background_jobs目录权限
chmod755/home/git/gitlab/bin/web

chmod755/home/git/gitlab/bin/background_jobs

#启动服务
service gitlab start





十五、配置Web服务

1
2
3
4
5
6
#本人使用的nginx
yum -y install nginx

chkconfig nginx on

wget -O /etc/nginx/conf.d/gitlab.conf https://gitlab.com/gitlab-org/gitlab-ce/raw/master/lib/support/nginx/gitlab-ssl




添加nginx到git组

1
2
3
usermod -a -G git nginx

chmod g+rx /home/git/




修改配置,修改server_name

1
2
3
4
5
6
vim /etc/nginx/conf.d/gitlab.conf
#两个server_name如果没有域名,改成自己的IP地址

#注释nginx.conf中的监听端口,不然后边启动nginx,会报错
vim/etc/nginx/nginx.conf
   listen       [::]:80 default_server;   注释掉




添加SSL

1
2
3
4
5
mkdir /etc/nginx/ssl

执行openssl req -newkey rsa:2048 -x509 -nodes -days 3560 -out gitlab.crt -keyout gitlab.key#随便填就行,最后生成gitlab.crtgitlab.key

cp gitlab.crtgitlab.key /etc/nginx/ssl




启动nginx 服务

1
2
3
4
5
service nginx start

#访问登录
#用户名:root
#密码:5iveL!fe






页: [1]
查看完整版本: CentOS7 安装 Gitlab