您的位置:首页 > 编程语言 > Ruby

rubyCas服务器搭建 (一)

2013-10-14 13:02 537 查看
1、安装ruby

wget http://ruby.taobao.org/mirrors/ruby/1.9/ruby-1.9.2-p180.tar.bz2
tar -xjvf ruby-1.9.2-p180.tar.bz2

cd ruby-1.9.2-p180

./configure –prefix=/usr/local/ruby

make && make install

在/etc/profile文件末尾添加一行:export PATH=$PATH:/usr/local/ruby/bin

export PATH=$PATH:/usr/local/ruby/bin

在/etc/profile.d/path.sh文件中追加:/usr/local/ruby/bin

ruby –v

2.

安装rubygems

wget http://rubyforge.org/frs/download.php/74445/rubygems-1.6.2.tgz
tar xzvf rubygems-1.6.2.tgz

cd rubygems-1.6.2

sudo ruby setup.rb

sudo gem sources –a http://ruby.taobao.org/
sudo gem sources –r http://rubygems.org/
gem –v

3. 安装openssl-devel

sudo yum –y install openssl-devel(Git依赖的库)

4.安装 rubycas-server

gem install rubycas-server

5.

[root@openstack /]# ruby /usr/local/rvm/gems/ruby-1.9.2-p180/bin/rubycas-server



!!! Config file /etc/rubycas-server/config.yml does not exist!





>>> Would you like the default config file copied to "/etc/rubycas-server/config.yml"? [y/N]



y



>>> Creating config directory...



mkdir -p /etc/rubycas-server



>>> Copying "/usr/local/rvm/gems/ruby-1.9.2-p180/gems/rubycas-server-1.1.2/lib/casserver/../../config/config.example.yml" to "/etc/rubycas-server/config.yml"...



cp /usr/local/rvm/gems/ruby-1.9.2-p180/gems/rubycas-server-1.1.2/lib/casserver/../../config/config.example.yml /etc/rubycas-server/config.yml



>>> The default config has been copied. You should now edit it and try starting again.



[root@openstack /]#

[root@openstack /]# ruby /usr/local/rvm/gems/ruby-1.9.2-p180/bin/rubycas-server



>>> Redirecting RubyCAS-Server log to /var/log/casserver.log





>>> Running migrations to make sure your database schema is up to date...



/usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.19/lib/active_record/connection_adapters/mysql_adapter.rb:629:in `real_connect': Access denied for user 'root'@'localhost' (using password: NO) (Mysql::Error)

from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.19/lib/active_record/connection_adapters/mysql_adapter.rb:629:in `connect'

from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.19/lib/active_record/connection_adapters/mysql_adapter.rb:164:in `initialize'

from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.19/lib/active_record/connection_adapters/mysql_adapter.rb:36:in `new'

from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.19/lib/active_record/connection_adapters/mysql_adapter.rb:36:in `mysql_connection'

from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.19/lib/active_record/connection_adapters/abstract/connection_pool.rb:229:in `new_connection'

from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.19/lib/active_record/connection_adapters/abstract/connection_pool.rb:237:in `checkout_new_connection'

from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.19/lib/active_record/connection_adapters/abstract/connection_pool.rb:191:in `block (2 levels) in checkout'

from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.19/lib/active_record/connection_adapters/abstract/connection_pool.rb:187:in `loop'

from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.19/lib/active_record/connection_adapters/abstract/connection_pool.rb:187:in `block in checkout'

from /usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'

from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.19/lib/active_record/connection_adapters/abstract/connection_pool.rb:186:in `checkout'

from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.19/lib/active_record/connection_adapters/abstract/connection_pool.rb:94:in `connection'

from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.19/lib/active_record/connection_adapters/abstract/connection_pool.rb:317:in `retrieve_connection'

from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.19/lib/active_record/connection_adapters/abstract/connection_specification.rb:97:in `retrieve_connection'

