- 两台服务器都需要安装JDK和WebLogic
在两台服务器上都执行以下步骤:
# 安装JDK
# 1. 创建Java安装目录
mkdir -p /usr/java
cd /usr/java# 2. 解压JDK
tar -zxvf /path/to/jdk-8u341-linux-x64.tar.gz# 3. 配置环境变量
cat >> /etc/profile << 'EOF'
export JAVA_HOME=/usr/java/jdk1.8.0_341
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
EOF# 4. 使环境变量生效
source /etc/profile# 5. 验证JDK安装
java -version
- 服务器1配置(AdminServer + Managed Server1)
# 1. 创建域配置脚本
cat > /home/weblogic/create_domain.py << EOF
readTemplate('/home/weblogic/oracle/middleware/wlserver/common/templates/wls/wls.jar')# 配置AdminServer
cd('Servers/AdminServer')
set('ListenAddress','192.168.1.101')
set('ListenPort', 7001)# 创建Machine1
cd('/')
create('Machine1', 'Machine')
cd('Machine/Machine1')
create('Machine1', 'NodeManager')
cd('NodeManager/Machine1')
set('ListenAddress', '192.168.1.101')
set('ListenPort', 5556)# 创建Machine2
cd('/')
create('Machine2', 'Machine')
cd('Machine/Machine2')
create('Machine2', 'NodeManager')
cd('NodeManager/Machine2')
set('ListenAddress', '192.168.1.102')
set('ListenPort', 5556)# 创建Server1
cd('/')
create('Server1', 'Server')
cd('Server/Server1')
set('ListenAddress', '192.168.1.101')
set('ListenPort', 7003)
set('Machine', 'Machine1')# 创建Server2
cd('/')
create('Server2', 'Server')
cd('Server/Server2')
set('ListenAddress', '192.168.1.102')
set('ListenPort', 7003)
set('Machine', 'Machine2')# 设置管理员密码
cd('/')
cd('Security/base_domain/User/weblogic')
cmo.setPassword('weblogic2022')# 创建域
setOption('OverwriteDomain', 'true')
writeDomain('/home/weblogic/oracle/middleware/user_projects/domains/base_domain')
closeTemplate()
exit()
EOF# 2. 执行域创建
cd /home/weblogic/oracle/middleware/oracle_common/common/bin
./wlst.sh /home/weblogic/create_domain.py
- 配置Node Manager(两台服务器都需要)
# 1. 创建Node Manager配置
cd /home/weblogic/oracle/middleware/user_projects/domains/base_domain/nodemanager
cat > nodemanager.properties << EOF
ListenAddress=
ListenPort=5556
SecureListener=false
WebLogicHome=/home/weblogic/oracle/middleware/wlserver
DomainsFile=/home/weblogic/oracle/middleware/wlserver/common/nodemanager/nodemanager.domains
LogLimit=0
LogLevel=INFO
LogToStderr=true
LogCount=1
DomainsDirRemoteSharingEnabled=true
StartScriptEnabled=true
NativeVersionEnabled=true
EOF
- 服务器2配置
# 1. 复制域配置
# 在服务器1上打包域配置
cd /home/weblogic/oracle/middleware/user_projects/domains
tar czf base_domain.tar.gz base_domain# 将base_domain.tar.gz传输到服务器2并解压
scp base_domain.tar.gz weblogic@192.168.1.102:/home/weblogic/oracle/middleware/user_projects/domains/
cd /home/weblogic/oracle/middleware/user_projects/domains
tar xzf base_domain.tar.gz
- 启动顺序
在服务器1上:
# 1. 启动Node Manager
cd /home/weblogic/oracle/middleware/user_projects/domains/base_domain/bin
./startNodeManager.sh# 2. 启动AdminServer
./startWebLogic.sh# 3. 启动Managed Server1
./startManagedWebLogic.sh Server1
在服务器2上:
# 1. 启动Node Manager
cd /home/weblogic/oracle/middleware/user_projects/domains/base_domain/bin
./startNodeManager.sh# 2. 启动Managed Server2
./startManagedWebLogic.sh Server2 http://192.168.1.101:7001
- 验证配置
访问WebLogic控制台:
http://192.168.1.101:7001/console
用户名:weblogic
密码:weblogic2022
以上完成两台weblogic主备配置
检查:
- Node Manager状态
- Managed Servers状态
- 集群通信
4.在WebLogic集群环境中,config.xml是关键配置文件。虽然通过create_domain.py脚本创建域时会自动生成基本配置,但我们可以检查和修改config.xml以确保配置正确:
config.xml位置:/home/weblogic/oracle/middleware/user_projects/domains/base_domain/config/config.xml
需要检查的关键配置:
<?xml version='1.0' encoding='UTF-8'?>
<domain xmlns="http://xmlns.oracle.com/weblogic/domain" xmlns:sec="http://xmlns.oracle.com/weblogic/security" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wls="http://xmlns.oracle.com/weblogic/security/wls" xsi:schemaLocation="http://xmlns.oracle.com/weblogic/security/wls http://xmlns.oracle.com/weblogic/security/wls/1.0/wls.xsd http://xmlns.oracle.com/weblogic/domain http://xmlns.oracle.com/weblogic/1.0/domain.xsd http://xmlns.oracle.com/weblogic/security http://xmlns.oracle.com/weblogic/1.0/security.xsd"><name>base_domain</name><domain-version>12.2.1.4.0</domain-version><!-- 安全配置 --><security-configuration><name>base_domain</name><realm><sec:authentication-provider xsi:type="wls:default-authenticatorType"></sec:authentication-provider><sec:authentication-provider xsi:type="wls:default-identity-asserterType"></sec:authentication-provider></realm></security-configuration><!-- AdminServer配置 --><server><name>AdminServer</name><listen-port>7001</listen-port><listen-address>192.168.1.101</listen-address></server><!-- Managed Server1配置 --><server><name>Server1</name><listen-port>7003</listen-port><listen-address>192.168.1.101</listen-address><machine>Machine1</machine></server><!-- Managed Server2配置 --><server><name>Server2</name><listen-port>7003</listen-port><listen-address>192.168.1.102</listen-address><machine>Machine2</machine></server><!-- Machine1配置 --><machine><name>Machine1</name><node-manager><name>Machine1</name><listen-address>192.168.1.101</listen-address><listen-port>5556</listen-port></node-manager></machine><!-- Machine2配置 --><machine><name>Machine2</name><node-manager><name>Machine2</name><listen-address>192.168.1.102</listen-address><listen-port>5556</listen-port></node-manager></machine><!-- 集群配置 --><cluster><name>Cluster-1</name><multicast-address>239.192.0.0</multicast-address><multicast-port>7777</multicast-port><cluster-messaging-mode>unicast</cluster-messaging-mode></cluster><!-- 将Server1和Server2加入集群 --><server-group-targeting-enabled>true</server-group-targeting-enabled><server><name>Server1</name><cluster>Cluster-1</cluster></server><server><name>Server2</name><cluster>Cluster-1</cluster></server>
</domain>
补:
已在一台服务器安装weblogic,现增加一台服务器进行搭配成weblogic集群,进行重新安装配置:
(已安装配置的机器:https://blog.csdn.net/qq_37257431/article/details/144940933?spm=1001.2014.3001.5502)
在服务器1上修改配置
# 1. 进入config目录
cd /home/weblogic/oracle/middleware/user_projects/domains/base_domain/config# 2. 备份原配置文件
cp config.xml config.xml.bak# 3. 修改config.xml
vim config.xml
需要在config.xml中添加或修改以下内容:
<domain><!-- AdminServer配置 --><server><name>AdminServer</name><listen-address>192.168.1.101</listen-address><listen-port>7001</listen-port></server><!-- Machine1配置 --><machine><name>Machine1</name><node-manager><name>Machine1</name><listen-address>192.168.1.101</listen-address><listen-port>5556</listen-port></node-manager></machine><!-- Machine2配置 --><machine><name>Machine2</name><node-manager><name>Machine2</name><listen-address>192.168.1.102</listen-address><listen-port>5556</listen-port></node-manager></machine><!-- Server1配置 --><server><name>Server1</name><listen-address>192.168.1.101</listen-address><listen-port>7003</listen-port><machine>Machine1</machine></server><!-- Server2配置 --><server><name>Server2</name><listen-address>192.168.1.102</listen-address><listen-port>7003</listen-port><machine>Machine2</machine></server>
</domain>