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隨機啟動腳本