redhat nginx随机启动脚本
开机自动启动nginx
1. 扔脚本进去/etc/init.d/
2. 授权
chmod +x nginx
3. 一旦抛出:binsh^M错误就执行编码改写
设置dos统一编码
(请看nginx脚本抛出binsh^M bad interpreter文档)
4. 添加到服务
chkconfig --add ningx
5. 随机启动脚本带动nginx开机启动
chkconfig --level 2345 nginx on
附上脚本
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: NGINX is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid # Source function library.
. /etc/rc.d/init.d/functions # Source networking configuration.
. /etc/sysconfig/network # Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0 nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx) NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf" [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx lockfile=/var/lock/subsys/nginx make_dirs() {
# make required directories
user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
if [ -z "`grep $user /etc/passwd`" ]; then
useradd -M -s /bin/nologin $user
fi
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
} start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
} stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
} restart() {
configtest || return $?
stop
sleep 1
start
} reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
} force_reload() {
restart
} configtest() {
$nginx -t -c $NGINX_CONF_FILE
} rh_status() {
status $prog
} rh_status_q() {
rh_status >/dev/null 2>&1
} case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
执行脚本时发现如下错误:
/bin/sh^M: bad interpreter: 没有那个文件或目录
错误分析:
因为操作系统是windows,我在windows下编辑的脚本,所以有可能有不可见字符。
脚本文件是DOS格式的, 即每一行的行尾以\n\r来标识, 其ASCII码分别是0x0D, 0x0A.
可以有很多种办法看这个文件是DOS格式的还是UNIX格式的, 还是MAC格式的
解决方法:
vim filename
然后用命令
:set ff? #可以看到dos或unix的字样. 如果的确是dos格式的。
然后用
:set ff=unix #把它强制为unix格式的, 然后存盘退出。
再次运行脚本。
在RedHat 6上编译安装openssl后,运行openssl version出现如下错误:
[html] view plain copy
openssl: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory
这是由于openssl库的位置不正确造成的。
解决方法:
在root用户下执行:
[html] view plain copy
ln -s /usr/local/lib64/libssl.so.1.1 /usr/lib64/libssl.so.1.1
ln -s /usr/local/lib64/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1
redhat nginx随机启动脚本的更多相关文章
- rsync随机启动脚本
服务端 #!/bin/sh # chkconfig: # description: Saves and restores system entropy pool for \ #create by xi ...
- centos 随机启动脚本编写
先说下问题背景 目前手上开发的产品是springboot微服务的,我们用jenkins来做的部署,部署脚本如下: 1.build脚本 负责从git服务器拉脚本 2.微服务脚本: #!/bin/shap ...
- nginx 的启动脚本
下载路径为: wget -q http://www.dwhd.org/script/Nginx-init-CentOS 根据自己的实际环境修改相应的参数 把该脚本放到/etc/rc.d/init.d/ ...
- Nginx的启动脚本(Centos)
vim /etc/init.d/nginxservice nginx start #!/bin/sh # chkconfig: 2345 85 15 # description:Nginx Serve ...
- nginx-(/etc/init.d/nginx)启动脚本
#!/bin/bash #nx Startup script for the Nginx HTTP Server # it is v. version. # chkconfig: - # descri ...
- Nginx的启动脚本
vi /etc/init.d/nginx #!/bin/sh # nginx Startup script for nginx # chkconfig: - 85 15 # proces ...
- Nginx服务启动脚本
#!/bin/sh # chkconfig: 2345 40 98 # description: Start/Stop Nginx server path=/application/nginx/sbi ...
- Nginx的编译安装及服务启动脚本
1.解决依赖关系 编译安装nginx需要事先需要安装开发包组"Development Tools"和 "Development Libraries".同时,还需 ...
- nginx、php-fpm启动脚本
Nginx官方启动脚本 //service nginx stop|start|restart|reloadtouch /etc/init.d/nginx chmod nginxvi /etc/init ...
随机推荐
- java GUI (课堂笔记)
关于java GUI Swing组件: JFrame 窗口组件 JLabel 标签 JButton 按钮组件 JTextField 单行文本框 系统控件(JDK自带) 自定义控件(模仿系统控件): 继 ...
- C#程序遍历数组A中所有元素
] { "a1","a2","a3","a4","a5"}; //第一种方法 ; i < A. ...
- 保存和恢复 Android Fragment 的状态
经过几年在 Android 应用开发中应用 Fragment 的努力之后,我必须要说尽管Fragment的概念非常优秀,但是它也同时带来了一堆问题.当我们处理实例的状态保存时就需要特别一件一件地修护好 ...
- 【原创+史上最全】Nginx+ffmpeg实现流媒体直播点播系统
#centos6.6安装搭建nginx+ffmpeg流媒体服务器 #此系统实现了视频文件的直播及缓存点播,并支持移动端播放(支持Apple和Android端) #系统需要自行安装,流媒体服务器配置完成 ...
- 有关typename
为了避免潜在的语法解析二义性,你需要在从属于形式类型参数的类型名前面使用typename,这样的类型被称为从属类型(dependent type) (摘自effective STL)
- Azure 基础:Table storage
Azure Storage 是微软 Azure 云提供的云端存储解决方案,当前支持的存储类型有 Blob.Queue.File 和 Table.其中的 Table 就是本文的主角 Azure Tabl ...
- 【Windows 10 应用开发】使用快捷访问键
UWP 虽然主要面向触控操作,但 Windows 设备是万能工具,不用手指不用笔的时候,也可能会接上键盘耍耍.因此,给应用界面上的一些元素弄个快捷访问键也挺不错的.为了使用 Windows 上的各类应 ...
- “java.lang.IllegalArgumentException: Failed to evaluate expression ‘ROLE_USER’”报错的解决
这个问题出现在Spring Security的相关配置中,找到原来的这一行: <security:intercept-url pattern="/**" access=&qu ...
- 使用 Socket.IO 开发聊天室
前言 Socket.IO 是一个用来实现实时双向通信的框架,其本质是基于 WebSocket 技术. 我们首先来聊聊 WebSocket 技术,先设想这么一个场景: · 用户小A,打开了某个网站的充值 ...
- EntityFramework连接SQLite
EF很强大,可惜对于SQLite不支持CodeFirst模式(需要提前先设计好数据库表结构),不过对SQLite的数据操作还是很好用的. 先用SQLiteManager随便创建一个数据库和一张表: