centos 7 启动脚本?centos7下载地址
大家好,今天给各位分享centos 7 启动脚本的一些知识,其中也会对centos7下载地址进行解释,文章篇幅可能偏长,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在就马上开始吧!
centos7如何添加开机启动服务脚本
一、添加开机自启服务
在centos7中添加开机自启服务非常方便,只需要两条命令(以Jenkins为例):
systemctl enable jenkins.service#设置jenkins服务为自启动服务sysstemctl start jenkins.service#启动jenkins服务
二、添加开机自启脚本
在centos7中增加脚本有两种常用的方法,以脚本autostart.sh为例:
#!/bin/bash#description:开机自启脚本/usr/local/tomcat/bin/startup.sh#启动tomcat
方法一
1、赋予脚本可执行权限(/opt/script/autostart.sh是你的脚本路径)
chmod+x/opt/script/autostart.sh
1
2、打开/etc/rc.d/rc/local文件,在末尾增加如下内容
/opt/script/autostart.sh
3、在centos7中,/etc/rc.d/rc.local的权限被降低了,所以需要执行如下命令赋予其可执行权限
chmod+x/etc/rc.d/rc.local
方法二
1、将脚本移动到/etc/rc.d/init.d目录下
mv/opt/script/autostart.sh/etc/rc.d/init.d
2、增加脚本的可执行权限
chmod+x/etc/rc.d/init.d/autostart.sh
3、添加脚本到开机自动启动项目中
cd/etc/rc.d/init.dchkconfig--add autostart.shchkconfig autostart.sh on
centos 7 shell 脚本怎样运行
一、root权限编辑/etc/rc.d/rc.local
Shell代码
su
cd/etc/rc.d/
vi rc.local
二、在这个文件加上你要执行的脚本,全部内容如下:
Shell代码
#!/bin/sh
#
# This script will be executed*after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch/var/lock/subsys/local
mount//192.168.0.3/data2-1/mnt/data2-1-o username=un,password=123
mount//192.168.0.3/data2-2/mnt/data2-2-o username=un,password=123
mount//192.168.0.3/data2-3/mnt/data2-3-o username=un,password=123
mount//192.168.0.3/data2-4/mnt/data2-4-o username=un,password=123
mount//192.168.0.3/data2-5/mnt/data2-4-o username=un,password=123
提示:这里的做法很不成熟,希望不要这样,最好自己写个脚本文件在这里来调用,结构更清晰,但是要注意到是把要执行的命令作为一个参数传递给su。
另外复习一个VI编辑命令-拷贝
yy
p
CENTOS7开机自启动脚本
1、因为在centos7中/etc/rc.d/rc.local的权限被降低了,所以需要赋予其可执行权
2、赋予脚本可执行权限
假设/usr/local/script/autostart.sh是你的脚本路径,给予执行权限
3、打开/etc/rc.d/rc.local文件,在末尾增加如下内容
1、将脚本移动到/etc/rc.d/init.d目录下
2、增加脚本的可执行权限
3、添加脚本到开机自动启动项目中
chkconfig启动脚本规范在脚本开头加入下面内容:
说明:chkonfig后面是启动级别和优先级,description后面是服务描述。如上面脚本意思是,
服务必须在运行级2,3,4,5下被启动或关闭,启动的优先级是90,停止的优先级是10。
优先级范围是0-100,数字越大,优先级越低。
Linux启动优先级
运行级别就是操作系统当前正在运行的功能级别。这个级别从0到6,具有不同的功能。
这些级别在/etc/inittab文件里指定。这个文件是init程序寻找的主要文件,最先运行的服务是那些放在/etc/rc.d目录下的文件。
不同的运行级定义如下:(可以参考Linux里面的/etc/inittab)