1、配置
系统管理-系统设置
建:RSYNC_DIR_***
值:/opt/rsyncdir/wms/pro/*******
jenkins URL http://***.****.****.****:8080/
2、deploy-web-transfer-21.sh脚本
#! /bin/sh echo $1 projectname="$1" projectdir="/opt/www/${projectname}" warname="${projectname}-web.war" rm -rf ${projectdir}/*.tar.gz mkdir -p ${projectdir} /usr/bin/rsync -avzP www@***.***.***.21::rsync_pro_**/${projectname}/*.war ${projectdir}/${projectname}-web.war
# ***.***.***.21是jenkins服务器ip
以上步骤完成jenkins构建项目,并且将war包从jenkins服务器同步到需要部署的resin服务器。
3、部署job,也可以和2整合在一起,构建与部署分开,解决分布式架构中,多项目编译代码慢的问题,可提前构建,上线时执行部署job
deploy-web-only.sh
#! /bin/sh echo $1 projectname="$1" projectdir="/opt/www/${projectname}" warname="${projectname}-web.war" root_file=root$(date +'%Y%m%d_%H%M%S') default_file=default latest_file=latest if [ ! -f "${projectdir}/${warname}" ]; then echo "error! ================== ${projectdir}/${warname} is not exist" exit -1; fi unzip -o ${projectdir}/${warname} -d ${projectdir}/${root_file} echo "unzip success, will restart real server" for i in $(seq 6);do #result=`sh /usr/local/resin/bin/resin.sh -conf /opt/conf/resin/resin-${projectname}.xml stop | grep "RemoteConnectionFailedException"` result=`sh /opt/script/resin/resin-one.sh ${projectname} stop | grep "RemoteConnectionFailedException"` if [ -n "$result" ]; then echo "shutdown resin success!" break else echo "shutdown resin ......" fi if [ $i -eq 5 ]; then pid=`ps -ef|grep "resin-${projectname}"|grep -v grep|awk '{print $2}'` if [ -n "$pid" ]; then echo "kill -9 $pid" kill -9 $pid break fi fi done echo "mv ${projectdir}/$default_file ${projectdir}/$latest_file" unlink ${projectdir}/$latest_file rm -rf ${projectdir}/$latest_file mv ${projectdir}/$default_file ${projectdir}/$latest_file ln -s ${projectdir}/${root_file} ${projectdir}/${default_file} echo "****start startup resin****" sh /opt/script/resin/resin-one.sh ${projectname} start
seq 6 是1,2,3,4,5,6。所以 if [ $i -eq 5 ];应该修改为 if [ $i -eq 6 ] 也就是最后一次循环时判断下采用stop命令是否正常关闭了resin服务,如果没有则kill掉进程
/opt/script/resin/resin-one.sh
#!/bin/bash cd `dirname $0` BIN_DIR=`pwd` #CONF_DIR=${BIN_DIR}/conf CONF_DIR=/opt/conf/resin #tmp_name=$1 if [ "$2" != "start" ] && [ "$2" != "stop" ]; then echo "ERROR: Please input 2 argument: start or stop" exit -1; fi CONF_FILE=${CONF_DIR}/resin-$1.xml echo $CONF_FILE if [ ! -f $CONF_FILE ]; then echo "File($CONF_FILE) does not exist. so will create this resin conf." sh $BIN_DIR/create-conf.sh $1 fi echo "/usr/local/resin/bin/resin.sh -conf $CONF_FILE $2" /usr/local/resin/bin/resin.sh -conf $CONF_FILE $2 #/usr/local/resin/bin/resin.sh -conf ${CONF_DIR}/resin-${tmp_name}.xml $2
/opt/script/resin/create-conf.sh
#!/bin/bash cd `dirname $0` BIN_DIR=`pwd` tmp_name=$1 if [ ! -n "$tmp_name" ] ; then echo "ERROR: Please input argument project name!" exit -1; fi http_port=`cat ${BIN_DIR}/port/${tmp_name}` echo $http_port if [ ! -n "$http_port" ]; then echo "error! http port undefined in file "${tmp_name}"" exit -1; fi if [ $http_port -le 8000 ] || [ $http_port -ge 8100 ] ; then echo "error! http port must between in [8000, 8100], but now is ${http_port}" exit -1; fi port=`echo $http_port|cut -b 3-` # 如果$http_port == 8001 则cut -b 3-的意思是 按字节截取第三个以及之后的字符,也就是01 tmp_watchdog_port="66${port}" #tmp_watchdog_port="6600" tmp_server_port="68${port}" tmp_http_port="80${port}" tmp_root_directory="/opt/www/${tmp_name}/default" tmp_log_path="/opt/logs/resin/${tmp_name}" #CONF_DIR=${BIN_DIR}/conf CONF_DIR=/opt/conf/resin mkdir -p $CONF_DIR echo $CONF_DIR $tmp_watchdog_port $tmp_server_port $tmp_http_port $tmp_root_directory $tmp_log_path cat ${BIN_DIR}/resin-tmp.xml | sed "s:tmp.name:${tmp_name}:" | sed "s:tmp.watchdog-port:${tmp_watchdog_port}:" | sed "s:tmp.server-port:${tmp_server_port}:" |sed "s:tmp.http-port:${tmp_http_port}:" |sed "s:tmp.root-directory:${tmp_root_directory}:" |sed "s:tmp.log-path:${tmp_log_path}:" > ${CONF_DIR}/resin-${tmp_name}.xml
port 目录下用项目名命名的文档中放端口号
resin-tmp.xml
<!-- - Resin 4.0 configuration file for a clustered/load-balance environment --> <resin xmlns="http://caucho.com/ns/resin" xmlns:resin="urn:java:com.caucho.resin" xmlns:health="urn:java:com.caucho.health"> <!-- - Logging configuration for the JDK logging API. --> <log-handler name="" level="all" path="stdout:" timestamp="[%y-%m-%d %H:%M:%S.%s] {%{thread}} "/> <!-- - level='info' for production - 'fine' or 'finer' for development and troubleshooting --> <logger name="com.caucho" level="info"/> <logger name="com.caucho.java" level="config"/> <logger name="com.caucho.loader" level="config"/> <!-- - driver .jar files can be placed in ${resin.root}/ext-lib --> <class-loader> <tree-loader path="${resin.home}/ext-lib"/> <tree-loader path="${resin.root}/ext-lib"/> </class-loader> <class-loader> <tree-loader path="${resin.home}/lib"/> <tree-loader path="${resin.root}/lib"/> </class-loader> <!-- - jars with maven dependencies can be placed in project-jars to be used - by web-apps --> <resin:ProjectJarRepository path="${resin.root}/project-jars"/> <!-- - Remote management requires at least one enabled admin user. --> <resin:AdminAuthenticator> <resin:import path="${__DIR__}/admin-users.xml" optional="true"/> </resin:AdminAuthenticator> <!-- - For clustered systems, create a password in place of "changeme" - and uncomment the <resin-system-auth-key>. - - <resin-system-auth-key>changeme</resin-system-auth-key> --> <!-- - For production sites, change dependency-check-interval to something - like 600s, so it only checks for updates every 10 minutes. --> <dependency-check-interval>2s</dependency-check-interval> <!-- Java system-properties --> <system-property mail.smtp.host="127.0.0.1"/> <system-property mail.smtp.port="25"/> <!-- - Sets the default character encoding to utf-8 - - <character-encoding>utf-8</character-encoding> --> <!-- - You can change the compiler to "javac", "eclipse" or "internal". --> <javac compiler="internal" args="-source 1.5"/> <!-- - default configuration applied to all clusters --> <cluster-default> <!-- shared webapp jars for non-classloader-aware libraries --> <web-app-default> <!-- - Enable EL expressions in Servlet and Filter init-param --> <allow-servlet-el/> <prologue> <allow-servlet-el/> </prologue> <class-loader> <library-loader path="${resin.home}/webapp-jars"/> </class-loader> <!-- - Some JSP packages have incorrect .tld files. It's possible to - set validate-taglib-schema to false to work around these packages. --> <jsp> <validate-taglib-schema>true</validate-taglib-schema> <fast-jstl>true</fast-jstl> </jsp> </web-app-default> <!-- standard servlet behavior, including .jsp, .php, and WEB-INF --> <resin:import path="classpath:META-INF/caucho/app-default.xml"/> <!-- enables development error pages --> <development-mode-error-page/> <!-- - Uncomment to allow remote administration services - - <resin:RemoteAdminService/> --> <!-- - Default host configuration applied to all virtual hosts. --> <host-default> <!-- <access-log path="log/access.log" format='%h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i"' rollover-period="1W"/> --> <!-- creates the webapps directory for .war expansion --> <!-- <web-app-deploy path="webapps" expand-preserve-fileset="WEB-INF/work/**"/> --> <!-- - Defaults applied to each web-app. --> <web-app-default> <prologue> <allow-servlet-el/> </prologue> <session-config> <!-- - enable persistent sessions - <use-persistent-store/> --> <enable-url-rewriting>false</enable-url-rewriting> </session-config> </web-app-default> </host-default> </cluster-default> <!-- - Configures the main appliction cluster. Load-balancing configurations - will also have a load-balance-tier cluster. --> <cluster id="app-tmp.name"> <!-- sets the content root for the cluster, relative to resin.root --> <root-directory>.</root-directory> <!-- defaults for each server, i.e. JVM --> <server-default> <!-- The http port --> <!--http address="*" port="8080"/--> <!-- SSL port configuration (jsse): --> <!-- <http address="*" port="8443"> <jsse-ssl self-signed-certificate-name="resin@localhost"/> </http> --> <!-- SSL port configuration (OpenSSL): --> <!-- <http address="*" port="8443"> <openssl> <certificate-file>keys/gryffindor.crt</certificate-file> <certificate-key-file>keys/gryffindor.key</certificate-key-file> <password>my-password</password> </openssl> </http> --> <!-- - Configures the minimum free memory allowed before Resin - will force a restart. --> <memory-free-min>1M</memory-free-min> <!-- Maximum number of threads. --> <thread-max>512</thread-max> <!-- Configures the socket timeout --> <socket-timeout>65s</socket-timeout> <!-- Configures the keepalive --> <keepalive-max>128</keepalive-max> <keepalive-timeout>15s</keepalive-timeout> <!-- - <jvm-arg>-Xmx512m</jvm-arg> - <jvm-arg>-agentlib:resin</jvm-arg> --> <jvm-arg>-server</jvm-arg> <jvm-arg>-d64</jvm-arg> <jvm-arg>-Xms2048m</jvm-arg> <jvm-arg>-Xmx2048m</jvm-arg> <jvm-arg>-Xmn1024m</jvm-arg> <jvm-arg>-Xss1m</jvm-arg> <jvm-arg>-XX:PermSize=256m</jvm-arg> <jvm-arg>-XX:MaxPermSize=256m</jvm-arg> <jvm-arg>-XX:SurvivorRatio=8</jvm-arg> <jvm-arg>-XX:GCTimeRatio=19</jvm-arg> <jvm-arg>-XX:+UseParNewGC</jvm-arg> <jvm-arg>-XX:+UseConcMarkSweepGC</jvm-arg> <jvm-arg>-XX:ParallelGCThreads=20</jvm-arg> <jvm-arg>-XX:TargetSurvivorRatio=90</jvm-arg> <jvm-arg>-XX:MaxTenuringThreshold=31</jvm-arg> <watchdog-jvm-arg>-Dcom.sun.management.jmxremote</watchdog-jvm-arg> <watchdog-port>tmp.watchdog-port</watchdog-port> </server-default> <!-- define the servers in the cluster --> <server id="tmp.name" address="127.0.0.1" port="tmp.server-port"> <http id="" port="tmp.http-port"/> </server> <!-- the default host, matching any host name --> <host id="" root-directory="."> <web-app id="/" root-directory="tmp.root-directory"> <form-parameter-max>100</form-parameter-max> <stderr-log path='tmp.log-path/stderr.log' timestamp='[%Y-%m-%d %H:%M:%S] ' rollover-period='1D'/> <stdout-log path='tmp.log-path/stdout.log' timestamp='[%Y-%m-%d %H:%M:%S] ' rollover-period='1D'/> </web-app> </host> <!-- configures a deployment directory for virtual hosts --> <!-- <host-deploy path="hosts"> <host-default> <resin:import path="host.xml" optional="true"/> </host-default> </host-deploy> --> </cluster> </resin>
resin-项目名.xml
<!-- - Resin 4.0 configuration file for a clustered/load-balance environment --> <resin xmlns="http://caucho.com/ns/resin" xmlns:resin="urn:java:com.caucho.resin" xmlns:health="urn:java:com.caucho.health"> <!-- - Logging configuration for the JDK logging API. --> <log-handler name="" level="all" path="stdout:" timestamp="[%y-%m-%d %H:%M:%S.%s] {%{thread}} "/> <!-- - level='info' for production - 'fine' or 'finer' for development and troubleshooting --> <logger name="com.caucho" level="info"/> <logger name="com.caucho.java" level="config"/> <logger name="com.caucho.loader" level="config"/> <!-- - driver .jar files can be placed in ${resin.root}/ext-lib --> <class-loader> <tree-loader path="${resin.home}/ext-lib"/> <tree-loader path="${resin.root}/ext-lib"/> </class-loader> <class-loader> <tree-loader path="${resin.home}/lib"/> <tree-loader path="${resin.root}/lib"/> </class-loader> <!-- - jars with maven dependencies can be placed in project-jars to be used - by web-apps --> <resin:ProjectJarRepository path="${resin.root}/project-jars"/> <!-- - Remote management requires at least one enabled admin user. --> <resin:AdminAuthenticator> <resin:import path="${__DIR__}/admin-users.xml" optional="true"/> </resin:AdminAuthenticator> <!-- - For clustered systems, create a password in place of "changeme" - and uncomment the <resin-system-auth-key>. - - <resin-system-auth-key>changeme</resin-system-auth-key> --> <!-- - For production sites, change dependency-check-interval to something - like 600s, so it only checks for updates every 10 minutes. --> <dependency-check-interval>2s</dependency-check-interval> <!-- Java system-properties --> <system-property mail.smtp.host="127.0.0.1"/> <system-property mail.smtp.port="25"/> <!-- - Sets the default character encoding to utf-8 - - <character-encoding>utf-8</character-encoding> --> <!-- - You can change the compiler to "javac", "eclipse" or "internal". --> <javac compiler="internal" args="-source 1.5"/> <!-- - default configuration applied to all clusters --> <cluster-default> <!-- shared webapp jars for non-classloader-aware libraries --> <web-app-default> <!-- - Enable EL expressions in Servlet and Filter init-param --> <allow-servlet-el/> <prologue> <allow-servlet-el/> </prologue> <class-loader> <library-loader path="${resin.home}/webapp-jars"/> </class-loader> <!-- - Some JSP packages have incorrect .tld files. It's possible to - set validate-taglib-schema to false to work around these packages. --> <jsp> <validate-taglib-schema>true</validate-taglib-schema> <fast-jstl>true</fast-jstl> </jsp> </web-app-default> <!-- standard servlet behavior, including .jsp, .php, and WEB-INF --> <resin:import path="classpath:META-INF/caucho/app-default.xml"/> <!-- enables development error pages --> <development-mode-error-page/> <!-- - Uncomment to allow remote administration services - - <resin:RemoteAdminService/> --> <!-- - Default host configuration applied to all virtual hosts. --> <host-default> <!-- <access-log path="log/access.log" format='%h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i"' rollover-period="1W"/> --> <!-- creates the webapps directory for .war expansion --> <!-- <web-app-deploy path="webapps" expand-preserve-fileset="WEB-INF/work/**"/> --> <!-- - Defaults applied to each web-app. --> <web-app-default> <prologue> <allow-servlet-el/> </prologue> <session-config> <!-- - enable persistent sessions - <use-persistent-store/> --> <enable-url-rewriting>false</enable-url-rewriting> </session-config> </web-app-default> </host-default> </cluster-default> <!-- - Configures the main appliction cluster. Load-balancing configurations - will also have a load-balance-tier cluster. --> <cluster id="app-wms-admin"> <!-- sets the content root for the cluster, relative to resin.root --> <root-directory>.</root-directory> <!-- defaults for each server, i.e. JVM --> <server-default> <!-- The http port --> <!--http address="*" port="8080"/--> <!-- SSL port configuration (jsse): --> <!-- <http address="*" port="8443"> <jsse-ssl self-signed-certificate-name="resin@localhost"/> </http> --> <!-- SSL port configuration (OpenSSL): --> <!-- <http address="*" port="8443"> <openssl> <certificate-file>keys/gryffindor.crt</certificate-file> <certificate-key-file>keys/gryffindor.key</certificate-key-file> <password>my-password</password> </openssl> </http> --> <!-- - Configures the minimum free memory allowed before Resin - will force a restart. --> <memory-free-min>1M</memory-free-min> <!-- Maximum number of threads. --> <thread-max>512</thread-max> <!-- Configures the socket timeout --> <socket-timeout>65s</socket-timeout> <!-- Configures the keepalive --> <keepalive-max>128</keepalive-max> <keepalive-timeout>15s</keepalive-timeout> <!-- - <jvm-arg>-Xmx512m</jvm-arg> - <jvm-arg>-agentlib:resin</jvm-arg> --> <jvm-arg>-server</jvm-arg> <jvm-arg>-d64</jvm-arg> <jvm-arg>-Xms2048m</jvm-arg> <jvm-arg>-Xmx2048m</jvm-arg> <jvm-arg>-Xmn1024m</jvm-arg> <jvm-arg>-Xss1m</jvm-arg> <jvm-arg>-XX:PermSize=256m</jvm-arg> <jvm-arg>-XX:MaxPermSize=256m</jvm-arg> <jvm-arg>-XX:SurvivorRatio=8</jvm-arg> <jvm-arg>-XX:GCTimeRatio=19</jvm-arg> <jvm-arg>-XX:+UseParNewGC</jvm-arg> <jvm-arg>-XX:+UseConcMarkSweepGC</jvm-arg> <jvm-arg>-XX:ParallelGCThreads=20</jvm-arg> <jvm-arg>-XX:TargetSurvivorRatio=90</jvm-arg> <jvm-arg>-XX:MaxTenuringThreshold=31</jvm-arg> <watchdog-jvm-arg>-Dcom.sun.management.jmxremote</watchdog-jvm-arg> <watchdog-port>6601</watchdog-port> </server-default> <!-- define the servers in the cluster --> <server id="zlwms" address="127.0.0.1" port="6801"> <http id="" port="8001"/> </server> <!-- the default host, matching any host name --> <host id="" root-directory="."> <web-app id="/" root-directory="/opt/www/base-web/default"> <form-parameter-max>100</form-parameter-max> <stderr-log path='/opt/logs/resin/base-web/stderr.log' timestamp='[%Y-%m-%d %H:%M:%S] ' rollover-period='1D'/> <stdout-log path='/opt/logs/resin/base-web/stdout.log' timestamp='[%Y-%m-%d %H:%M:%S] ' rollover-period='1D'/> <filter filter-name="gzip" filter-class="com.caucho.filters.GzipFilter"> <init> <use-vary>true</use-vary> </init> </filter> <filter-mapping filter-name="gzip"> <url-pattern> <exclude-pattern>*.jpg</exclude-pattern> <exclude-pattern>*.jhtml</exclude-pattern> <include-pattern>/*</include-pattern> </url-pattern> </filter-mapping> </web-app> </host> <!-- configures a deployment directory for virtual hosts --> <!-- <host-deploy path="hosts"> <host-default> <resin:import path="host.xml" optional="true"/> </host-default> </host-deploy> --> </cluster> </resin>
jenkins服务器所在机器,查看rsyncd.conf
uid = nobody gid = nobody use chroot = no read only = yes timeout = 600 max connections = 40 secrets file = /etc/rsyncd.secrets #motd file = /etc/rsyncd.motd pid file = /var/run/rsyncd.pid lock file = /var/run/rsync.lock log file = /var/log/rsyncd.log ############################ # ***_pro ############################ [rsync_pro_***1] path=/opt/rsyncdir/wms/pro/***1 [rsync_pro_***2] path=/opt/rsyncdir/wms/pro/***2 comment=test wms rsync site hosts allow=***.***.***.201 ***.***.***.202