Linux中redhat6.9安装Nginx操作流程

Linux中redhat6.9安装Nginx操作流程

版本: Red Hat Enterprise Linux Server release 6.9 (Santiago)
环境:内网

Nginx下载地址

 解压Nginx:
 cd /usr/local/src/
 tar -zxvf   nginx-1.18.0.tar.gz
 cd nginx-1.18.0
 执行 ./configure 显示如下图(出现下图的原因是缺少依赖库)

在这里插入图片描述

下载对应的依赖库(安装目录:/usr/local/src/):
1. pcre-8.40下载:
https://netix.dl.sourceforge.net/project/pcre/pcre/8.40/pcre-8.40.tar.gz
安装: tar -zxvf pcre-8.40.tar.gz
	  cd  pcre-8.40
	  ./configure
	  make
	  make install 
2. zlib-1.2.11下载:
http://zlib.net/zlib-1.2.11.tar.gz
安装:tar -zxvf zlib-1.2.11
	  cd  zlib-1.2.11
	  ./configure
	  make
	  make install 
继续安装Nginx:
[root@localhost src]# cd nginx-1.18.0/
[root@localhost nginx-1.18.0]# ./configure
checking for OS
 + Linux 2.6.32-696.el6.x86_64 x86_64
checking for C compiler ... found
 + using GNU C compiler
 + gcc version: 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC) 
checking for gcc -pipe switch ... found
checking for -Wl,-E switch ... found
checking for gcc builtin atomic operations ... found
checking for C99 variadic macros ... found
checking for gcc variadic macros ... found
checking for gcc builtin 64 bit byteswap ... found
checking for unistd.h ... found
checking for inttypes.h ... found
checking for limits.h ... found
checking for sys/filio.h ... not found
checking for sys/param.h ... found
checking for sys/mount.h ... found
checking for sys/statvfs.h ... found
checking for crypt.h ... found
checking for Linux specific features
checking for epoll ... found
checking for EPOLLRDHUP ... found
checking for EPOLLEXCLUSIVE ... not found
checking for O_PATH ... not found
checking for sendfile() ... found
checking for sendfile64() ... found
checking for sys/prctl.h ... found
checking for prctl(PR_SET_DUMPABLE) ... found
checking for prctl(PR_SET_KEEPCAPS) ... found
checking for capabilities ... found
checking for crypt_r() ... found
checking for sys/vfs.h ... found
checking for nobody group ... found
checking for poll() ... found
checking for /dev/poll ... not found
checking for kqueue ... not found
checking for crypt() ... not found
checking for crypt() in libcrypt ... found
checking for F_READAHEAD ... not found
checking for posix_fadvise() ... found
checking for O_DIRECT ... found
checking for F_NOCACHE ... not found
checking for directio() ... not found
checking for statfs() ... found
checking for statvfs() ... found
checking for dlopen() ... not found
checking for dlopen() in libdl ... found
checking for sched_yield() ... found
checking for sched_setaffinity() ... found
checking for SO_SETFIB ... not found
checking for SO_REUSEPORT ... found
checking for SO_ACCEPTFILTER ... not found
checking for SO_BINDANY ... not found
checking for IP_TRANSPARENT ... found
checking for IP_BINDANY ... not found
checking for IP_BIND_ADDRESS_NO_PORT ... not found
checking for IP_RECVDSTADDR ... not found
checking for IP_SENDSRCADDR ... not found
checking for IP_PKTINFO ... found
checking for IPV6_RECVPKTINFO ... found
checking for TCP_DEFER_ACCEPT ... found
checking for TCP_KEEPIDLE ... found
checking for TCP_FASTOPEN ... not found
checking for TCP_INFO ... found
checking for accept4() ... found
checking for eventfd() ... found
checking for int size ... 4 bytes
checking for long size ... 8 bytes
checking for long long size ... 8 bytes
checking for void * size ... 8 bytes
checking for uint32_t ... found
checking for uint64_t ... found
checking for sig_atomic_t ... found
checking for sig_atomic_t size ... 4 bytes
checking for socklen_t ... found
checking for in_addr_t ... found
checking for in_port_t ... found
checking for rlim_t ... found
checking for uintptr_t ... uintptr_t found
checking for system byte ordering ... little endian
checking for size_t size ... 8 bytes
checking for off_t size ... 8 bytes
checking for time_t size ... 8 bytes
checking for AF_INET6 ... found
checking for setproctitle() ... not found
checking for pread() ... found
checking for pwrite() ... found
checking for pwritev() ... found
checking for sys_nerr ... found
checking for localtime_r() ... found
checking for clock_gettime(CLOCK_MONOTONIC) ... not found
checking for clock_gettime(CLOCK_MONOTONIC) in librt ... found
checking for posix_memalign() ... found
checking for memalign() ... found
checking for mmap(MAP_ANON|MAP_SHARED) ... found
checking for mmap("/dev/zero", MAP_SHARED) ... found
checking for System V shared memory ... found
checking for POSIX semaphores ... not found
checking for POSIX semaphores in libpthread ... found
checking for struct msghdr.msg_control ... found
checking for ioctl(FIONBIO) ... found
checking for ioctl(FIONREAD) ... found
checking for struct tm.tm_gmtoff ... found
checking for struct dirent.d_namlen ... not found
checking for struct dirent.d_type ... found
checking for sysconf(_SC_NPROCESSORS_ONLN) ... found
checking for sysconf(_SC_LEVEL1_DCACHE_LINESIZE) ... found
checking for openat(), fstatat() ... found
checking for getaddrinfo() ... found
checking for PCRE library ... found
checking for PCRE JIT support ... found
checking for zlib library ... found
creating objs/Makefile

Configuration summary
  + using system PCRE library
  + OpenSSL library is not used
  + using system zlib library

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

[root@localhost nginx-1.18.0]# make
make -f objs/Makefile
make[1]: Entering directory `/usr/local/src/nginx-1.18.0'
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-u
.................省略
[root@localhost nginx-1.18.0]# make install
make -f objs/Makefile install
make[1]: Entering directory `/usr/local/src/nginx-1.18.0'
test -d '/usr/local/nginx' || mkdir -p '/usr/local/nginx'
.................省略
[root@localhost nginx-1.18.0]# cd /usr/local/nginx/
conf/ html/ logs/ sbin/ 
[root@localhost nginx-1.18.0]# cd /usr/local/nginx/
conf/ html/ logs/ sbin/ 
# 配置nginx配置
[root@localhost nginx-1.18.0]# vi /usr/local/nginx/conf/nginx.conf

启动nginx:
[root@localhost nginx-1.18.0]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
启动Nginx报错如下(原因:nginx已经启动)
[root@localhost nginx-1.18.0]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()

解决以上错误:
1. 查看nginx启动进程:ps -ef |grep nginx
2. 杀掉进程: kill -9 345797
操作如下:
[root@localhost nginx-1.18.0]# ps -ef |grep nginx
nobody   345798      1  0 16:18 ?        00:00:00 nginx: worker process                                          
root     371104 200204  0 16:36 pts/4    00:00:00 grep nginx
[root@localhost nginx-1.18.0]# kill -9 345798
[root@localhost nginx-1.18.0]# ps -ef |grep nginx
root     371855 200204  0 16:37 pts/4    00:00:00 grep nginx
[root@localhost nginx-1.18.0]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
安装nginx时缺少依赖包

查看是否安装相关依赖: yum list installed | grep “依赖名称”
在安装nginx前首先要确认系统中安装了gcc、pcre-devel、zlib-devel、openssl-devel
例如: yum list installed | grep “gcc”

访问nginx

在这里插入图片描述

使用service nginx restart来启动Nginx
安装Nginx以后使用service nginx restart启动报错:
nginx: 未被识别的服务
解决(将nginx加为系统服务):
创建文件:vi /etc/init.d/nginx
写入下方内容:
#! /bin/sh
# chkconfig: 2345 55 25
# Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and
# run 'update-rc.d -f nginx defaults', or use the appropriate command on your
# distro. For CentOS/Redhat run: 'chkconfig --add nginx'

### BEGIN INIT INFO
# Provides:          nginx
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the nginx web server
# Description:       starts nginx using start-stop-daemon
### END INIT INFO

# Author:   licess
# website:  http://lnmp.org

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=nginx
NGINX_BIN=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/$NAME.conf
PIDFILE=/usr/local/nginx/logs/$NAME.pid

case "$1" in
    start)
        echo -n "Starting $NAME... "

        if netstat -tnpl | grep -q nginx;then
            echo "$NAME (pid `pidof $NAME`) already running."
            exit 1
        fi

        $NGINX_BIN -c $CONFIGFILE

        if [ "$?" != 0 ] ; then
            echo " failed"
            exit 1
        else
            echo " done"
        fi
        ;;

    stop)
        echo -n "Stoping $NAME... "

        if ! netstat -tnpl | grep -q nginx; then
            echo "$NAME is not running."
            exit 1
        fi

        $NGINX_BIN -s stop

        if [ "$?" != 0 ] ; then
            echo " failed. Use force-quit"
            exit 1
        else
            echo " done"
        fi
        ;;

    status)
        if netstat -tnpl | grep -q nginx; then
            PID=`pidof nginx`
            echo "$NAME (pid $PID) is running..."
        else
            echo "$NAME is stopped"
            exit 0
        fi
        ;;

    force-quit)
        echo -n "Terminating $NAME... "

        if ! netstat -tnpl | grep -q nginx; then
            echo "$NAME is not running."
            exit 1
        fi

        kill `pidof $NAME`

        if [ "$?" != 0 ] ; then
            echo " failed"
            exit 1
        else
            echo " done"
        fi
        ;;

    restart)
        $0 stop
        sleep 1
        $0 start
        ;;

    reload)
        echo -n "Reload service $NAME... "

        if netstat -tnpl | grep -q nginx; then
            $NGINX_BIN -s reload
            echo " done"
        else
            echo "$NAME is not running, can't reload."
            exit 1
        fi
        ;;

    configtest)
        echo -n "Test $NAME configure files... "

        $NGINX_BIN -t
        ;;

    *)
        echo "Usage: $0 {start|stop|force-quit|restart|reload|status|configtest}"
        exit 1
        ;;

esac

保存并退出!

[root@localhost src]# service nginx stop
Stoping nginx...  done
[root@localhost src]# service nginx start
Starting nginx...  done
[root@localhost src]# service nginx reload
Reload service nginx...  done
[root@localhost src]# 

运行报错libpcre.so.1

[root@localhost src]# service nginx start
Starting nginx... /usr/local/nginx/sbin/nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory
 failed
 
# 查找libpcre.so.1
[root@localhost pcre-8.40]# find / -name libpcre.so.1
/usr/local/src/pcre-8.40/.libs/libpcre.so.1
/usr/local/lib/libpcre.so.1

# 查看软连接
[root@localhost lib64]# ldd $(which /usr/local/nginx/sbin/nginx) 
        linux-vdso.so.1 =>  (0x00007ffc2f3f6000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00000039c8400000)
        librt.so.1 => /lib64/librt.so.1 (0x00000039c9000000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00000039c8c00000)
        libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00000039d3800000)
        libpcre.so.1 => not found
        libz.so.1 => /lib64/libz.so.1 (0x00000039c9400000)
        libc.so.6 => /lib64/libc.so.6 (0x00000039c8800000)
        /lib64/ld-linux-x86-64.so.2 (0x00000039c8000000)
        libfreebl3.so => /lib64/libfreebl3.so (0x00000039d2c00000)
       
 # 查询软连接
[root@localhost nginx]# cd /lib64/
[root@localhost lib64]# ll libpcre*
lrwxrwxrwx. 1 root root     16 12月 31 10:50 libpcre.so.0 -> libpcre.so.0.0.1
-rwxr-xr-x. 1 root root 185464 2月  27 2015 libpcre.so.0.0.1
# 创建软连接
[root@localhost lib64]# ln -s /lib64/libpcre.so.0.0.1  libpcre.so.1
# 再次查看
[root@localhost lib64]# ldd $(which /usr/local/nginx/sbin/nginx) 
        linux-vdso.so.1 =>  (0x00007ffd14fa7000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00000039c8400000)
        librt.so.1 => /lib64/librt.so.1 (0x00000039c9000000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00000039c8c00000)
        libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00000039d3800000)
        libpcre.so.1 => /lib64/libpcre.so.1 (0x00000039d9800000)
        libz.so.1 => /lib64/libz.so.1 (0x00000039c9400000)
        libc.so.6 => /lib64/libc.so.6 (0x00000039c8800000)
        /lib64/ld-linux-x86-64.so.2 (0x00000039c8000000)
        libfreebl3.so => /lib64/libfreebl3.so (0x00000039d2c00000)
# 启动nginx
[root@localhost lib64]# service nginx start
正在启动 nginx:                                           [确定]

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值