确定关闭并且关闭开启自启:selinux、firewalld
service iptables status chkconfig iptables off
vim /etc/selinux/config
====================
安装 依赖包
yum deplist nginx ##检查依赖
yum -y install libmysqlclient* bison* bzip2* glibc* libaio* libcurl* libjpeg* freetype* libpng* libtool* libxml2*
yum -y install ncurses* openssl* openldap* pcre* perl gcc gcc-c++ autoconf automake make cmake
yum -y install vixie-cron crontabs expect lrzsz vim ntpdate screen iftop rsync bind-utils sysstat gdb
==============================================
卸载预安装的httpd:
yum -y erase httpd
添加www用户
grep -q "^www" /etc/passwd || useradd -M -s /sbin/nologin www && groups www
解压安装包:
官网下载安装包1.62和补丁包2.2
mkdir /data/tmp/install && tar -xzvf nginx /data/tmp/install && cd /data/tmp/install/nginx-1.6.2
编译安装:
##auto/cc/gcc 设置编译器,把CFLAGS="$CFLAGS -g"替换成CFLAGS="$CFLAGS " 并进行编译
sed -i 's#CFLAGS="$CFLAGS -g"#CFLAGS="$CFLAGS "#' auto/cc/gcc && \
CHOST="x86_64-pc-linux-gnu" CFLAGS="-O3" CXX=gcc CXXFLAGS="-O3 -felide-constructors -fno-exceptions -fno-rtti" && \
./configure --user=www --group=www --prefix=/data/opt/nginx --with-http_stub_status_module --with-google_perftools_module --with-pcre --with-http_ssl_module --with-http_dav_module --add-module=nginx-upload-module-2.2 && make -j 4 && make install
##依赖包:yum install gcc gcc-c++ make automake autoconf libtool pcre* zlib openssl openssl-devel
##问题1:报错 ./configure: error: C compiler cc is not found
解决:yum -y install gcc gcc-c++ autoconf automake make
##问题2:报错 ./configure: error: no nginx-upload-module-2.2/config was found
解决:wget http://www.grid.net.ru/nginx/download/nginx_upload_module-2.0.11.tar.gz && tar -xzvf nginx_upload_module-2.0.11.tar.gz && rm -f nginx_upload_module-2.0.11.tar.gz
##问题3:报错 checking for PCRE library ... not found
解决:yum -y install pcre-devel
##问题4:报错 checking for OpenSSL library ... not found
解决:yum -y install openssl openssl-devel
##问题5:报错 Google perftools ... not found / the Google perftool module requires the Google perftools
解决:
wget http://mirror.yongbok.net/nongnu/libunwind/libunwind-1.1.tar.gz
wget https://github.com/gperftools/gperftools/releases/download/gperftools-2.5/gperftools-2.5.tar.gz
1、安装 libunwind cd 到libunwind目录 ./configure (默认安装路径/usr/local/lib)&& make && make install
2、安装google-perfile CFLAGS=-fPIC && ./configure --prefix=/usr/local &&make clean && make CFLAGS=-fPIC && make CFLAGS=-fPIC install
&& echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf && ldconfig
安装完nginx之后可以使用这条命令进行测试 lsof -n | grep nginx #测试nginx
再重新安装nginx
==================================================
拷贝nginx配置文件并进行配置
##除非文件不存在,否则(存在就)拷贝进行备份
[ ! -f /data/opt/nginx/conf/nginx.conf ] || \cp -f /data/opt/nginx/conf/nginx.conf /data/opt/nginx/conf/nginx.conf.20200701
[ ! -f /data/opt/nginx/conf/fastcgi.conf ] || \cp -f /data/opt/nginx/conf/fastcgi.conf /data/opt/nginx/conf/fastcgi.conf.20200701
[ ! -f /etc/init.d/nginx ] || \cp -f /etc/init.d/nginx /etc/init.d/nginx.20200701
##下载nginx文件到/root/nginx/,拷贝事这些先配置好的nginx文件到nginx安装目录,并修改 nginxdir 目录为 /data/opt/nginx
\cp -f /root/nginx/nginx.conf /data/opt/nginx/conf/nginx.conf && \
\cp -f /root/nginx/fastcgi.conf /data/opt/nginx/conf/fastcgi.conf && \
\cp -f /root/nginx/nginx.init /etc/init.d/nginx && \
sed -i 's#@nginxdir@#'/data/opt/nginx'#' /data/opt/nginx/conf/nginx.conf && \
sed -i 's#@nginxdir@#'/data/opt/nginx'#' /etc/init.d/nginx && \
chmod +x /etc/init.d/nginx && mkdir -p /data/opt/nginx/run && mkdir -p /data/opt/nginx/conf/vhost
=========================================
启动 nginx
chmod +x /etc/init.d/nginx && service nginx start && chkconfig --level 345 nginx on