使用chef方式安装Powerdns和JPowerAdmin

原创 服务器

本文附件中包含有安装手册和pdns-server、jpoweradmin的cookbook文件(不含安装包)

完整版本(带安装包)请至http://down.51cto.com/425872/up 

安装前的准备

1、 本文的非chef的安装方式对应为:

《Powerdns JPowerAdmin安装附详细配置 (分布式主从结构)》 http://jedy82.blog.51cto.com/425872/1136525

但本文关于powerdns未做主从结构的配置,需做主从配置的请自行配置/var/chef/cookbooks/pdns-server/templates/default/pdns.conf.erb 文件的内容

 

2、 本文的系统环境

[root@chef-server ~]# uname -a

Linux chef-server.tian.com 2.6.32-279.22.1.el6.x86_64 #1 SMP Wed Feb 6 03:10:46 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

[root@chef-server ~]# more /etc/redhat-release

CentOS release 6.3 (Final)

[root@chef-server ~]# ulimit -SHn 65535

[root@chef-server ~]# echo "ulimit -SHn 65535" >>/etc/rc.local

 

 

3、 本文涉及到的软件版本和下载地址

请尽量使用和我一致的版本,部分软件对版本有特定要求,更高版本反而不能使用。

其中JPowerAdmin需要的依赖组件,如下:

  •  powerdns:官网最新版 本文使用的是 pdns-server-3.2-1
  •  mysql:5.5 本文使用的是 mysql-server-5.5.30
  • JPowerAdmin本文使用的是 JPowerAdmin-v0.99.tar.gz
  • java 1.5或1.6 本文使用的是 jdk-6u39-linux-x64.bin
  • ant 1.7 及以上版本 本文使用的是 ant-1.7.1-13.el6.x86_64
  • exim 4.6及以上版本 本文使用的是 exim-4.72-4.el6.x86_64
  • jboss 需6.0.0 本文使用的是 jboss-as-distribution-6.0.0.Final.zip
  • jboss-seam 需 2.2.x 本文使用的是 jboss-seam-2.2.2.Final.zip
  • yum 源:

http://www.monshouwer.eu/download/3rd_party/pdns-recursor/el6/pdns-recursor.el6.repo

http://www.monshouwer.eu/download/3rd_party/pdns-server/el6/pdns-server.el6.repo

  • powerdns yum方式安装

pdns-server-3.2-1.el6.MIND.x86_64

pdns-server-backend-mysql-3.2-1.el6.MIND.x86_64

  • mysql yum方式安装

mysql-5.5.30-1.el6.remi.x86_64

mysql-server-5.5.30-1.el6.remi.x86_64

  • mysql-connector-java

mysql-connector-java-5.1.22.zip

http://www.mysql.com/downloads/connector/j/

  • JPowerAdmin

JPowerAdmin-v0.99.tar.gz

http://www.nicmus.com/JPowerAdmin-v0.99.tar.gz

 

  • Java

jdk-6u39-linux-x64.bin

http://www.oracle.com/technetwork/java/javase/downloads/jdk6downloads-1902814.html

  • Antyum方式安装

ant-1.7.1-13.el6.x86_64

  • Exim : yum方式安装

exim-4.72-4.el6.x86_64

  • Jboss

jboss-seam-2.2.2.Final.zip

http://nchc.dl.sourceforge.net/project/jboss/JBoss/JBoss-6.0.0.Final/jboss-as-distribution-6.0.0.Final.zip

  • Jboss-seam

jboss-seam-2.2.2.Final.zip

http://nchc.dl.sourceforge.net/project/jboss/JBoss%20Seam/2.2.2.Final/jboss-seam-2.2.2.Final.zip

  • Poweradmin

poweradmin-2.1.6.tgz

http://cloud.github.com/downloads/poweradmin/poweradmin/poweradmin-2.1.6.tgz

 

 

安装powerdns

Server

一、 创建cookbook 名称为:pdns-server

[root@chef-server ~]# knife cookbook create pdns-server

[root@chef-server ~]#

 

二、 创建自动作脚本

1. 创建powerdns yum 源

[root@chef-server ~]# more /var/chef/cookbooks/pdns-server/recipes/yum_source.rb

# Cookbook Name:: pdns_server

# Recipe::yum_source

#

# Copyright 2013, YOUR_COMPANY_NAME

#

# All rights reserved - Do Not Redistribute

#

package "wget" do

action [:install]

not_if "which wget"

end

execute "yum_source_pdns-recursor.el6.repo" do

command "cd /etc/yum.repos.d/;wget http://www.monshouwer.eu/download/3rd_party/pdns-recursor/el6/pdns-recursor.el6.repo"

not_if {FileTest.exists?("/etc/yum.repos.d/pdns-recursor.el6.repo")}

only_if do platform?("centos","redhat") end

end

execute "yum_source_pdns-server.el6.repo" do

command "cd /etc/yum.repos.d/;wget http://www.monshouwer.eu/download/3rd_party/pdns-server/el6/pdns-server.el6.repo"

not_if {FileTest.exists?("/etc/yum.repos.d/pdns-server.el6.repo")}

only_if do platform?("centos","redhat") end

end

[root@chef-server ~]#

 

 

2. 创建默认动作

[root@chef-server ~]# more /var/chef/cookbooks/pdns-server/recipes/default.rb

# Cookbook Name:: pdns-server

# Recipe:: default

#

# Copyright 2009, Adapp, Inc.

#

group "pdns" do

gid 53

end

user "pdns" do

comment "powerdns user"

gid "pdns"

uid 53

home "/var/empty"

supports :manage_home => false

shell "/sbin/nologin"

end

include_recipe "pdns-server::yum_source" //加载其它的resource

include_recipe "pdns-server::server"

[root@chef-server ~]#

 

3. 创建powerdns安装过程文件

[root@chef-server ~]# more /var/chef/cookbooks/pdns-server/recipes/server.rb

# Cookbook Name:: pdns-server

# Recipe:: server

#

# Copyright 2013, Adapp, Inc.

#

# Manual steps, run /etc/powerdns/powerdns.sql manually,

# e.g. mysql -p -f < /etc/powerdns/powerdns.sql

service "pdns-server" do

supports :restart => true, :status => true, :reload => true

action :nothing

end

execute "install_powerdns_from_yum" do

command "yum install -y pdns-server pdns-server-backend-mysql"

not_if { FileTest.exists?("/usr/sbin/pdns_server") }

only_if do platform?("centos","redhat") end

end

service "pdns-server" do

action [:enable,:start]

end

directory "/etc/powerdns" do

mode 0750

owner "pdns"

group "pdns"

end

template "/etc/powerdns/pdns.conf" do

source "pdns.conf.erb"

mode 0600

owner "root"

group "root"

backup false

end

template "/etc/powerdns/powerdns.sql" do

source "powerdns.sql.erb"

mode 0400

owner "root"

group "root"

backup false

end

[root@chef-server ~]#

 

三、 创建模板文件

1. powerdns 配置文件

[root@chef-server ~]# more /var/chef/cookbooks/pdns-server/templates/default/pdns.conf.erb

# Autogenerated configuration file template

#################################

# allow-axfr-ips Allow zonetransfers only to these subnets

#

# allow-axfr-ips=0.0.0.0/0,::/0

allow-axfr-ips=0.0.0.0/0,::/0

#################################

# allow-recursion List of subnets that are allowed to recurse

#

# allow-recursion=0.0.0.0/0

allow-recursion=0.0.0.0/0

#################################

# cache-ttl Seconds to store packets in the PacketCache

#

# cache-ttl=20

#################################

# chroot If set, chroot to this directory for more security

#

# chroot=

#################################

# config-dir Location of configuration directory (pdns.conf)

#

# config-dir=/usr/local/etc

#################################

# config-name Name of this virtual configuration - will rename the binary image

#

# config-name=

#################################

# control-console Debugging switch - don't use

#

# control-console=no

#################################

# daemon Operate as a daemon

#

# daemon=no

#################################

# default-soa-name name to insert in the SOA record if none set in the backend

#

# default-soa-name=a.misconfigured.powerdns.server

#################################

# default-ttl Seconds a result is valid if not set otherwise

#

# default-ttl=3600

#################################

# disable-axfr Disable zonetransfers but do allow TCP queries

#

# disable-axfr=no

disable-axfr=no

#################################

# disable-tcp Do not listen to TCP queries

#

# disable-tcp=no

disable-tcp=no

#################################

# distributor-threads Default number of Distributor (backend) threads to start

#

# distributor-threads=3

#################################

# do-ipv6-additional-processing Do AAAA additional processing

#

# do-ipv6-additional-processing=yes

#################################

# edns-subnet-option-number EDNS option number to use

#

# edns-subnet-option-number=20730

#################################

# edns-subnet-processing If we should act on EDNS Subnet options

#

# edns-subnet-processing=no

#################################

# entropy-source If set, read entropy from this file

#

# entropy-source=/dev/urandom

#################################

# experimental-direct-dnskey EXPERIMENTAL: fetch DNSKEY RRs from backend during DNSKEY synthesis

#

# experimental-direct-dnskey=no

#################################

# experimental-json-interface If the webserver should serve JSON data

#

# experimental-json-interface=no

#################################

# experimental-logfile Filename of the log file for JSON parser

#

# experimental-logfile=/var/log/pdns.log

#################################

# fancy-records Process URL and MBOXFW records

#

# fancy-records=no

#################################

# guardian Run within a guardian process

#

# guardian=no

#################################

# launch Which backends to launch and order to query them in

#

# launch=

#################################

# load-modules Load this module - supply absolute or relative path

#

# load-modules=

#################################

# local-address Local IP addresses to which we bind

#

# local-address=0.0.0.0

#################################

# local-ipv6 Local IP address to which we bind

#

# local-ipv6=

#################################

# local-port The port on which we listen

#

# local-port=53

#################################

# log-dns-details If PDNS should log DNS non-erroneous details

#

# log-dns-details=

log-dns-details=yes

#################################

# log-dns-queries If PDNS should log all incoming DNS queries

#

# log-dns-queries=no

log-dns-queries=yes

#################################

# log-failed-updates If PDNS should log failed update requests

#

# log-failed-updates=

log-failed-updates=yes

#################################

# logging-facility Log under a specific facility

#

# logging-facility=

# logging-facility=0

#################################

# loglevel Amount of logging. Higher is more. Do not set below 3

#

# loglevel=4

#################################

# lua-prequery-script Lua script with prequery handler

#

# lua-prequery-script=

#################################

# master Act as a master

#

# master=no

# master=yes

#

#

#################################

# max-cache-entries Maximum number of cache entries

#

# max-cache-entries=1000000

#################################

# max-ent-entries Maximum number of empty non-terminals in a zone

#

# max-ent-entries=100000

#################################

# max-queue-length Maximum queuelength before considering situation lost

#

# max-queue-length=5000

#################################

# max-tcp-connections Maximum number of TCP connections

#

# max-tcp-connections=10

#################################

# module-dir Default directory for modules

#

# module-dir=/usr/local/lib

#################################

# negquery-cache-ttl Seconds to store negative query results in the QueryCache

#

# negquery-cache-ttl=60

#################################

# no-shuffle Set this to prevent random shuffling of answers - for regression testing

#

# no-shuffle=off

#################################

# out-of-zone-additional-processing Do out of zone additional processing

#

# out-of-zone-additional-processing=yes

#################################

# overload-queue-length Maximum queuelength moving to packetcache only

#

# overload-queue-length=0

#################################

# pipebackend-abi-version Version of the pipe backend ABI

#

# pipebackend-abi-version=1

#################################

# query-cache-ttl Seconds to store query results in the QueryCache

#

# query-cache-ttl=20

#################################

# query-local-address Source IP address for sending queries

#

# query-local-address=0.0.0.0

#################################

# query-local-address6 Source IPv6 address for sending queries

#

# query-local-address6=::

#################################

# query-logging Hint backends that queries should be logged

#

# query-logging=no

query-logging=yes

#################################

# queue-limit Maximum number of milliseconds to queue a query

#

# queue-limit=1500

#################################

# receiver-threads Default number of Distributor (backend) threads to start

#

# receiver-threads=1

#################################

# recursive-cache-ttl Seconds to store packets for recursive queries in the PacketCache

#

# recursive-cache-ttl=10

#################################

# recursor If recursion is desired, IP address of a recursing nameserver

#

# recursor=no

#

# recursor=61.177.7.1

# recursor=221.228.255.1

# recursor=218.2.135.1

# recursor=202.96.0.133

# recursor=202.106.193.115

# recursor=202.106.195.68

# recursor=202.106.0.20

# recursor=202.106.196.115

#################################

# retrieval-threads Number of AXFR-retrieval threads for slave operation

#

# retrieval-threads=2

#################################

# send-root-referral Send out old-fashioned root-referral instead of ServFail in case of no authority

#

# send-root-referral=no

#################################

# server-id Returned when queried for 'server.id' TXT or NSID, defaults to hostname

#

# server-id=

#################################

# setgid If set, change group id to this gid for more security

#

# setgid=

#################################

# setuid If set, change user id to this uid for more security

#

# setuid=

#################################

# signing-threads Default number of signer threads to start

#

# signing-threads=3

#################################

# slave Act as a slave

#

# slave=no

#################################

# slave-cycle-interval Reschedule failed SOA serial checks once every .. seconds

#

# slave-cycle-interval=60

#################################

# slave-renotify If we should send out notifications for slaved updates

#

# slave-renotify=no

slave-renotify=no

#################################

# smtpredirector Our smtpredir MX host

#

# smtpredirector=a.misconfigured.powerdns.smtp.server

#################################

# soa-expire-default Default SOA expire

#

# soa-expire-default=604800

#################################

# soa-minimum-ttl Default SOA minimum ttl

#

# soa-minimum-ttl=3600

#################################

# soa-refresh-default Default SOA refresh

#

# soa-refresh-default=10800

#################################

# soa-retry-default Default SOA retry

#

# soa-retry-default=3600

#################################

# soa-serial-offset Make sure that no SOA serial is less than this number

#

# soa-serial-offset=0

#################################

# socket-dir Where the controlsocket will live

#

# socket-dir=/var/run

#################################

# strict-rfc-axfrs Perform strictly rfc compliant axfrs (very slow)

#

# strict-rfc-axfrs=no

#################################

# tcp-control-address If set, PowerDNS can be controlled over TCP on this address

#

# tcp-control-address=

#################################

# tcp-control-port If set, PowerDNS can be controlled over TCP on this address

#

# tcp-control-port=53000

#################################

# tcp-control-range If set, remote control of PowerDNS is possible over these networks only

#

# tcp-control-range=127.0.0.0/8, 10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12, ::1/128, fe80::/10

#################################

# tcp-control-secret If set, PowerDNS can be controlled over TCP after passing this secret

#

# tcp-control-secret=

#################################

# traceback-handler Enable the traceback handler (Linux only)

#

# traceback-handler=yes

#################################

# trusted-notification-proxy IP address of incoming notification proxy

#

# trusted-notification-proxy=

#################################

# urlredirector Where we send hosts to that need to be url redirected

#

# urlredirector=127.0.0.1

#################################

# version-string PowerDNS version in packets - full, anonymous, powerdns or custom

#

# version-string=full

#################################

# webserver Start a webserver for monitoring

#

# webserver=no

#################################

# webserver-address IP Address of webserver to listen on

#

# webserver-address=127.0.0.1

#################################

# webserver-password Password required for accessing the webserver

#

# webserver-password=

#################################

# webserver-port Port of webserver to listen on

#

# webserver-port=8081

#################################

# webserver-print-arguments If the webserver should print arguments

#

# webserver-print-arguments=no

#################################

# wildcard-url Process URL and MBOXFW records

#

# wildcard-url=no

module-dir=/usr/lib64

socket-dir=/var/run/pdns-server

setuid=powerdns

setgid=powerdns

#launch=bind

launch=gmysql

gmysql-host=127.0.0.1

gmysql-user=power_admin

gmysql-password=power_admin_password

gmysql-dbname=powerdns

#gmysql-dnssec=yes

[root@chef-server ~]#

 

 

2. sql 建表文件,需手动执行

[root@chef-server ~]# more /var/chef/cookbooks/pdns-server/templates/default/powerdns.sql.erb

CREATE DATABASE powerdns;

GRANT ALL ON powerdns.* TO 'power_admin'@'localhost' IDENTIFIED BY 'power_admin_password';

FLUSH PRIVILEGES;

USE powerdns;

CREATE TABLE domains (

id INT auto_increment,

name VARCHAR(255) NOT NULL,

master VARCHAR(128) DEFAULT NULL,

last_check INT DEFAULT NULL,

type VARCHAR(6) NOT NULL,

notified_serial INT DEFAULT NULL,

account VARCHAR(40) DEFAULT NULL,

primary key (id)

) Engine=InnoDB;

CREATE UNIQUE INDEX name_index ON domains(name);

