title: 持续集成系统搭建(一) Jenkins + Redmine + CAS + github OAuth2 实现 SSO
tag:
- CI
- SSO
- OAuth2
- Jenkins
- Redmine
- Linux
date: 2016-11-08 18:14:08
tags:
安装Jetty服务器
解压到 /opt/eclipse/jetty
$ ln -s /opt/eclipse/jetty/bin/jetty.sh /etc/init.d/jetty
新建 /etc/default/jetty
加入
JAVA_HOME=/usr/bin/java
JETTY_HOME=/opt/eclipse/jetty
修改 /opt/eclipse/jetty/start.ini 中的配置
jetty.http.host=127.0.0.1 //修改绑定ip为本地
jetty.http.port=8088 //修改端口
将jetty加入系统启动服务
$ update-rc.d jetty defaults
配置nginx服务器,实现代理
在 /etc/nginx/site-enable 中增加一个配置 ci
内容如下
server {
listen 80; listen [::]:80; server_name ci.joseph-han.net; location /jenkins/ { proxy_pass http://127.0.0.1:8088/jenkins/; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }
}
以管理员身份登陆Jenkins,设置当前服务器为Master,设置从节点数量为5个
VPS内核太低,不支持docker,等带自己的服务器环境搭建完成再上Jenkins集群 :(
配置docker,实现swarm集群
配置swarm master节点
配置swarm salve节点
##安装Redmine
- 在mysql创建redmine数据库
- 为Nginx安装Phusion Passenger Passenger 官网安装指导
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7
sudo apt-get install -y apt-transport-https ca-certificates
sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger xenial main > /etc/apt/sources.list.d/passenger.list’
sudo apt-get update
sudo apt-get install -y nginx-extras passenger
修改/etc/nginx/nginx.conf
include /etc/nginx/passenger.conf;
sudo service nginx restart
验证
sudo /usr/bin/passenger-config validate-install
sudo /usr/sbin/passenger-memory-stats
- 配置 nginx
vim /etc/nginx/sites-enable/ci
location ~ ^/redmine(/.*|$) { alias /opt/CI/redmine/public$1; # <-- be sure to point to 'public'! passenger_base_uri /redmine; passenger_app_root /opt/CI/redmine; passenger_document_root /opt/CI/redmine/public; passenger_enabled on; }
- 下载redmine
cd /opt/CI
wget http://www.redmine.org/releases/redmine-3.3.1.tar.gz
tar vxf redmine-3.3.1.tar.gz
ln -s /opt/CI/redmine-3.3.1 ./redmine
chown -R www-data.www-data /opt/CI
- 配置redmine
cd /opt/CI/redmine/config
cp configuration.yml.example configuration.yml
cp database.yml.example database.yml
配置db
- 安装ruby依赖
gem install bundler
apt install libroot-bindings-ruby-dev
apt install libmysqlclient-dev
apt install libmagickwand-dev
bundle install --without development test
- 生成tocken和数据表:
bundle exec rake generate_secret_token
RAILS_ENV=production bundle exec rake db:migrate
RAILS_ENV=production bundle exec rake redmine:load_default_data
安装CAS
- 下载cas并编译cas-gradle-overlay-template,
注意为了使用github代理登陆一定要添加依赖 Reference: Delegate Authentication
vim ~/cas-gradle-overlay-template/cas/build.gradle
1 | dependencies { |
cd ~/cas-gradle-overlay-template;./gradlew clean build
//到~/cas-gradle-overlay-template/cas/build/libs下把cas.war拷贝到/opt/CI/
将~/cas-gradle-overlay-template/etc/cas/ 下的配置文件解压到/etc/cas下
- 配置nginx服务器,实现ssl代理
生成服务器ssl证书
注意:名字一定要是服务器域名
1 | 证书文件生成: |
//3. 配置CAS Reference: CAS Properties
// >vim /opt/CI/cas/WEB-INF/classes/application.properties
- 配置cas增加github代理认证
vim /opt/CI/cas/WEB-INF/spring-configuration/applicationContext.xml
1 | <bean id="github" class="org.pac4j.oauth.client.GitHubClient"> |
修改service id,使http的客户端也可以访问https的服务器
vim /opt/CI/cas/WEB-INF/classes/services/Apereo-10000002.json
1 | "serviceId" : "^http.*", //原来是https:// |
事先生成下面要用的密钥 Reference: secret key tool
vim /opt/CI/cas/WEB-INF/cas.properties
1 | # The encryption secret key. By default, must be a octet string of size 256. |
Redmine 关联 CAS
cd /opt/CI/redmine/plugins/
git clone https://github.com/joseph-bing-han/redmine_omniauth_cas.git
我fork了插件代码,增加了自动创建用户到db的逻辑
登陆管理页面配置正确cas域名即可
Jenkins 关联 CAS
登陆系统,在插件管理页面安装CAS plugins http://ci.joseph-han.net/jenkins/pluginManager/available
配置好cas域名,重启服务即可