1、环境
centOS 7.6 64位
Oracle 11g 11.2.0.4 64位
2、方法:
在rc.local文件中增加自动启动的命令
touch /var/lock/subsys/local
su - oracle -c 'dbstart'
su - oracle -c 'lsnrctl start'
cd /usr/local/nginx/sbin && ./nginx
cd /home/newfis/newfisWebapp && source /etc/profile;nohup java -jar demo-0.0.1-SNAPSHOT.jar>>nohup.out 2>&1 &
3、总结
3.1 centOS的开机启动命令
在/etc/rc.d/rc.local文件中的命令,在OS启动时都会执行。这个版本建议用serviced方式,但这个方法简单明了。
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
# 增加这个文件是用来保持兼容性的。
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
# 强烈建议使用systemd或udev rules方式代替这种方式
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
3.2 执行其他用户下的命令
因为启动中,执行命令的用户是root,与目标应用的环境变量是不一样的。
可以切换用户执行命令。
su - oracle -c dbstart
-c:是su命令的参数,pass a single command to the shell传递单个命令给shell。
注意:
- 单个命令执行完毕后,会返回之前的用户环境;
[root@board ~]# su - oracle -c date
Tue Apr 26 11:58:20 CST 2022
[root@board ~]#
- 只能传递单个命令,当多个命令时要’'或者自己写个脚本
命令分开写,后续的参数不生效。
[root@board ~]# su - oracle -c lsnrctl status
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 26-APR-2022 11:54:42
Copyright (c) 1991, 2013, Oracle. All rights reserved.
Welcome to LSNRCTL, type "help" for information.
LSNRCTL> ^C
Session terminated, killing shell...
...killed.
命令放到单引号里,后续的参数生效。
[root@board ~]#
[root@board ~]#
[root@board ~]#
[root@board ~]# su - oracle -c 'lsnrctl status'
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 26-APR-2022 11:55:01
Copyright (c) 1991, 2013, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date 26-APR-2022 10:50:50
Uptime 0 days 1 hr. 4 min. 11 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /home/oracle/app/product/112040/db_1/network/admin/listener.ora
Listener Log File /home/oracle/app/diag/tnslsnr/board/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=board)(PORT=1521)))
Services Summary...
Service "test1" has 1 instance(s).
Instance "test1", status READY, has 1 handler(s) for this service...
Service "test1XDB" has 1 instance(s).
Instance "test1", status READY, has 1 handler(s) for this service...
The command completed successfully
3.3 nohup不要nohup.out
nohup命令默认生成nohup.out的日志,日志会越来越大。如下:
nohup java -jar test.jar &
指定输出到null,错误输出到log,关闭默认输出:
nohup java -jar yourProject.jar >/dev/null 2>log &
注意:
linux有3个默认的输出输出:0 指键盘输入;1 指显示器输出;2指错误输出。
2>log:输出错误时,输出到log文件。


4353

被折叠的 条评论
为什么被折叠?



