Centos7安装gitlab
2016-01-01 15:01
615 查看
安装基本系统与依赖包
安装 Gitlab 依赖的工具
bashyum -y updateyum -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 git redis ruby sudo wget crontabs logwatch logrotate perl-Time-HiRes
安装 Redis
访问 http://www.redis.io/download ,下载 Redis 源代码。bashwget http://download.redis.io/releases/redis-3.0.0.tar.gz tar zxvf redis-3.0.0.tar.gz cd redis-3.0.0make若在编译过程中出错,则可以执行下面的命令:
bashsudo make test
安装:
bashsudo make install sudo ./utils/install_server.sh
配置
创建/etc/init.d/redis并使用下面的代码作为启动脚本。添加如下内容:
bash###########################PATH=/usr/local/bin:/sbin:/usr/bin:/bin REDISPORT=6379 EXEC=/usr/local/bin/redis-server REDIS_CLI=/usr/local/bin/redis-cli PIDFILE=/var/run/redis.pid CONF="/etc/redis/6379.conf"case "$1" in start) if [ -f $PIDFILE ] then echo "$PIDFILE exists, process is already running or crashed" else echo "Starting Redis server..." $EXEC $CONF fi if [ "$?"="0" ] then echo "Redis is running..." fi ;; stop) if [ ! -f $PIDFILE ] then echo "$PIDFILE does not exist, process is not running" else PID=$(cat $PIDFILE) echo "Stopping ..." $REDIS_CLI -p $REDISPORT SHUTDOWN while [ -x ${PIDFILE} ] do echo "Waiting for Redis to shutdown ..." sleep 1 done echo "Redis stopped" fi ;; restart|force-reload) ${0} stop ${0} start ;; *) echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2 exit 1 esac##############################保存后,添加可执行权限:
sudo chmod +x /etc/init.d/redis确保
redis能随系统启动:
vi /etc/rc.d/rc.local在文件末尾添加下面这行:
service redis start然后使用上面同样的命令启动
redis服务:
service redis start
安装邮件服务器
yum -y install postfix
安装Git
先删除系统中原有的老版本git:
bashyum -y remove git yum install zlib-devel perl-CPAN gettext curl-devel expat-devel gettext-devel openssl-devel从官方网站下载源代码进行:
bashcurl --progress https://www.kernel.org/pub/software/scm/git/git-2.4.0.tar.gz | tar xzcd git-2.4.0/ ./configure make make prefix=/usr/local install然后使用下面这个命令检测安装是否有效:
which git
安装 ruby
如果 ruby 的版本低于2.0的话,则需要重新安装
ruby。
bashcd ~ curl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.2/ruby-2.2.2.tar.gz | tar xzcd ruby-2.2.2 ./configure --disable-install-rdocmake make prefix=/usr/local install
为 Gitlab 添加系统用户
adduser --system --shell /bin/bash --comment 'GitLab' --create-home --home-dir /home/git/ git为了包含/usr/local/bin到git用户的$PATH,一个方法是编辑超级用户文件。以管理员身份运行:
visudo然后搜索:
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin将其改成:
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
安装数据库
MySQL 已经不再包含在 CentOS 7 的源中,而改用了 MariaDB,先搜索MariaDB现有的包:
rpm -qa | grep mariadb然后全部删除:
rpm -e --nodeps mariadb-*然后创建
/etc/yum.repos.d/MariaDB.repo:
vi /etc/yum.repos.d/MariaDB.repo将以下内容添加至该文件中:
# MariaDB 10.0 CentOS repository list - created 2015-05-04 19:16 UTC# http://mariadb.org/mariadb/repositories/[mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.0/centos7-amd64gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDBgpgcheck=1[/code]然后运行下面命令安装MariaDB 10.0:sudo yum install MariaDB-server MariaDB-client然后启动 MariaDB 服务:service mysql start接着运行mysql_secure_installation:mysql_secure_installation登录 MariaDB 并创建相应的数据库用户与数据库:mysql -uroot -pCREATE USER 'git'@'localhost' IDENTIFIED BY '$password';SET storage_engine=INNODB;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 'git'@'localhost';\q尝试使用新用户连接数据库:sudo -u git -H mysql -u git -p -D gitlabhq_production \q安装 Gitlab
克隆源
sudo -u -git cd /home/git sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 7-10-stable gitlab配置
cd /home/git/gitlab # Copy the example GitLab config # 复制GitLab的示例配置文件 sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml # Make sure to change "localhost" to the fully-qualified domain name of your host serving GitLab where necessary # 确保修改“localhost”为你的GitLab主机的FQDN # # If you want to use https make sure that you set `https` to `true`. See #using-https for all necessary details. # 如果你想要使用https确保你设置了`https`为`true`。具体必要的细节参见#using-https # # If you installed Git from source, change the git bin_path to /usr/local/bin/git # 如果你从源代码安装了Git,修改git的bin_path为/usr/local/bin/git sudo -u git -H editor config/gitlab.yml # Make sure GitLab can write to the log/ and tmp/ directories # 确保GitLab可以写入log/和temp/目录 chown -R git {log,tmp} chmod -R u+rwX {log,tmp} # Create directory for satellites # 为卫星(?)创建目录 sudo -u git -H mkdir /home/git/gitlab-satellites chmod u+rwx,g+rx,o-rwx /home/git/gitlab-satellites # Make sure GitLab can write to the tmp/pids/ and tmp/sockets/ directories # 确保GitLab可以写入tmp/pids/和temp/sockets/目录 chmod -R u+rwX tmp/{pids,sockets} # Make sure GitLab can write to the public/uploads/ directory # 确保GitLab可以写入public/uploads/目录 chmod -R u+rwX public/uploads # Copy the example Unicorn config # 复制Unicorn的示例配置文件 sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb # Enable cluster mode if you expect to have a high load instance # Ex. change amount of workers to 3 for 2GB RAM server # 启用集群模式如果你期望拥有一个高负载实例 # 附:修改worker的数量到3用于2GB内存的服务器 sudo -u git -H editor config/unicorn.rb # Copy the example Rack attack config # 复制Rack attack的示例配置文件 sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb # Configure Git global settings for git user, useful when editing via web # Edit user.email according to what is set in config/gitlab.yml # 为git用户配置Git全局设定,当通过web修改时有用 # 修改user.email根据config/gitlab.yml中的设定 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数据库配置
# MySQL only: # 仅限MySQL: sudo -u git cp config/database.yml.mysql config/database.yml # MySQL and remote PostgreSQL only: # Update username/password in config/database.yml. # You only need to adapt the production settings (first part). # If you followed the database guide then please do as follows: # Change 'secure password' with the value you have given to $password # You can keep the double quotes around the password # 仅限MySQL和远程PostgreSQL: # 在config/database.yml中更新用户名/密码; # 你只需要适配生产设定(第一部分); # 如果你跟从数据库向导,请按以下操作: # 修改'secure password'使用你刚才设定的$password; # 你可以保留密码两端的双引号。 sudo -u git -H editor config/database.yml # PostgreSQL and MySQL: # Make config/database.yml readable to git only# PostgreSQL和MySQL: # 设置config/database.yml仅对git可读。 sudo -u git -H chmod o-rwx config/database.yml安装 Gems
cd /home/git/gitlab# For users from China mainland only# 仅限中国大陆用户nano /home/git/gitlab/Gemfile source "http://ruby.taobao.org" // 原始 source "https://rubygems.org/"# For MySQL (note, the option says "without ... postgres")sudo -u git -H bundle install --deployment --without development test postgres awsInstall GitLab shell
安装GitLab Shell
GitLab Shell是一个专门为GitLab开发的SSH访问和源管理软件。# Go to the Gitlab installation folder:# 转到GitLab安装目录:cd /home/git/gitlab# For users from China mainland only# 仅限中国大陆用户nano /home/git/gitlab/Gemfile source "http://ruby.taobao.org" // 原始 source "https://rubygems.org/"# Run the installation task for gitlab-shell (replace `REDIS_URL` if needed):# 运行gitlab-shell的安装任务(替换`REDIS_URL`如果有需要的话):sudo -u git -H bundle exec rake gitlab:shell:install[v1.9.6] REDIS_URL=redis://localhost:6379 RAILS_ENV=production# By default, the gitlab-shell config is generated from your main gitlab config.# 默认的,gitlab-shell的配置文件是由你的gitlab主配置文件生成的。## Note: When using GitLab with HTTPS please change the following:# - Provide paths to the certificates under `ca_file` and `ca_path options.# - The `gitlab_url` option must point to the https endpoint of GitLab.# - In case you are using self signed certificate set `self_signed_cert` to `true`.# See #using-https for all necessary details.# 提示:当通过HTTPS使用GitLab时,请做出如下更改:# - 提供证书的路径在`ca_file`和`ca_path`选项;# - `gitlab_url`选项必须指向GitLab的https端点;# - 如果你使用自签名的证书,设置`self-signed_cert`为`true`。# 所有必需的具体细节参见#using-https## You can review (and modify) it as follows:# 你可以检查(并修改该)通过以下方法:sudo -u git -H editor /home/git/gitlab-shell/config.yml# Ensure the correct SELinux contexts are set# Read http://wiki.centos.org/HowTos/Network/SecuringSSH# 确保正确的SELinux上下文被设置# 阅读http://wiki.centos.org/HowTos/Network/SecuringSSHrestorecon -Rv /home/git/.ssh初始化数据库和激活高级功能
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production # Type 'yes' to create the database tables. # When done you see 'Administrator account created:'提示:你可以设置管理员密码通过在环境变量GITLAB_ROOT_PASSWORD中提供,例如:sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=newpassword安装初始化脚本
下载初始化脚本(将放在/etc/init.d/gitlab):sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab chmod +x /etc/init.d/gitlab chkconfig --add gitlab设置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编译静态文件
sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production启动实例
/etc/init.d/gitlab start
相关文章推荐
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- C#获取网页源代码的方法
- LCL.VBS 病毒源代码
- ASP常用源代码的总结(上)
- php查看网页源代码的方法
- User Scripts: Video Download by User Scripts
- Lua中的源代码预编译浅析
- ASP常用源代码的总结(下)
- android private libraries 中的包源代码添加方法
- jQuery-digest | 咀嚼jQuery源码
- 掌握主流框架的源码实现,理解框架背后的思想(续) 3ff0
- 2048 C++源代码by Reason
- Spark源码分析(1) 从WordCount示例看Spark延迟计算原理
- 37、chen框架v2源代码和示例项目发布
- [源码]Norton Ghost C# 源代码
- [源代码]symantec远程控制软件PcAnywhere源代码分享
- [源代码]Torque3D引擎SDK
- [游戏源码]Doom3公布源代码下载
- 《Doom 3》源代码将在《Rage》上市后免费发布
- 【资料分享】网游[天龙八部]源代码分享