本篇所在总结的内容本来是一个过时的东西,不过由于当下红帽考试仍使用的这个旧的版本,这里还是简单总结下openshift2.x的配置和使用。openshift是红帽的paas 应用,想要和cloudfoundry之类的paas类产品竞争,不过从当前市场占用份额上来看,cloudfoundry处于行业主宰者,龙头地位。openshit2.x是基于红帽自己搞的gear技术---可以看做是类似沙箱的一种技术,和docker一样也是基于lxc基础上做的封装。当前openshitf3.x 版本较openshitf2.x 做了几乎完全的改变。openshit3.x是基于docker和k8s的,后面有时间会单独拉出来一些章节对openshit3.x做介绍。本篇对理论不做过多的讲解,还是从实战出发。
一、主机规划
broker.domain1.example.com: 172.25.6.10
node1.domain1.example.com: 172.25.6.11
dev.domain1.example.com: 172.25.6.12
不过由于我实验环境是和openshit 课程环境一致的,只有两台主机,这里会让a主机做broker,同时又做dev主机名,b主机做node主机。
二、broker节点配置与安装
openshit-broker-install
[root@server6-a ~]# ssh-keygen
[root@server6-a ~]# ssh-copy-id root@server6-a
[root@server6-a ~]# ssh-copy-id root@server6-b
[root@server6-a ~]# mkdir oo-install
[root@server6-a ~]# cd oo-install/
[root@server6-aoo-install]#wget http://classroom.example.com/materials/ex280/oo-install-ose.tgz
[root@server6-a oo-install]# gunzip oo-install-ose.tgz
[root@server6-a oo-install]# tar xvf oo-install-ose.tar
[root@server6-a oo-install]# yum install ruby –y
[root@server6-a oo-install]# ./oo-install-ose
Select from the following installation scenarios.
You can also type '?' for Help or 'q' to Quit:
1. Install OpenShift Enterprise
2. Add a Node to OpenShift Enterprise
Type a selection and press <return>: 1
First things first: do you already have a running Broker? (y/n/q) n
What domain do you want to use for applications that are hosted by
this OpenShift deployment? |example.com| apps6.example.com
Do you want to register DNS entries for your OpenShift hosts with the
same OpenShift DNS service that will be managing DNS records for the
hosted applications? (y/n/q) n
Hostname (the FQDN that other OpenShift hosts will use to connect to
the host that you are describing): server6-a.example.com
Hostname / IP address for SSH access to server6-a.example.com from the
host where you are running oo-install. You can say 'localhost' if you
are running oo-install from the system that you are describing:
|server6-a.example.com|
Username for SSH access to server6-a.example.com: |root|
Detected multiple network interfaces for this host:
* 172.25.6.10 on interface eth0
* 172.25.106.10 on interface eth1
Do you want Nodes to use one of these IP addresses to reach this
Broker? (y/n/q/?) y
The following network interfaces were found on this host. Choose the
one that it uses for communication on the local subnet.:
1. 172.25.6.10 on interface eth0
2. 172.25.106.10 on interface eth1
Type a selection and press <return>: 1
If that will work in your deployment, press <enter> to accept the
default value. Otherwise, provide an alternate IP address that will
enable other OpenShift components to reach the BIND DNS service on the
Broker: |172.25.6.10|
Valid Gear Sizes for this deployment: |small|
Default Gear Capabilties for new users: |small|
Default Gear Size for new applications: |small|
Do you want to specify usernames and passwords for services configured
on this host? Otherwise default usernames and randomized passwords
will be configured. (y/n/q) n
That's everything we need to know right now for the Broker. Moving on
to the next role.
----------------------------------------------------------------------
Node Configuration
----------------------------------------------------------------------
Do you already have a running Node? (y/n/q) n
Do you want to assign the Node role to server6-a.example.com?
(y/n/q/?) n --->如果想要让broker节点也同时是node节点,这里可以选择yes Okay, please provide information about the Node host.
Hostname (the FQDN that other OpenShift hosts will use to connect to
the host that you are describing): server6-b.example.com
Hostname / IP address for SSH access to server6-b.example.com from the
host where you are running oo-install. You can say 'localhost' if you
are running oo-install from the system that you are describing:
|server6-b.example.com|
Username for SSH access to server6-b.example.com: |root|
Detected multiple network interfaces for this host:
* 172.25.6.11 on interface eth0
* 172.25.106.11 on interface eth1
Do you want to use one of these as the public IP information for this
Node? (y/n/q/?) y
The following network interfaces were found on this host. Choose the
one that it uses for communication on the local subnet.:
1. 172.25.6.11 on interface eth0
2. 172.25.106.11 on interface eth1
Type a selection and press <return>: 1
A gear profile, or gear size, specifies the parameters of the gears
provided by a node host. Note, this only sets the name of the profile.
For more information about gear profiles see:
https://access.redhat.com/site/documentation/en-US/OpenShift_Enterpris
e/2/html/Deployment_Guide/sect-Gear_Profiles_Sizes.html
Known Profiles: small
Gear profile for this host: |small|
Known Districts:
District this host should belong to: |default-small| small_district ---> Do you want to specify usernames and passwords for services configured
on this host? Otherwise default usernames and randomized passwords
will be configured. (y/n/q) n
Note: ActiveMQ, MongoDB and named will all be installed on the Broker.
For more flexibility, rerun the installer in advanced mode (-a).
DNS Settings
* App Domain: apps6.example.com
* Register OpenShift components with OpenShift DNS? No
Role Assignments
+--------+-----------------------+
| Broker | server6-a.example.com |
| Node | server6-b.example.com |
+--------+-----------------------+
Host Information
+---------------------------+--------------------------------------+
| Host | server6-a.example.com |
| Roles | Broker |
| SSH Host | server6-a.example.com |
| User | root |
| IP Addr | 172.25.6.10 |
| BIND DNS Addr | 172.25.6.10 |
| Install Status | new |
| Valid Gear Sizes | small |
| Default Gear Capabilities | small |
| Default Gear Size | small |
| District Mappings | small_district:server6-b.example.com |
| MCollective User | mcollective |
| MCollective Password | Q1EjZrJToYPVwz5IgUO0JA |
| MongoDB Broker User | openshift |
| MongoDB Broker Password | yA7Yu1uWdtk5ZYrwY5fWA |
| OpenShift User | demo |
| OpenShift Password | VrgnRcuYUxRYhVe7Qmrwww |
+---------------------------+--------------------------------------+
+----------------------+------------------------+
| Host | server6-b.example.com |
| Roles | Node |
| SSH Host | server6-b.example.com |
| User | root |
| IP Addr | 172.25.6.11 |
| IP Interface | eth0 |
| Install Status | new |
| Node Profile | small |
| District | small_district |
| MCollective User | mcollective |
| MCollective Password | Q1EjZrJToYPVwz5IgUO0JA |
+----------------------+------------------------+
Do you want to change the deployment info? (y/n/q/?) y
Choose from the following deployment configuration options:
1. Change the DNS configuration
2. Move an OpenShift role to a different host
3. Modify the information for an existing host
4. Add another Node host
5. Finish editing the deployment configuration
Type a selection and press <return>: 5
Here is the subscription configuration that the installer will use for
this deployment.
+---------+-------+
| Setting | Value |
+---------+-------+
| type | none |
+---------+-------+
Do you want to make any changes to the subscription info in the
configuration file? (y/n/q/?) n
Do you want to set any temporary subscription settings for this
installation only? (y/n/q/?) n
接下来会有10-20分钟左右的等待,完装完成后,按上面的提示---网内有其他主机充当DNS主机,所以这里将broker主机上的DNS停用掉,并将加密方式改为MD5。
openshift-broker-dns
[root@server6-a oo-install]# service named stop
[root@server6-a oo-install]# chkconfig named off
[root@server6-a oo-install]# vi /etc/openshift/ plugins.d/ openshift-origin-dns-nsupdate.conf
修改DNS及MD5,修改内容参见上图
[root@server6-a oo-install]#/etc/init.d/openshift-broker restart
[root@server6-a plugins.d]# htpasswd -b /etc/openshift/htpasswd marc flectrag
Adding password for user marc
[root@server6-a plugins.d]# htpasswd -b /etc/openshift/htpasswd grace flectrag
Adding password for user grace
三、配置命令行开发访问
rhc-configure
本部操作理论上来讲是在开者主机上配置的,也就是上面所提到的dev主机。这里的操作需要用到rhc命令,该命令可以通过yum -y install rhc安装。该命令类似于appfog平台下的af命令,cloudfoundry下的cf命令。
[root@server6-a ~]# useradd marc
[root@server6-a ~]# useradd grace
[root@server6-a ~]# su – marc
[marc@server6-a ~]$ rhc setup
If you have your own OpenShift server, you can specify it now. Just hit enter to use: server6-a.example.com.
Enter the server hostname: |server6-a.example.com|
Connect without checking the certificate? (yes|no): y
Login to server6-a.example.com: marc
Password: ********
OpenShift can create and store a token on disk which allows to you to access the server without using your password. The key is stored in your home
directory and should be kept secret. You can delete the key at any time by running 'rhc logout'.
Generate a token now? (yes|no) y
Your public SSH key must be uploaded to the OpenShift server to access code. Upload now? (yes|no) y
Please enter a namespace (letters and numbers only) |<none>|: scaled
Your domain 'scaled' has been successfully created
[root@server6-a ~]# su - grace
[grace@server6-a ~]$ rhc setup
If you have your own OpenShift server, you can specify it now. Just hit enter to use: server6-a.example.com.
Enter the server hostname: |server6-a.example.com|
Connect without checking the certificate? (yes|no): yes
Login to server6-a.example.com: grace
Password: ********
OpenShift can create and store a token on disk which allows to you to access the server without using your password. The key is stored in your home
directory and should be kept secret. You can delete the key at any time by running 'rhc logout'.
Generate a token now? (yes|no) yes
Your public SSH key must be uploaded to the OpenShift server to access code. Upload now? (yes|no) yes
Please enter a namespace (letters and numbers only) |<none>|: ex280
Your domain 'ex280' has been successfully created
注意这里输入的密码,不是系统用户的密码,而是broker安装时通过htpasswd命令生成出的密码。通过与远程broker通信,可以创建基于key认证的开发环境 ,以后只需要通过git上传开发的包,并通过rhc命令启停应用就行了。
四、配置资源限制
gear-size-limits
[root@server6-a ~]# oo-admin-ctl-user -l marc
User marc:
plan:
consumed domains: 1
max domains: 10
consumed gears: 0
max gears: 100
max tracked storage per gear: 0
max untracked storage per gear: 0
max teams: 0
viewing all global teams allowed: false
gear sizes: small
sub accounts allowed: false
private SSL certificates allowed: false
inherit gear sizes: false
HA allowed: false
[root@server6-a ~]# oo-admin-ctl-user -l marc --setmaxgears 25
[root@server6-a ~]# oo-admin-ctl-user -l grace --setmaxgears 50
而增加 medium 型的gear类型,是需要在配置文件中启用的。gears类型预设的有small 、medium、larage三种。可以通过下面的方式修改增加。
[root@server6-a ~]# vi /etc/openshift/broker.conf
# Comma-separated list of valid gear sizes
# Eg: "small,medium,large"
VALID_GEAR_SIZES="small,medium"
# Default gear sizes (comma-separated) allowed to a new user
DEFAULT_GEAR_CAPABILITIES="small,medium"
[root@server6-a ~]# /etc/init.d/openshift-broker restart
[root@server6-a ~]# oo-admin-ctl-user -l marc --addgearsize medium
Adding gear size medium for user marc... Done.
User marc:
plan:
consumed domains: 1
max domains: 10
consumed gears: 0
max gears: 25
max tracked storage per gear: 0
max untracked storage per gear: 0
max teams: 0
viewing all global teams allowed: false
gear sizes: small, medium
sub accounts allowed: false
private SSL certificates allowed: false
inherit gear sizes: false
HA allowed: false
五、配置districts
districts 是一个逻辑层面的东西,不太好描述,其作用就是出现多个node节点时,在相同的dictricts下,可以保证gear可以在不同的node里迁移,而且保证gear之间有相同的资源限制。
districts
由于在第一步安装broker里,我们已经创建了一个small_district,这里需要在创建一个,创建前后我们可以通过oo-admin-ctl-district 查看,发现在创建后,会多出一个district来。
[root@server6-a ~]# oo-admin-ctl-district --->会输出small_district的信息,这里略过输出
[root@server6-a ~]# oo-admin-ctl-district -c create -n exam_district -p small
[root@server6-a ~]# oo-admin-ctl-district
{"_id"=>"56da4df5d9b5eb6025000001",
"active_servers_size"=>1,
"available_capacity"=>6000,
"available_uids"=>"<6000 uids hidden>",
"created_at"=>2016-03-05 03:09:41 UTC,
"gear_size"=>"small",
"max_capacity"=>6000,
"max_uid"=>6999,
"name"=>"small_district",
"platform"=>"Linux",
"servers"=>
[{"_id"=>"56da4df6d9b5eb6025000002",
"active"=>true,
"name"=>"server6-b.example.com",
"unresponsive"=>false}],
"updated_at"=>2016-03-05 03:09:41 UTC,
"uuid"=>"56da4df5d9b5eb6025000001"}
{"_id"=>"56da5670d9b5eb39c6000001",
"uuid"=>"56da5670d9b5eb39c6000001",
"available_uids"=>"<6000 uids hidden>",
"name"=>"exam_district", --->多出来的exam_district
"platform"=>"linux",
"gear_size"=>"small",
"available_capacity"=>6000,
"max_uid"=>6999,
"max_capacity"=>6000,
"active_servers_size"=>0,
"updated_at"=>2016-03-05 03:45:52 UTC,
"created_at"=>2016-03-05 03:45:52 UTC}
六、发布一个应用
deploy-app
这里默认虽然没有指定的发布应用使用的类型,不过在后面的要求需要附加属性时会有要求是php-5.3,所以这会创建php-5.3应用---因为默认还有php-5.4的应用可选。
还需注意的是,这个操作本身是开发人员已经有paas帐号了,可以写好代码直接上传平台并展示,所以是在dev主机上进行的操作。
[grace@server6-a ~]$ rhc app create -a welcomeapp -t php-5.3
[grace@server6-a ~]$ cd welcomeapp/
[grace@server6-a welcomeapp]$ echo "<?phpinfo();?>" >welcome.php
[grace@server6-a welcomeapp]$ ls
index.php welcome.php
[grace@server6-a welcomeapp]$ git add .
[grace@server6-a welcomeapp]$ git commit -am "add welcome php"
[grace@server6-a welcomeapp]$ git push
七、配置cartridge
cartridges
cartidge 就是可以选择的应用类型,这个比较容易理解。
[grace@server6-a welcomeapp]$ rhc cartridge list
jenkins-1 Jenkins Server web
nodejs-0.10 Node.js 0.10 web
perl-5.10 Perl 5.10 web
php-5.3 PHP 5.3 web
php-5.4 PHP 5.4 web
python-2.6 Python 2.6 web
python-2.7 Python 2.7 web
python-3.3 Python 3.3 web
ruby-1.8 Ruby 1.8 web
ruby-1.9 Ruby 1.9 web
jbossews-1.0 Tomcat 6 (JBoss EWS 1.0) web
jbossews-2.0 Tomcat 7 (JBoss EWS 2.0) web
diy-0.1 Do-It-Yourself 0.1 web
cron-1.4 Cron 1.4 addon
jenkins-client-1 Jenkins Client addon
mongodb-2.4 MongoDB 2.4 addon
mysql-5.1 MySQL 5.1 addon
mysql-5.5 MySQL 5.5 addon
postgresql-8.4 PostgreSQL 8.4 addon
postgresql-9.2 PostgreSQL 9.2 addon
haproxy-1.4 Web Load Balancer addon
[grace@server6-a welcomeapp]$ rhc cartridge add cron-1.4 -a welcomeapp
Adding cron-1.4 to application 'welcomeapp' ... done
[grace@server6-a welcomeapp]$ rhc cartridge add mysql-5.1 -a welcomeapp
八、配置一个自增应用
在线应用的一个理想装状是什么?就是可以根据负载量和访问量进行线型的增长。配置这个scale应用就可以实现这个功能,其底层实际上还是基于haproxy实现的。
scaling-app
[marc@server6-a ~]$ rhc app create scaledapp -t php-5.3 –s
其中-s参数就是scale的含义。
九、配置watchman监控
watchman
watchman服务是运行在node节点上的,其会都gear的一些常用指标进行监控,这里假设只需要监控cpu信息,并设置刷新频率,可以通过下面的方法配置。
[root@server6-b ~]#/etc/init.d/openshift-watchman status
[root@server6-b ~]#vi /etc/openshift/node.conf
修改90行至181行,关于watchman的选项都开启,特别需要注意以下两行:
WATCHMAN_METRICS_INTERVAL=60
CGROUPS_METRICS_KEYS="cpu.stat"
[root@server6-b ~]#vi /etc/sysconfig/watchman
修改两处
GEAR_RETRIER=10
SATE_CHANGE_DELAY=60
[root@server6-b ~]#/etc/init.d/openshift-watchman restart
十、配置自定义的cartidge
custom-cartridge
[root@server6-b~]# oo-admin-cartridge --action install --source ex280_cart
[root@server6-b~]/etc/init.d/ruby193-mcollective restart
[root@server6-a oo-install]# oo-admin-ctl-cartridge -c import-node --activate
[root@server6-a oo-install]# oo-admin-console-cache --clear
[root@server6-a oo-install]# oo-admin-ctl-cartridge -c list
这里有三点需要注意:
1、下载下来的.tgz包需要先gunzip,再使用tar xvf解压,使用--source可以指定绝对路径,也可以使用当前目录下的相对路径;
2、需要先在node节点上安装,并且需要重启服务;
3、激活操作是在broker节点上,另外需要特别注意参数,有一个import参数,还有一个 --active参数 ,和上面用的参数是很空间混淆的。
十一、使用自定义cartidge创建应用
deploy-custom-app
[root@server6-a oo-install]# su - grace
[grace@server6-a ~]$ rhc cartridge list
ex280-httpd-0.1 HTTPD Cartridge for EX280 web
jenkins-1 Jenkins Server web
nodejs-0.10 Node.js 0.10 web
perl-5.10 Perl 5.10 web
php-5.3 PHP 5.3 web
php-5.4 PHP 5.4 web
python-2.6 Python 2.6 web
python-2.7 Python 2.7 web
python-3.3 Python 3.3 web
ruby-1.8 Ruby 1.8 web
ruby-1.9 Ruby 1.9 web
jbossews-1.0 Tomcat 6 (JBoss EWS 1.0) web
jbossews-2.0 Tomcat 7 (JBoss EWS 2.0) web
diy-0.1 Do-It-Yourself 0.1 web
cron-1.4 Cron 1.4 addon
jenkins-client-1 Jenkins Client addon
mongodb-2.4 MongoDB 2.4 addon
mysql-5.1 MySQL 5.1 addon
mysql-5.5 MySQL 5.5 addon
postgresql-8.4 PostgreSQL 8.4 addon
postgresql-9.2 PostgreSQL 9.2 addon
haproxy-1.4 Web Load Balancer addon
[grace@server6-a ~]$ rhc app create -a customapp -t ex280-httpd-0.1
十二、通过API 获取console数据
console-data
需要注意的是console api 获取的数据默认只能在broker节点上才可以查看。
[root@server6-a ~]# cd /etc/httpd/conf.d/
[root@server6-a conf.d]# mv 000002_openshift_origin_broker_proxy.conf 000002_openshift_origin_broker_proxy.conf.bak
[root@server6-a conf.d]# wget http://classroom.example.com/materials/ex280/000002_openshift_origin_broker_proxy.conf
[root@server6-a conf.d]# yum install curl
[root@server6-a conf.d]# curl
http://localhost:8080/admin-console/capacity/profiles.json |python -m json.tool >profile_output