1 说明
设置开机自启动,需要用到systemctl工具。systemctl是一个systemd工具,主要负责控制systemd系统和服务管理器。systemd是一个系统管理守护进程、工具和库的集合,用于取代System V初始进程。Systemd的功能是用于集中管理和配置类UNIX系统。
2 准备
操作系统:Oracle Linux 7.1
systemctl –version : systemd 208
weblogic version:12.2.1.3.0
3 编写系统服务文件
3.1 adminserver 系统服务文件
[root@localhost system]# vi weblogic.service [Unit] Description=WebLogic Adminserver Service[Service] [Service] Type=simple WorkingDirectory=/weblogic/Oracle/Middleware/user_projects/domains/base_domain ExecStart=/weblogic/Oracle/Middleware/user_projects/domains/base_domain/bin/startWebLogic.sh ExecStop=/weblogic/Oracle/Middleware/user_projects/domains/base_domain/bin/stopWebLogic.sh User=weblogic Group=weblogic [Install] WantedBy=multi-user.target
3.2 配置weblogic将日志输出到指定文件${DOMAIN_HOME}/admin.log,也就是在以下命令后面加上>”${DOMAIN_HOME}/admin.log” 2>&1
[weblogic@localhost bin]$ vi startWebLogic.sh if [ "${WLS_REDIRECT_LOG}" = "" ] ; then echo "Starting WLS with line:" echo "${JAVA_HOME}/bin/java ${JAVA_VM} ${MEM_ARGS} ${LAUNCH_ARGS} -Dweblogic.Name=${SERVER_NAME} -Djava.security.policy=${WLS_POLICY_FILE} ${JAVA_OPTIONS} ${PROXY_SETTINGS} ${SERVER_CLASS}" ${JAVA_HOME}/bin/java ${JAVA_VM} ${MEM_ARGS} ${LAUNCH_ARGS} -Dweblogic.Name=${SERVER_NAME} -Djava.security.policy=${WLS_POLICY_FILE} ${JAVA_OPTIONS} ${PROXY_SETTINGS} ${SERVER_CLASS} >"${DOMAIN_HOME}/admin.log" 2>&1 else echo "Redirecting output from WLS window to ${WLS_REDIRECT_LOG}" ${JAVA_HOME}/bin/java ${JAVA_VM} ${MEM_ARGS} ${LAUNCH_ARGS} -Dweblogic.Name=${SERVER_NAME} -Djava.security.policy=${WLS_POLICY_FILE} ${JAVA_OPTIONS} ${PROXY_SETTINGS} ${SERVER_CLASS} >"${DOMAIN_HOME}/admin.log" 2>&1
3.3 查看系统服务文件是否被识别
[root@localhost system]# systemctl list-unit-files|grep weblogic weblogic.service disabled 3.4 禁用防火墙和SELinux
[root@localhost system]# setenforce 0 [root@localhost system]# sed -i "/^SELINUX=/s#enforcing#disabled#" /etc/selinux/config [root@localhost system]# cat /etc/selinux/config # This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX=disabled # SELINUXTYPE= can take one of three two values: # targeted - Targeted processes are protected, # minimum - Modification of targeted policy. Only selected processes are protected. # mls - Multi Level Security protection. SELINUXTYPE=targeted [root@localhost system]# systemctl is-enabled firewalld enabled [root@localhost system]# systemctl status firewalld firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled) Active: active (running) since Fri 2023-03-31 14:11:15 CST; 1h 16min ago Main PID: 602 (firewalld) CGroup: /system.slice/firewalld.service └─602 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid Mar 31 14:11:15 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon. [root@localhost system]# systemctl stop firewalld [root@localhost system]# systemctl disable firewalld rm '/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service' rm '/etc/systemd/system/basic.target.wants/firewalld.service' [root@localhost system]# systemctl is-enabled firewalld disabled [root@localhost system]# firewall-cmd --zone=public --list-ports FirewallD is not running
4 测试系统服务
4.1 启动系统服务
[root@localhost system]# systemctl start weblogic.service
[root@localhost base_domain]# tail -f admin.log
<Mar 31, 2023 3:56:09 PM CST> <Info> <Security> <BEA-090905> <Disabling the CryptoJ JCE Provider self-integrity check for better startup performance. To enable this check, specify -Dweblogic.security.allowCryptoJDefaultJCEVerification=true.>
<Mar 31, 2023 3:56:09 PM CST> <Info> <Security> <BEA-090906> <Changing the default Random Number Generator in RSA CryptoJ from ECDRBG128 to HMACDRBG. To disable this change, specify -Dweblogic.security.allowCryptoJDefaultPRNG=true.>
<Mar 31, 2023 3:56:10 PM CST> <Info> <WebLogicServer> <BEA-000377> <Starting WebLogic Server with Java HotSpot(TM) 64-Bit Server VM Version 25.131-b11 from Oracle Corporation.>
<Mar 31, 2023 3:56:10 PM CST> <Info> <RCM> <BEA-2165021> <“ResourceManagement” is not enabled in this JVM. Enable “ResourceManagement” to use the WebLogic Server “Resource Consumption Management” feature. To enable “ResourceManagement”, you must specify the following JVM options in the WebLogic Server instance in which the JVM runs: -XX:+UnlockCommercialFeatures -XX:+ResourceManagement.>
<Mar 31, 2023 3:56:10 PM CST> <Info> <Management> <BEA-141107> <Version: WebLogic Server 12.2.1.3.0 Thu Aug 17 13:39:49 PDT 2017 1882952>
<Mar 31, 2023 3:59:53 PM CST> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to STARTING.>
<Mar 31, 2023 3:59:53 PM CST> <Info> <WorkManager> <BEA-002900> <Initializing self-tuning thread pool.>
<Mar 31, 2023 3:59:53 PM CST> <Info> <WorkManager> <BEA-002942> <CMM memory level becomes 0. Setting standby thread pool size to 256.>
<Mar 31, 2023 4:01:39,810 PM CST> <Notice> <Log Management> <BEA-170019> <The server log file weblogic.logging.FileStreamHandler instance=460171696
Current log file=/weblogic/Oracle/Middleware/user_projects/domains/base_domain/servers/AdminServer/logs/AdminServer.log
Rotation dir=/weblogic/Oracle/Middleware/user_projects/domains/base_domain/servers/AdminServer/logs
is opened. All server side log events will be written to this file.>
<Mar 31, 2023 4:01:40,077 PM CST> <Notice> <Security> <BEA-090946> <Security pre-initializing using security realm: myrealm>
<Mar 31, 2023 4:01:40,771 PM CST> <Notice> <Security> <BEA-090947> <Security post-initializing using security realm: myrealm>
<Mar 31, 2023 4:01:41,826 PM CST> <Notice> <Security> <BEA-090082> <Security initialized using administrative security realm: myrealm>
<Mar 31, 2023 4:01:42,631 PM CST> <Notice> <JMX> <BEA-149512> <JMX Connector Server started at service:jmx:iiop://10.138.130.64:7001/jndi/weblogic.management.mbeanservers.runtime.>
4.2 停止系统服务
[root@localhost system]# systemctl stop weblogic.service
5 将服务设置成开机自启动
[root@localhost system]# systemctl enable weblogic.service ln -s '/etc/systemd/system/weblogic.service' '/etc/systemd/system/multi-user.target.wants/weblogic.service' [root@localhost system]# systemctl list-unit-files|grep weblogic weblogic.service enabled
反向命令:
[root@localhost system]# systemctl disable weblogic.service rm '/etc/systemd/system/multi-user.target.wants/weblogic.service' [root@localhost system]# systemctl list-unit-files|grep weblogic weblogic.service disabled
6 重启服务器并检查weblogic是否自启动
[root@localhost system]#reboot [root@localhost ~]# ps -ef | grep java weblogic 721 1 0 16:13 ? 00:00:01 /usr/java/jdk1.8.0_131/bin/java -Dderby.system.home=/weblogic/Oracle/Middleware/user_projects/domains/base_domain/common/db -classpath /weblogic/Oracle/Middleware/wlserver/common/derby/lib/derby.jar:/weblogic/Oracle/Middleware/wlserver/common/derby/lib/derbynet.jar:/weblogic/Oracle/Middleware/wlserver/common/derby/lib/derbytools.jar:/weblogic/Oracle/Middleware/wlserver/common/derby/lib/derbyclient.jar org.apache.derby.drda.NetworkServerControl start weblogic 722 645 6 16:13 ? 00:01:07 /usr/java/jdk1.8.0_131/bin/java -server -Xms256m -Xmx512m -XX:CompileThreshold=8000 -cp /weblogic/Oracle/Middleware/wlserver/server/lib/weblogic-launcher.jar -Dlaunch.use.env.classpath=true -Dweblogic.Name=AdminServer -Djava.security.policy=/weblogic/Oracle/Middleware/wlserver/server/lib/weblogic.policy -Djava.system.class.loader=com.oracle.classloader.weblogic.LaunchClassLoader -javaagent:/weblogic/Oracle/Middleware/wlserver/server/lib/debugpatch-agent.jar -da -Dwls.home=/weblogic/Oracle/Middleware/wlserver/server -Dweblogic.home=/weblogic/Oracle/Middleware/wlserver/server weblogic.Server root 3094 3019 0 16:31 pts/0 00:00:00 grep --color=auto java