开机自动启动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随机启动脚本的更多相关文章

  1. rsync随机启动脚本

    服务端 #!/bin/sh # chkconfig: # description: Saves and restores system entropy pool for \ #create by xi ...

  2. centos 随机启动脚本编写

    先说下问题背景 目前手上开发的产品是springboot微服务的,我们用jenkins来做的部署,部署脚本如下: 1.build脚本 负责从git服务器拉脚本 2.微服务脚本: #!/bin/shap ...

  3. nginx 的启动脚本

    下载路径为: wget -q http://www.dwhd.org/script/Nginx-init-CentOS 根据自己的实际环境修改相应的参数 把该脚本放到/etc/rc.d/init.d/ ...

  4. Nginx的启动脚本(Centos)

    vim /etc/init.d/nginxservice nginx start #!/bin/sh # chkconfig: 2345 85 15 # description:Nginx Serve ...

  5. nginx-(/etc/init.d/nginx)启动脚本

    #!/bin/bash #nx Startup script for the Nginx HTTP Server # it is v. version. # chkconfig: - # descri ...

  6. Nginx的启动脚本

    vi /etc/init.d/nginx #!/bin/sh # nginx        Startup script for nginx # chkconfig: - 85 15 # proces ...

  7. Nginx服务启动脚本

    #!/bin/sh # chkconfig: 2345 40 98 # description: Start/Stop Nginx server path=/application/nginx/sbi ...

  8. Nginx的编译安装及服务启动脚本

    1.解决依赖关系 编译安装nginx需要事先需要安装开发包组"Development Tools"和 "Development Libraries".同时,还需 ...

  9. nginx、php-fpm启动脚本

    Nginx官方启动脚本 //service nginx stop|start|restart|reloadtouch /etc/init.d/nginx chmod nginxvi /etc/init ...

随机推荐

  1. [HDU1020] Encoding - 加密

    Problem Description Given a string containing only 'A' - 'Z', we could encode it using the following ...

  2. 使用Eclipse进行Javaweb项目开发时,如何设置外置浏览器Chrome

    使用Eclipse开发Javaweb项目时,在Eclipse中显示页面不是很好,那么如何让它自动打开外置浏览器呢?操作如下

  3. struts2 Unable to load configuration. - bean - jar:file:struts2-core-2.2.3.jar!/struts-default.xml:29:72

    今天启动tomcat的时候发现如下错误记录一下! 从stackoverflow上找到 原因是加入了多个struts2包 删除相同的包即可!!

  4. python基础操作_集合_三元运算

    #使用操作文件的时候,可以使用with函数#with open('E:\info.txt','a+') as fr#fr这个值可以是任意值# :#for line in fr:'''with open ...

  5. awk内引用shell变量【自己手动加精】

    题目 [root@localhost ~]# cat 1.txt iii sss ddd 执行命令 [root@localhost ~]# A=0 [root@localhost ~]# awk '{ ...

  6. oracle日期时间函数 总结

    表中存在伪列:sysdate,systimestamp 伪列存在但是不显示 select sysdate from dual; select systimestamp from dual; 日期计算公 ...

  7. android6.0搜索蓝牙无法显示问题解决

    1.android6.0版本搜索蓝牙需要开启位置信息 需在Manifest中添加权限: <uses-permission android:name="android.permissio ...

  8. jQuery 提供多个与 AJAX 有关的方法。

    jQuery 提供多个与 AJAX 有关的方法. 通过 jQuery AJAX 方法,您能够使用 HTTP Get 和 HTTP Post 从远程服务器上请求文本.HTML.XML 或 JSON - ...

  9. vs2015添加ActiveX Control Test Container工具(转载)

    http://blog.csdn.net/lphbtm/article/details/8647565 vs2010 中添加 ActiveX Control Test Container工具(转载) ...

  10. vue-router单页应用简单示例(二)

    我们先来理一下思路. 图1:main.js 引入vue,App.vue,router/index.js文件 声明要渲染的Id为app,将App.vue中的模版渲染到入口界面(就是打开localhost ...