在WebLogic启动中设置环境变量的最佳方法 [英] Best way to set environmental variables in WebLogic startup

查看:686
本文介绍了在WebLogic启动中设置环境变量的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Oracle WebLogic中,设置环境变量以使其可被您的代码访问的最佳方法是什么?我们有运行WebLogic的第三方应用程序,用于寻找环境变量.

In Oracle WebLogic, what is the best way to set an environmental variable so that it can be accessed by your code? We have third-party apps running WebLogic that look for an environment variable.

注意:我们使用节点管理器启动托管服务器.

Note: We start our managed servers using Node Manager.

我希望能够在域配置中的某个位置进行设置,例如在管理控制台的服务器启动"标签中,但是似乎没有合适的位置.

I would prefer to be able to set it somewhere in the domain configuration, like in the Server Start tab in the Admin Console, but there seems no good place to do that.

我唯一看到的方法是

  1. 编辑bin/setDomainEnv.sh以导出环境变量
  2. 修改nodemanager.properties以具有StartScriptEnabled=true
  1. Edit the bin/setDomainEnv.sh to export the environmental variable
  2. Modify nodemanager.properties to have StartScriptEnabled=true

这是要强制NodeManager使用<ms_home>/bin/startManagedWebLogic.sh,该源将获取setDomainEnv.sh,并在NodeManager启动时将其提取.但是您还必须在每台计算机上执行此操作.

What this does is, forces NodeManager to use the <ms_home>/bin/startManagedWebLogic.sh, which sources setDomainEnv.sh and they will be picked up when NodeManager starts. But you also have to do this on every machine.

想知道是否有比使用Oracle的启动脚本更干净的方法.

Wondering if there is a cleaner way of doing this than mucking with Oracle's startup scripts.

推荐答案

如果您确定没有使用任何通用框架(例如Spring框架),并且您有严格寻找环境变量的代码,那么您必须在启动任何期望的Java进程之前,在任何常规配置文件之外设置环境变量. Java进程启动后,环境变量为只读,并且该进程的最终 .

If you know for certain that none of the common frameworks are in use, like the Spring Framework, and you have code that strictly looks for environment variables, then you must set the environment variables outside of any of the usual configuration files, before the Java process that will be expecting it, is started. Once the Java process is started, environment variables are read-only and final for that process.

注意::如果您需要整个系统的环境变量,请使用/etc/profile,/etc/bash_profile,/etc/environment等.请记住,在这些变量中设置变量全局位置要求您从全新的登录名重新启动节点管理器.您无需重新启动,但配置文件/环境文件通常仅在登录时提供.

Note: If you need Environment Variables for the entire system, use /etc/profile, /etc/bash_profile, /etc/environment, etc. Keep in mind, that setting the variables in these global locations requires that you restart the Node Manager from a fresh login. You do not need to reboot, but profile/environment files are usually only sourced on login.

对于仅一个域或节点内的应用程序,环境变量应位于服务器的启动脚本中.编辑 setDomainEnv.[sh | cmd] start(Managed)Weblogic.[sh | cmd] 是设置WebLogic环境变量的最佳选择.

For apps within just one domain or node, environment variables should be in the startup scripts for the server(s). Editing setDomainEnv.[sh|cmd] or start(Managed)Weblogic.[sh|cmd], is the best option for setting WebLogic environment variables.

但是,如果应用程序使用的是Spring,则会合并系统属性和环境变量.强烈建议系统属性,并且更易于维护和控制.

However, if the app is using Spring, system properties and environment variables are combined. System properties are highly encouraged and easier to maintain and control.

参考:什么设置Java系统属性-D或System.setProperty()的最佳实践?

Weblogic域环境变量

设置系统属性或环境变量的地方之一是编辑域环境脚本,该域环境脚本用于启动共享相同WebLogic服务器安装和域的所有节点或服务器.内< weblogic_domain>/bin/setDomainEnv.sh (在Windows上为 setDomainEnv.cmd ),对于环境变量,只需在顶部附近添加它们,并添加注释以记录其使用情况.

One of the places to set both system properties or environment variables, is to edit the domain environment script used to start all nodes or servers that share the same WebLogic server installation and domain. Inside < weblogic_domain >/bin/setDomainEnv.sh, (setDomainEnv.cmd on windows), for environment variables, just add them near the top and add comments to document their use.

    export CUSTOM_VAR="test" # UNIX comment to describe environment variable.

对于系统属性,可以通过在文件顶部附近,WL_HOME定义附近,函数和注释之后添加EXTRA_JAVA_PROPERTIES的行来添加将添加到每台服务器的命令行参数.

For System Properties, you can add command line arguments that will be added to every server by adding a line for EXTRA_JAVA_PROPERTIES, near the top of the file, near the WL_HOME definition, but after the functions and comments.

    EXTRA_JAVA_PROPERTIES="-Denv=TEST"
    export EXTRA_JAVA_PROPERTIES

    WL_HOME="/appl/oracle/middleware/wls/12.1.2.0.0/wlserver"
    export WL_HOME

特定于Weblogic节点的环境变量

如果对于由同一节点管理器启动的每个节点需要不同的环境变量,则必须多自定义启动脚本.在这种情况下,请编辑< weblogic_domain>/bin/startManagedWeblogic.[sh | cmd] ,并在_export SERVER_NAME_之后插入一些脚本逻辑.这样,您可以根据SERVER_NAME等驱动设置.

If you need different Environment Variables for each node that is started up by the same Node Manager, you will have to customize the startup scripts a little more. In that case, edit the < weblogic_domain >/bin/startManagedWeblogic.[sh|cmd] and insert some scripting logic after _export SERVER_NAME_. This way, you can drive your settings based on SERVER_NAME, etc.

提示: Windows 环境变量在System.getenv(..)中不区分大小写.

Tip: Windows Environment Variables are not case-sensitive with System.getenv(..).

这篇关于在WebLogic启动中设置环境变量的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