Linux各种服务配置开机自启
2022/9/6 5:24:18
本文主要是介绍Linux各种服务配置开机自启,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
一、Linux配置redis开机自启
(1)到redis配置文件中找到conf文件:vi redis.conf
(2)daemonize no 修改为:daemonize yes
(3)cd /etc/init.d,新建文件redis,可用该路径下:(/usr/local/redis/redis6.2.7/utils/redis_init_script)
(4)进行配置:
#!/bin/bash #chkconfig: 22345 10 90 #description: Start and Stop redis #端口 REDISPORT=6379 #server:/usr/local/redis/redis-6.2.7/src/redis-server EXEC=/usr/local/redis/bin/redis-server #/usr/local/redis/redis-6.2.7/src/redis-cli CLIEXEC=/usr/local/redis/bin/redis-cli #密码 REDISPWD=123456 #该文件路径可从conf文件中找 PIDFILE=/var/run/redis_6379.pid #conf路径 CONF=/usr/local/redis/etc/redis.conf case "$1" in start) if [ -f $PIDFILE ];then echo "$PIDFILE exists,process is already running or crashed" else echo "Starting Redis server..." $EXEC $CONF fi ;; stop) if [ ! -f $PIDFILE ];then echo "$PIDFILE does not exist,process is not running" else PID=$(cat $PIDFILE) echo "Stopping..." $CLIEXEC -p $REDISPORT -a $REDISPWD shutdown while [ -x /proc/${PID} ] do echo "Waiting for Redis to shutdown..." sleep 1 done echo "Redis stopped" fi ;; restart) "$0" stop sleep 3 "$0" start ;; *) echo "Please use start or stop or restart as first argument" ;; esac
(5)修改文件权限:chmod 777 /etc/init.d/redis
(6)测试脚本
cd /etc/init.d ./redis start ./redis stop ps -ef|grep redis
(7)配置开机自启
chkconfig --add /etc/init.d/redis chkconfig redis on
二、Linux配置Oracle11g开机自启
(1)首先查看/etc路径下是否有oratab文件
如果没有root身份下执行以下命令 cd $ORACLE_HOME ./root.sh
(2)执行dbstart 数据库自带启动脚本
cd $ORACLE_HOME cd bin/ #编辑dbstart以及dushut文件 ORACLE_HOME_LISTNER=$1修改成 ORACLE_HOME_LISTNER=$ORACLE_HOME,前提是$ORACLE_HOME环境设置正确:
(3)编辑oratab文件
vi /etc/oratab 将orcl:/u01/app/oracle/product/11.2.0/dbhome_1:N 修改成 orcl:/u01/app/oracle/product/11.2.0/dbhome_1:Y 注意:orcl为数据库实例名
(4)root用户编辑/etc/rc.d/rc.local启动文件,添加数据库启动脚本dbstart
vi /etc/rc.d/rc.local #touch /var/lock/subsys/local下加入如下内容(修改成自己的oracle路径) su oracle -lc "/home/oracle/app/oracle/product/11.2.0/dbhome_1/bin/lsnrctl start" su oracle -lc /home/oracle/app/oracle/product/11.2.0/dbhome_1/bin/dbstart
(5)赋予权限
chmod 777 /etc/rc.d/rc.local cd /etc/rc.d/ #看看rc.local变为绿色 ll
(6)重启
#重启 reboot #连接 sqlplus / as sysdba #查看状态 select status from v$instance; #退出 quit #查看监听状态 lsnrctl status
三、批处理启动服务
(1)创建.sh文件
#!/bin/bash #chkconfig:2345 10 90 #description:resind cd /home/sgxy/mpms nohup ./01-startAdministratorLogic.sh > nohup01.out & nohup ./02-startUapServerLogic.sh > nohup02.out & port_status=`netstat -nlt|grep 9003|wc -l` sleep 10 if [ $port_status -lt 1 ]; then echo "succeed" nohup ./03-startMpms.sh > nohup03.out & nohup ./04-startDamr.sh > nohup04.out & cd /home/sgxy/mpms/other_jar/dtu nohup java -jar DtuDataServer.jar > catalina.out 2>&1 & else echo "filed" fi
以下内容中必须填写
chkconfig:2345 10 90
description:resind
(2)配置开机自启动
然后把该文件放到/etc/rc.d/init.d目录下,redis开机自启动第七步再来一遍
(3)重启查看
reboot ps -ef | grep 'java'
注意
通过shell脚本运行jar包报错运行如下命令,建立软连接
echo $JAVA_HOME #复制路径:/home/local/java/jdk1.8.0_301 cd /usr/bin ln -s -f /home/local/java/jdk1.8.0_301/bin/java
这篇关于Linux各种服务配置开机自启的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-03-30[译]漫画SELinux概念
- 2024-03-29linux 移动文件
- 2024-03-28linux .so file
- 2024-03-28Linux 磁盘管理
- 2024-03-28Linux学习笔记(十三)磁盘管理(一):磁盘分区
- 2024-03-26linux 创建 文件
- 2024-03-25使用SecureCRT对Linux vim进行颜色设置
- 2024-03-202019-2020-12 20199317 《Linux内核原理与分析》 第十二周作业
- 2024-03-20Linux运维的第二周总结
- 2024-03-13how to count number of directories in linux