from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.19/lib/active_record/connection_adapters/abstract/connection_specification.rb:89:in `connection'

from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.19/lib/active_record/migration.rb:488:in `initialize'

from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.19/lib/active_record/migration.rb:435:in `new'

from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.19/lib/active_record/migration.rb:435:in `up'

from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.19/lib/active_record/migration.rb:417:in `migrate'

from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/rubycas-server-1.1.2/lib/casserver/server.rb:276:in `init_database!'

from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/rubycas-server-1.1.2/lib/casserver/server.rb:287:in `block in <class:Server>'

from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/sinatra-1.4.3/lib/sinatra/base.rb:1385:in `configure'

from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/rubycas-server-1.1.2/lib/casserver/server.rb:284:in `<class:Server>'

from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/rubycas-server-1.1.2/lib/casserver/server.rb:10:in `<module:CASServer>'

from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/rubycas-server-1.1.2/lib/casserver/server.rb:9:in `<top (required)>'

from /usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:54:in `require'

from /usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:54:in `require'

from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/rubycas-server-1.1.2/lib/casserver.rb:10:in `<top (required)>'

from /usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:54:in `require'

from /usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:54:in `require'

from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/rubycas-server-1.1.2/bin/rubycas-server:28:in `<top (required)>'

from /usr/local/rvm/gems/ruby-1.9.2-p180/bin/rubycas-server:19:in `load'

from /usr/local/rvm/gems/ruby-1.9.2-p180/bin/rubycas-server:19:in `<main>'

6.修改配置文件如下

vi /etc/rubycas-server/config.yml

database:

adapter: mysql

database: casserver

username: root

password: funkpass

host: localhost

reconnect: true

authenticator:

# - class: CASServer::Authenticators::Google

- class: CASServer::Authenticators::SQL

database:

adapter: mysql

database: casserver

username: root

password: funkpass

host: localhost

user_table: user

username_column: username

password_column: password

【正式用的时候不要用root了,另授权mysql用户】

7.创建对应的表

[root@xen190v-ttt bin]# mysql -h127.0.0.1 -uroot -pfunkpass casserver

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 352428

Server version: 5.1.52 Qihoo.com



Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.



mysql> create table user

(

userid int not null auto_increment,

username varchar(40) not null,

password varchar(40) not null,

full_name varchar(50) null,

access_level int null,

primary key(userid)

);

Query OK, 0 rows affected (0.01 sec)



mysql> quit

8.

[root@openstack /]# ruby /usr/local/rvm/gems/ruby-1.9.2-p180/bin/rubycas-server



>>> Redirecting RubyCAS-Server log to /var/log/casserver.log





>>> Running migrations to make sure your database schema is up to date...



D, [2013-10-14T10:45:59.082615 #15680] DEBUG -- : SCHEMA (0.3ms) SHOW TABLES

D, [2013-10-14T10:45:59.143210 #15680] DEBUG -- : SCHEMA (60.2ms) SHOW TABLES

D, [2013-10-14T10:45:59.144414 #15680] DEBUG -- : SQL (0.1ms) SELECT `schema_migrations`.`version` FROM `schema_migrations`

I, [2013-10-14T10:45:59.144572 #15680] INFO -- : Migrating to CreateInitialStructure (1)



>>> Your database is now up to date.



== RubyCAS-Server is starting up on port 443 for development with backup from WEBrick



!!! The specified certificate file "/path/to/your/ssl.pem" does not exist or is not readable. Your 'ssl_cert' configuration setting must be a path to a valid ssl certificate.



/usr/local/rvm/gems/ruby-1.9.2-p180/gems/rubycas-server-1.1.2/lib/casserver/server.rb:175:in `handler_ssl_options': The specified certificate file "/path/to/your/ssl.pem" does not exist or is not readable. Your 'ssl_cert' configuration setting must be a ath
to a valid ssl certificate. (RuntimeError)

from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/rubycas-server-1.1.2/lib/casserver/server.rb:159:in `handler_options'

from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/rubycas-server-1.1.2/lib/casserver/server.rb:70:in `run!'