CREATE TABLE records (

id INT auto_increment,

domain_id INT DEFAULT NULL,

name VARCHAR(255) DEFAULT NULL,

type VARCHAR(10) DEFAULT NULL,

content VARCHAR(64000) DEFAULT NULL,

ttl INT DEFAULT NULL,

prio INT DEFAULT NULL,

change_date BIGINT DEFAULT NULL,

CONSTRAINT `records_ibfk_1` FOREIGN KEY (`domain_id`) REFERENCES `domains`(`id`) ON DELETE CASCADE,

primary key(id)

) Engine=InnoDB;

CREATE INDEX rec_name_index ON records(name);

CREATE INDEX nametype_index ON records(name,type);

CREATE INDEX domain_id ON records(domain_id);

CREATE TABLE supermasters (

ip VARCHAR(25) NOT NULL,

nameserver VARCHAR(255) NOT NULL,

account VARCHAR(40) DEFAULT NULL

) Engine=InnoDB;

CREATE TABLE domainmetadata (

id INT auto_increment,

domain_id INT NOT NULL,

kind VARCHAR(16),

content TEXT,

primary key(id)

);

CREATE INDEX domainmetaidindex on domainmetadata(domain_id);

CREATE TABLE cryptokeys (

id INT auto_increment,

domain_id INT NOT NULL,

flags INT NOT NULL,

active BOOL,

content TEXT,

primary key(id)

);

CREATE INDEX domainidindex on cryptokeys(domain_id);

ALTER TABLE records add ordername VARCHAR(255) BINARY;

ALTER TABLE records add auth bool;

CREATE INDEX recordorder on records (domain_id, ordername);

CREATE TABLE tsigkeys (

id INT auto_increment,

name VARCHAR(255),

algorithm VARCHAR(50),

secret VARCHAR(255),

primary key(id)

);

CREATE UNIQUE INDEX namealgoindex on tsigkeys(name, algorithm);

ALTER TABLE records change column type type VARCHAR(10);

[root@chef-server ~]#

 

四、 更新chef cookbook

[root@chef-server ~]# knife cookbook upload pdns-server

Uploading pdns-server [0.0.1]

upload complete

[root@chef-server ~]#

[root@chef-server ~]# knife node run_list add chef-client.tian.com recipe[pdns-server]

 

 

 

 

Client

更新chef cookbook到客户端

[root@chef-client ~]# chef-client

[root@chef-client ~]# mysql -f </etc/powerdns/powerdns.sql

 

 

 

安装JPowerAdmin

Server

一、 创建cookbook 名称为:jpoweradmin

[root@chef-server ~]# knife cookbook create jpoweradmin

[root@chef-server ~]#

 

二、 准备各安装所需的软件并放入以下目录

[root@chef-server ~]# ll -h /var/chef/cookbooks/jpoweradmin/files/default/

total 371M

-rw-r--r-- 1 root root 173M Dec 28 2010 jboss-as-distribution-6.0.0.Final.zip

-rw-r--r-- 1 root root 108M Apr 26 2011 jboss-seam-2.2.2.Final.zip

-rw-r--r-- 1 root root 69M Feb 5 10:47 jdk-6u39-linux-x64.bin

-rw-r--r-- 1 root root 366K Feb 1 17:09 JPowerAdmin-v0.99.tar.gz

-rw-r--r-- 1 root root 4.1M Feb 4 11:15 mysql-connector-java-5.1.22.zip

-rw-r--r-- 1 root root 17M Aug 3 2011 resteasy-jaxrs-2.2.2.GA-all.zip

[root@chef-server ~]#

 

三、 创建自动作脚本

1. 创建默认动作

[root@chef-server ~]# more /var/chef/cookbooks/jpoweradmin/recipes/default.rb

# Cookbook Name:: jpoweradmin

# Recipe:: default

#

# Copyright 2013, YOUR_COMPANY_NAME

#

# All rights reserved - Do Not Redistribute

#

directory "/software" do

owner "root"

group "root"

mode 0755

action :create

end

%w{jboss-as-distribution-6.0.0.Final.zip jdk-6u39-linux-x64.bin mysql-connector-java-5.1.22.zip jboss-seam-2.2.2.Final.zip JPowerAdmin-v0.99.tar.gz resteasy

-jaxrs-2.2.2.GA-all.zip}.each do |dir|

cookbook_file "/software/#{dir}" do

source "#{dir}"

owner 'root'

group 'root'

end

end

package "unzip" do

action [:install]

not_if "which unzip"

end

package "ant" do

action [:install]

not_if "rpm -qa | grep ant"

end

package "exim" do

action [:install]

not_if "rpm -qa | grep exim"

end

include_recipe "jpoweradmin::jdk"

include_recipe "jpoweradmin::resteasy"

include_recipe "jpoweradmin::jboss"

include_recipe "jpoweradmin::jboss-seam"

include_recipe "jpoweradmin::mysql-connector"

include_recipe "jpoweradmin::jpoweradmin"

[root@chef-server ~]#

 

 

2. 创建jdk安装过程文件

[root@chef-server ~]# more /var/chef/cookbooks/jpoweradmin/recipes/jdk.rb

# Cookbook Name:: jpoweradmin

# Recipe:: jdk

#

# Copyright 2013, YOUR_COMPANY_NAME

#

# All rights reserved - Do Not Redistribute

#

# Manual steps, run /etc/etc/jdk.profile manually,

# command: "source /etc/jdk.profile"

execute "install_jdk" do

command "chmod +x /software/jdk-6u39-linux-x64.bin;cd /usr/local; /software/jdk-6u39-linux-x64.bin; source /etc/jdk.profile"

not_if "ls /usr/local|grep jdk1.6.0_39"

action :nothing

end

link "/usr/local/jdk" do

to "/usr/local/jdk1.6.0_39"

end

template "/etc/jdk.profile" do

source "jdk.profile.erb"

backup false

notifies :run, "execute[install_jdk]", :immediately

end

[root@chef-server ~]#

 

3. 创建resteasy-jaxrs安装过程文件

[root@chef-server ~]# more /var/chef/cookbooks/jpoweradmin/recipes/resteasy.rb

# Cookbook Name:: jpoweradmin

# Recipe:: resteasy

#

# Copyright 2013, YOUR_COMPANY_NAME

#

# All rights reserved - Do Not Redistribute

#

execute "install_resteasy" do

command "cd /usr/local && unzip /software/resteasy-jaxrs-2.2.2.GA-all.zip"

not_if "ls /usr/local|grep resteasy-jaxrs-2.2.2.GA"

end

link "/usr/local/resteasy-jaxrs" do

to "/usr/local/resteasy-jaxrs-2.2.2.GA"

end

[root@chef-server ~]#

 

 

4. 创建jboss安装过程文件

[root@chef-server ~]# more /var/chef/cookbooks/jpoweradmin/recipes/jboss.rb

# Cookbook Name:: jpoweradmin

# Recipe:: jboss

#

# Copyright 2013, YOUR_COMPANY_NAME

#

# All rights reserved - Do Not Redistribute

#

# Manual steps, run /etc/etc/jboss.profile manually,

# command: "source /etc/jboss.profile"

execute "install_jboss" do

command "cd /usr/local && unzip /software/jboss-as-distribution-6.0.0.Final.zip"

not_if "ls /usr/local|grep jboss-6.0.0.Final"

end

link "/usr/local/jboss" do

to "/usr/local/jboss-6.0.0.Final"

end

template "/etc/jboss.profile" do

source "jboss.profile.erb"

end

template "/usr/local/jboss/server/default/deploy/mysql-ds.xml" do

source "mysql-ds.xml.erb"

end

template "/etc/init.d/jboss" do

source "jboss_init.erb"

notifies :run, "execute[chmod_jboss]", :immediately

end

execute "chmod_jboss" do

command "chmod 755 /etc/init.d/jboss; source /etc/jboss.profile"

action :nothing

end

link "/etc/rc0.d/K20jboss" do

to "/etc/init.d/jboss"

end

link "/etc/rc3.d/S80jboss" do

to "/etc/init.d/jboss"

end

link "/etc/rc5.d/S80jboss" do

to "/etc/init.d/jboss"

end

execute "restart_jboss" do

command "service jboss restart"

end

[root@chef-server ~]#

 

 

5. 创建jboss-seam安装过程文件

[root@chef-server ~]# more /var/chef/cookbooks/jpoweradmin/recipes/jboss-seam.rb

# Cookbook Name:: jpoweradmin

# Recipe:: jboss-seam

#

# Copyright 2013, YOUR_COMPANY_NAME

#

# All rights reserved - Do Not Redistribute

#

# Manual steps, run /etc/etc/jboss.profile manually,

execute "install_jboss-seam" do

command "cd /usr/local && unzip /software/jboss-seam-2.2.2.Final.zip"

not_if "ls /usr/local|grep -i jboss-seam"

end

link "/usr/local/jboss-seam" do

to "/usr/local/jboss-seam-2.2.2.Final"

end

template "/usr/local/jboss-seam/build.properties" do

source "build.properties.erb"

end

execute "install_jboss-seam" do

command "cd /usr/local/jboss-seam/examples/booking && ant deploy"

end

[root@chef-server ~]#

 

 

6. 创建mysql-connector安装过程文件

[root@chef-server ~]# more /var/chef/cookbooks/jpoweradmin/recipes/mysql-connector.rb

# Cookbook Name:: jpoweradmin

# Recipe:: mysql-connector

#

# Copyright 2013, YOUR_COMPANY_NAME

#

# All rights reserved - Do Not Redistribute

#

execute "install_mysql-connector" do

command "cd /usr/local && unzip /software/mysql-connector-java-5.1.22.zip ; cp /usr/local/mysql-connector-java-5.1.22/mysql-connector-java-5.1.22-bin.jar

/usr/local/jboss/server/default/lib/mysql-connector-java-5.1.22-bin.jar"

not_if "ls /usr/local/jboss/server/default/lib/mysql-connector-java-5.1.22-bin.jar"

end

[root@chef-server ~]#

 

 

7. 创建jpoweradmin安装过程文件

[root@chef-server ~]# more /var/chef/cookbooks/jpoweradmin/recipes/jpoweradmin.rb

# Cookbook Name:: jpoweradmin

# Recipe:: jpoweradmin

#

# Copyright 2013, YOUR_COMPANY_NAME

#

# All rights reserved - Do Not Redistribute

#

# Manual steps, run /etc/etc/jboss.profile manually,

# command: "source /etc/etc/jboss.profile"

execute "install_jpoweradmin" do

command "cd /usr/local && tar zxvf /software/JPowerAdmin-v0.99.tar.gz"

not_if "ls /usr/local|grep -i JPowerAdmin"

end

template "/usr/local/JPowerAdmin/build.xml" do

source "build.xml.erb"

end

template "/usr/local/JPowerAdmin/resources/JPowerAdmin-ds.xml" do

source "JPowerAdmin-ds.xml.erb"

end

template "/usr/local/JPowerAdmin/resources/META-INF/persistence.xml" do

source "persistence.xml.erb"

end

execute "ant_ear" do

command "cd /usr/local/JPowerAdmin && ant ear; ant datasource; ant deploy "

end

[root@chef-server ~]#

 

 

 

四、 创建模板文件

1. build.properties.erb文件

[root@chef-server ~]# more /var/chef/cookbooks/jpoweradmin/templates/default/build.properties.erb

#See build/sample.build.properties for properties you might want to set

#Tue, 26 Apr 2011 16:30:15 +0200

mavenized=false

qualifier=.Final

jboss.home /usr/local/jboss

[root@chef-server ~]#

 

 

2. build.xml.erb文件

[root@chef-server ~]# more /var/chef/cookbooks/jpoweradmin/templates/default/build.xml.erb

<?xml version="1.0" ?>

<project name="JPowerAdmin" default="deploy">

<tstamp />

<!--Common properties-->

<!-- Names -->

<property name="Name" value="JPower Admin control panel on JBOSS SEAM" />

<property name="project.name" value="JPowerAdmin" />

<property name="datasource" value="JPowerAdmin-ds.xml" />

<property name="debug" value="false"/>

<!--Source Directories-->

<property name="src.dir" value="./src"/>

<property name="view.dir" value="./view" />

<property name="resources.dir" value="./resources"/>

<!--Target Directories-->

<property name="build.dir" value="./build" />

<property name="dist.dir" value="./dist" />

<property name="exploded-archives.dir" value="./exploded-archives"/>

<property name="ear.name" value="${dist.dir}/${project.name}.ear" />

<property name="jar.name" value="${build.dir}/${project.name}.jar" />

<property name="war.name" value="${build.dir}/${project.name}.war" />

<!--Libraries-->

<property name="lib.dir" value="/usr/local/jboss-seam/lib"/>

<!--Rest easy integration -->

<property name="rest-easy-lib.dir" value="/usr/local/resteasy-jaxrs/lib"/>

<!--Deployment Directories-->

<property name="jboss-home.dir" value="/usr/local/jboss"/>

<property name="deploy.dir" value="${jboss-home.dir}/server/default/deploy"/>

<!--SEAM JARS AND REQUIRED DEPENDENCIES-->

<!--Seam Core-->

<fileset id="seam.jar" dir="${lib.dir}">

<include name="jboss-seam.jar"/>

</fileset>

<!--Seam tag library - seam ui with dependencies -->

<fileset id="seam.ui.jar" dir="${lib.dir}">

<include name="jboss-seam-ui.jar"/>

<include name="commons-beanutils.jar"/>

</fileset>

<fileset id="seam.mail.jar" dir="${lib.dir}">

<include name="jboss-seam-mail.jar"/>

</fileset>

<!-- Jboss EL -->

<fileset id="jboss-el.jar" dir="${lib.dir}">

<include name="jboss-el.jar" />

</fileset>

<!-- Facelets dependencies-->

<fileset id="facelets.jar" dir="${lib.dir}">

<include name="jsf-facelets.jar" />

</fileset>

<!-- RichFaces dependencies -->

<fileset id="richfaces-api.jar" dir="${lib.dir}">

<include name="richfaces-api.jar" />

<include name="commons-beanutils.jar" />

<include name="commons-digester.jar" />

</fileset>

<fileset id="richfaces-impl.jar" dir="${lib.dir}">

<include name="richfaces-impl.jar"/>

<include name="richfaces-ui.jar" />

</fileset>

<!--Rest easy integration-->

<fileset id="seam-rest-easy" dir="${lib.dir}">

<include name="jboss-seam-resteasy.jar"/>

</fileset>

<!--Rest easy jars-->

<fileset id="rest-easy-jars" dir="${rest-easy-lib.dir}">

<include name="jaxrs-api-2.0.0.GA.jar" />

<include name="jaxb-api-2.1.jar"/>

<include name="jaxb-impl-2.1.12.jar"/>

<include name="resteasy-jaxrs-2.0.0.GA.jar"/>

<include name="resteasy-jaxb-provider-2.0.0.GA.jar" />

</fileset>

<!-- Define what goes in the war file/jar file/ear files-->

<fileset id="war.view" dir="${view.dir}">

<include name="**/*"/>

</fileset>

<fileset id="war.resources" dir="${resources.dir}">

<include name="WEB-INF/*.xml" />

<include name="WEB-INF/*.sql" />

</fileset>

<!-- put the Localised view handler in the war -->

<fileset id="war.localizedViewHandler" dir="${build.dir}/classes">

<include name="**/LocalisedViewHandler.class" />

</fileset>

<!-- Stuff that goes into the jar-->

<fileset id="jar.resources" dir="${resources.dir}">

<include name="import.sql" />

<include name="seam.properties" />

<include name="META-INF/persistence.xml" />

<include name="META-INF/ejb-jar.xml" />

</fileset>

<!-- Stuff that goes into the ear -->

<fileset id="ear.resources" dir="${resources.dir}">

<include name="META-INF/jboss-app.xml" />

<include name="META-INF/application.xml" />

</fileset>

<!-- Property resources - themes/internatiolization, etc to be put on

the class path -->

<fileset id="war.classes.resources" dir="${resources.dir}">

<exclude name="seam.properties" />

<exclude name="components.properties" />

<include name="*.properties"/>

</fileset>

<!-- Build classpath -->

<path id="build.classpath">

<fileset dir="${lib.dir}">

<include name="*.jar" />

<exclude name="jboss-seam-debug.jar" />

</fileset>

<fileset refid="rest-easy-jars"/>

</path>

<target name="init">

<tstamp/>

<mkdir dir="${build.dir}/classes" />

<mkdir dir="${dist.dir}" />

</target>

<target name="clean" depends="init">

<delete dir="${build.dir}"/>

<delete dir="${dist.dir}" />

</target>

<!--Compile the source -->

<target name="compile" depends="init">

<javac classpathref="build.classpath" destdir="${build.dir}/classes" debug="off">

<src path="${src.dir}" />

</javac>

</target>

<!-- Build the ejb project jar -->

<target name="jar" depends="compile">

<jar destfile="${jar.name}" basedir="${build.dir}/classes">

<fileset refid="jar.resources" />

</jar>

</target>

<!--Build the ejb project war-->

<target name="war" depends="init,compile" >

<mkdir dir="${build.dir}/tmp/war/resources" />

<copy todir="${build.dir}/tmp/war/resources">

<fileset refid="war.resources" />

<filterset>

<filter token="debug" value="${debug}" />

<filter token="ProjectName" value="${project.name}"/>

<filter token="jndiPattern" value="${project.name}/#{ejbName}/local" />

</filterset>

</copy>

<jar destfile="${war.name}">

<zipfileset refid="war.view"/>

<zipfileset refid="seam.mail.jar" prefix="WEB-INF/lib" />

<zipfileset refid="seam.ui.jar" prefix="WEB-INF/lib" />

<zipfileset refid="facelets.jar" prefix="WEB-INF/lib" />

<zipfileset refid="richfaces-impl.jar" prefix="WEB-INF/lib" />

<zipfileset refid="war.classes.resources" prefix="WEB-INF/classes" />

<zipfileset refid="war.localizedViewHandler" prefix="WEB-INF/classes"/>

<fileset dir="${build.dir}/tmp/war/resources" />

</jar>

</target>

<!-- Build the ear file -->

<target name="ear" depends="jar,war,init">

<mkdir dir="${build.dir}/tmp/ear/resources" />

<copy todir="${build.dir}/tmp/ear/resources">

<fileset refid="ear.resources"/>

<filterset>

<filter token="ProjectName" value="${project.name}"/>

</filterset>

</copy>

<jar destfile="${ear.name}" >

<fileset refid="seam.jar" />

<fileset dir="${build.dir}/tmp/ear/resources"/>

<zipfileset refid="rest-easy-jars" prefix="lib"/>

<zipfileset refid="seam-rest-easy" prefix="lib"/>

<zipfileset refid="richfaces-api.jar" prefix="lib" />

<zipfileset refid="jboss-el.jar" prefix="lib"/>

<fileset dir="${build.dir}">

<include name="${project.name}.jar"/>

<include name="${project.name}.war"/>

</fileset>

</jar>

</target>

<!--Deploy the data source -->

<target name="datasource">

<fail unless="jboss-home.dir">jboss-home.dir not set</fail>

<copy todir="${deploy.dir}" file="${resources.dir}/${datasource}"/>

</target>

<target name="deploy" depends="ear,datasource">

<fail unless="jboss-home.dir">jboss-home.dir not set</fail>

<copy todir="${deploy.dir}" file="${ear.name}" />

</target>

<target name="undeploy">

<delete file="${deploy.dir}/${project.name}.ear" failonerror="no" />

<delete file="${deploy.dir}/${datasource}" failonerror="no"/>

</target>

</project>

[root@chef-server ~]#

 

 

3. jboss_init.erb文件

[root@chef-server ~]# more /var/chef/cookbooks/jpoweradmin/templates/default/jboss_init.erb

#!/bin/sh

#

# $Id: jboss_init_redhat.sh 81068 2008-11-14 15:14:35Z [email protected] $

#

# JBoss Control Script

#

# To use this script run it as root - it will switch to the specified user

#

# Here is a little (and extremely primitive) startup/shutdown script

# for RedHat systems. It assumes that JBoss lives in /usr/local/jboss,

# it's run by user 'jboss' and JDK binaries are in /usr/local/jdk/bin.

# All this can be changed in the script itself.

#

# Either modify this script for your requirements or just ensure that

# the following variables are set correctly before calling the script.

JBOSS_HOST=${JBOSS_HOST:-"0.0.0.0"}

#define where jboss is - this is the directory containing directories log, bin, conf etc

JBOSS_HOME=${JBOSS_HOME:-"/usr/local/jboss"}

#define the user under which jboss will run, or use 'RUNASIS' to run as the current user

JBOSS_USER=${JBOSS_USER:-"root"}

#make sure java is in your path

JAVAPTH=${JAVAPTH:-"/usr/local/jdk/bin"}

#configuration to use, usually one of 'minimal', 'default', 'all'

JBOSS_CONF=${JBOSS_CONF:-"default"}

#if JBOSS_HOST specified, use -b to bind jboss services to that address

JBOSS_BIND_ADDR=${JBOSS_HOST:+"-b $JBOSS_HOST"}

#define the classpath for the shutdown class

JBOSSCP=${JBOSSCP:-"$JBOSS_HOME/bin/shutdown.jar:$JBOSS_HOME/client/jnet.jar"}

#define the script to use to start jboss

JBOSSSH=${JBOSSSH:-"$JBOSS_HOME/bin/run.sh -c $JBOSS_CONF $JBOSS_BIND_ADDR"}

if [ "$JBOSS_USER" = "RUNASIS" ]; then

SUBIT=""

else

SUBIT="su - $JBOSS_USER -c "

fi

if [ -n "$JBOSS_CONSOLE" -a ! -d "$JBOSS_CONSOLE" ]; then

# ensure the file exists

touch $JBOSS_CONSOLE

if [ ! -z "$SUBIT" ]; then

chown $JBOSS_USER $JBOSS_CONSOLE

fi

fi

if [ -n "$JBOSS_CONSOLE" -a ! -f "$JBOSS_CONSOLE" ]; then

echo "WARNING: location for saving console log invalid: $JBOSS_CONSOLE"

echo "WARNING: ignoring it and using /dev/null"

JBOSS_CONSOLE="/dev/null"

fi

#define what will be done with the console log

JBOSS_CONSOLE=${JBOSS_CONSOLE:-"/dev/null"}

JBOSS_CMD_START="cd $JBOSS_HOME/bin; $JBOSSSH"

JBOSS_CMD_STOP=${JBOSS_CMD_STOP:-"java -classpath $JBOSSCP org.jboss.Shutdown --shutdown"}

if [ -z "`echo $PATH | grep $JAVAPTH`" ]; then

export PATH=$PATH:$JAVAPTH

fi

if [ ! -d "$JBOSS_HOME" ]; then

echo JBOSS_HOME does not exist as a valid directory : $JBOSS_HOME

exit 1

fi

echo JBOSS_CMD_START = $JBOSS_CMD_START

case "$1" in

start)

cd $JBOSS_HOME/bin

if [ -z "$SUBIT" ]; then

eval $JBOSS_CMD_START >${JBOSS_CONSOLE} 2>&1 &

else

$SUBIT "$JBOSS_CMD_START >${JBOSS_CONSOLE} 2>&1 &"

fi

;;

stop)

if [ -z "$SUBIT" ]; then

$JBOSS_CMD_STOP

else

$SUBIT "$JBOSS_CMD_STOP"

fi

;;

restart)

$0 stop

$0 start

;;

*)

echo "usage: $0 (start|stop|restart|help)"

esac

[root@chef-server ~]#

 

4. jboss.profile.erb文件

[root@chef-server ~]# more /var/chef/cookbooks/jpoweradmin/templates/default/jboss.profile.erb

#/etc/jboss.profile

export JBOSS_HOME=/usr/local/jboss

export PATH=$JBOSS_HOME/bin:$PATH

[root@chef-server ~]#

 

5. jdk.profile.erb文件

[root@chef-server ~]# more /var/chef/cookbooks/jpoweradmin/templates/default/jdk.profile.erb

# /etc/jdk.profile

export JAVA_HOME=/usr/local/jdk

export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar

export PATH=$JAVA_HOME/bin:$PATH

[root@chef-server ~]#

 

6. JPowerAdmin-ds.xml.erb文件

[root@chef-server ~]# more /var/chef/cookbooks/jpoweradmin/templates/default/JPowerAdmin-ds.xml.erb

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE datasources

PUBLIC "-//JBoss//DTD JBOSS JCA Config 1.5//EN"

"http://www.jboss.org/j2ee/dtd/jboss-ds_1_5.dtd">

<datasources>

<local-tx-datasource>

<jndi-name>MySqlDS</jndi-name>

<use-java-context>true</use-java-context>

<!-- <connection-url>jdbc:hsqldb:file:/tmp/pdns-db</connection-url> -->

<connection-url>jdbc:mysql://127.0.0.1:3306/powerdns</connection-url>

<!-- <driver-class>org.hsqldb.jdbcDriver</driver-class> -->

<driver-class>com.mysql.jdbc.Driver</driver-class>

<user-name>power_admin</user-name>

<password>power_admin_password</password>

</local-tx-datasource>

</datasources>

[root@chef-server ~]#

 

7. mysql-ds.xml.erb文件

[root@chef-server ~]# more /var/chef/cookbooks/jpoweradmin/templates/default/mysql-ds.xml.erb

<?xml version="1.0" encoding="UTF-8"?>

<!-- See http://www.jboss.org/community/wiki/Multiple1PC for information about local-tx-datasource -->

<!-- $Id: mysql-ds.xml 97536 2009-12-08 14:05:07Z jesper.pedersen $ -->

<!-- Datasource config for MySQL using 3.0.9 available from:

http://www.mysql.com/downloads/api-jdbc-stable.html

-->

<datasources>

<local-tx-datasource>

<jndi-name>MySqlDS</jndi-name>

<connection-url>jdbc:mysql://127.0.0.1:3306/powerdns</connection-url>

<driver-class>com.mysql.jdbc.Driver</driver-class>

<user-name>power_admin</user-name>

<password>power_admin_password</password>

<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>

<!-- should only be used on drivers after 3.22.1 with "ping" support

<valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker</valid-connection-checker-class-name>

-->

<!-- sql to call when connection is created

<new-connection-sql>some arbitrary sql</new-connection-sql>

-->

<!-- sql to call on an existing pooled connection when it is obtained from pool - MySQLValidConnectionChecker is preferred for newer drivers

<check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>

-->

<!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->

<metadata>

<type-mapping>mySQL</type-mapping>

</metadata>

</local-tx-datasource>

</datasources>

[root@chef-server ~]#

 

8. persistence.xml.erb文件

[root@chef-server ~]# more /var/chef/cookbooks/jpoweradmin/templates/default/persistence.xml.erb

<?xml version="1.0" encoding="UTF-8"?>

<!-- Persistence deployment descriptor for dev profile -->

<persistence xmlns="http://java.sun.com/xml/ns/persistence"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"

version="1.0">

<persistence-unit name="pDNS">

<provider>org.hibernate.ejb.HibernatePersistence</provider>

<jta-data-source>java:/MySqlDS</jta-data-source>

<properties>

<property name="hibernate.dialect" value = "org.hibernate.dialect.MySQLDialect" />

<!-- <property name="hibernate.dialect" value = "org.hibernate.dialect.HSQLDialect" /> -->

<property name="hibernate.hbm2ddl.auto" value="update"/>

<property name="hibernate.show_sql" value="false"/>

<property name="hibernate.format_sql" value="true"/>

<property name="jboss.entity.manager.factory.jndi.name" value="java:/JPowerAdminEntityManagerFactory"/>

</properties>

</persistence-unit>

</persistence>

[root@chef-server ~]#

 

 

五、 更新chef cookbook

[root@chef-server ~]# knife cookbook upload jpoweradmin

Uploading jpoweradmin [0.0.1]

upload complete

[root@chef-server ~]#

[root@chef-server ~]# knife node run_list add chef-client.tian.com recipe[jpoweradmin]

 

 

 

 

Client

更新chef cookbook到客户端

[root@chef-client ~]# chef-client

你可能感兴趣的:(安装,服务器)