from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/rubycas-server-1.1.2/bin/rubycas-server:30:in `<top (required)>'

from /usr/local/rvm/gems/ruby-1.9.2-p180/bin/rubycas-server:19:in `load'

from /usr/local/rvm/gems/ruby-1.9.2-p180/bin/rubycas-server:19:in `<main>'

[root@openstack /]#

9可见,只差证书了

[root@openstack /]# cat /etc/rubycas-server/config.yml |grep ssl.pem

ssl_cert: /path/to/your/ssl.pem

需要把证书放到配置的这个位置,或者修改配置指向ssl.pem

我们这里先测试不使用证书的方法

注释掉

#ssl_cert: /path/to/your/ssl.pem

10.

[root@openstack /]# ruby /usr/local/rvm/gems/ruby-1.9.2-p180/bin/rubycas-server



>>> Redirecting RubyCAS-Server log to /var/log/casserver.log





>>> Running migrations to make sure your database schema is up to date...



D, [2013-10-14T10:56:00.238824 #25402] DEBUG -- : SCHEMA (0.3ms) SHOW TABLES

D, [2013-10-14T10:56:00.239453 #25402] DEBUG -- : SCHEMA (0.2ms) SHOW TABLES

D, [2013-10-14T10:56:00.240567 #25402] DEBUG -- : SQL (0.1ms) SELECT `schema_migrations`.`version` FROM `schema_migrations`

I, [2013-10-14T10:56:00.240712 #25402] INFO -- : Migrating to CreateInitialStructure (1)



>>> Your database is now up to date.



== RubyCAS-Server is starting up on port 443 for development with backup from WEBrick

[2013-10-14 10:56:07] INFO WEBrick 1.3.1

[2013-10-14 10:56:07] INFO ruby 1.9.2 (2011-02-18) [x86_64-linux]

[2013-10-14 10:56:07] INFO WEBrick::HTTPServer#start: pid=25402 port=443

11.现在启动没问题了,本地访问一下

[root@openstack /opt/nginx/sbin]# curl "127.0.0.1:443"

[root@openstack /opt/nginx/sbin]# curl "127.0.0.1:443" -i

HTTP/1.1 303 See Other

Content-Type: text/html;charset=utf-8

Location: http://127.0.0.1:443/login
Content-Length: 0

X-Xss-Protection: 1; mode=block

X-Content-Type-Options: nosniff

X-Frame-Options: SAMEORIGIN

Server: WEBrick/1.3.1 (Ruby/1.9.2/2011-02-18)

Date: Mon, 14 Oct 2013 03:21:27 GMT

Connection: Keep-Alive

[root@openstack /opt/nginx/sbin]# curl "127.0.0.1:443/login"

<?xml version="1.0" ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

"XHTML1-s.dtd" >

<html xmlns="http://www.w3.org/TR/1999/REC-html-in-xml"

xml:lang="en" lang="en" >



<head>

<title>CASCentral Login</title>

<link rel="stylesheet" type="text/css" href="/themes/cas.css" />

<link rel="stylesheet" type="text/css" href="/themes/simple/theme.css" />

<link rel="icon" type="image/png" href="/themes/simple/favicon.png" />

</head>



<body onload="if (document.getElementById('username')) document.getElementById('username').focus()">

<table id="login-box">

<tr>

<td colspan="2">

<div id="headline-container">

<strong>CAS</strong>

Central Login

</div>

</td>

</tr>







<tr>

<td id="logo-container">

<img id="logo" src="/themes/simple/logo.png" />

</td>

<td id="login-form-container">

<form method="post" action="login" id="login-form"

onsubmit="submitbutton = document.getElementById('login-submit'); submitbutton.value='Please wait...'; submitbutton.disabled=true; return true;">

<table id="form-layout">

<tr>

<td id="username-label-container">

<label id="username-label" for="username">

Username

</label>

</td>

<td id="username-container">

<input type="text" id="username" name="username"

size="32" tabindex="1" accesskey="u" />

</td>

</tr>

<tr>

<td id="password-label-container">

<label id="password-label" for="password">

Password

</label>

</td>

<td id="password-container">

<input type="password" id="password" name="password"

size="32" tabindex="2" accesskey="p" autocomplete="off" />

</td>

</tr>

<tr>

<td />

<td id="submit-container">

<input type="hidden" id="lt" name="lt" value="LT-1381720899rA9973007F53DDD0527" />

<input type="hidden" id="service" name="service" value="" />

<input type="submit" class="button" accesskey="l" value="LOGIN"

tabindex="4" id="login-submit" />

</td>

</tr>

<tr>

<td colspan="2" id="infoline">

Powered by <a href="http://code.google.com/p/rubycas-server/">RubyCAS-Server</a>

</td>

</tr>

</table>

</form>



</td>

</tr>

</table>



</body>

</html>

[root@openstack /opt/nginx/sbin]#

12.现在从外界访问不了

tcp 0 0 127.0.0.1:443 0.0.0.0:* LISTEN 14624/ruby

13.修改配置

vi /etc/rubycas-server/config.yml

bind_address: 0.0.0.0

仍然绑定127.0.0.1导致外界无法访问

14.猜测使用了/etc/hosts中的localhost作为绑定

更改/etc/hosts

0.0.0.0 localhost

[root@openstack /opt/nginx/sbin]# netstat -nlp|grep 443

tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 680/ruby

可以了

15.试下

[root@openstack /opt/nginx/sbin]# curl "10.16.13.37:443/login"

<?xml version="1.0" ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

"XHTML1-s.dtd" >

<html xmlns="http://www.w3.org/TR/1999/REC-html-in-xml"

xml:lang="en" lang="en" >



<head>

<title>CASCentral Login</title>

<link rel="stylesheet" type="text/css" href="/themes/cas.css" />

<link rel="stylesheet" type="text/css" href="/themes/simple/theme.css" />

<link rel="icon" type="image/png" href="/themes/simple/favicon.png" />

</head>



<body onload="if (document.getElementById('username')) document.getElementById('username').focus()">

<table id="login-box">

<tr>

<td colspan="2">

<div id="headline-container">

<strong>CAS</strong>

Central Login

</div>

</td>

</tr>







<tr>

<td id="logo-container">

<img id="logo" src="/themes/simple/logo.png" />

</td>

<td id="login-form-container">

<form method="post" action="login" id="login-form"

onsubmit="submitbutton = document.getElementById('login-submit'); submitbutton.value='Please wait...'; submitbutton.disabled=true; return true;">

<table id="form-layout">

<tr>

<td id="username-label-container">

<label id="username-label" for="username">

Username

</label>

</td>

<td id="username-container">

<input type="text" id="username" name="username"

size="32" tabindex="1" accesskey="u" />

</td>

</tr>

<tr>

<td id="password-label-container">

<label id="password-label" for="password">

Password

</label>

</td>

<td id="password-container">

<input type="password" id="password" name="password"

size="32" tabindex="2" accesskey="p" autocomplete="off" />

</td>

</tr>

<tr>

<td />

<td id="submit-container">

<input type="hidden" id="lt" name="lt" value="LT-1381722029r733421F509E9779FF7" />

<input type="hidden" id="service" name="service" value="" />

<input type="submit" class="button" accesskey="l" value="LOGIN"

tabindex="4" id="login-submit" />

</td>

</tr>

<tr>

<td colspan="2" id="infoline">

Powered by <a href="http://code.google.com/p/rubycas-server/">RubyCAS-Server</a>

</td>

</tr>

</table>

</form>



</td>

</tr>

</table>



</body>

</html>

没问题了



16.现在随便输入账号密码,报错误的账号密码

17.在数据库插入

insert into user(userid,username,password,full_name,access_level)values(null,'zzz','zzzpass','zzz',0);

18.用zzz zzzpass试验下

没问题了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: