(一)、在线安装nginx依赖包
yum -y install gcczlib zlib-devel pcre-devel openssl openssl-devel |
以下为离线安装依赖包:
1.离线安装gcc
a.从CentOS7的系统安装镜像中取出需要的rpm包(也可以通过别的方式获取):解压镜像文件,进入"CentOS-7-x86_64-DVD-1708.iso\Packages"目录,里面很多rpm包,取出如下几个:
mpfr-3.1.1-4.el7.x86_64.rpm libmpc-1.0.1-3.el7.x86_64.rpm kernel-headers-3.10.0-123.el7.x86_64.rpm glibc-headers-2.17-55.el7.x86_64.rpm glibc-devel-2.17-55.el7.x86_64.rpmcpp-4.8.2-16.el7.x86_64.rpm gcc-4.8.2-16.el7.x86_64.rpm |
b.将这些包上传到待安装的系统中【可安装Xftp进行上传】,按如下顺序执行安装命令:
rpm -ivh mpfr-3.1.1-4.el7.x86_64.rpm rpm -ivh libmpc-1.0.1-3.el7.x86_64.rpm rpm -ivh kernel-headers-3.10.0-123.el7.x86_64.rpm rpm -ivh glibc-headers-2.17-55.el7.x86_64.rpm rpm -ivh glibc-devel-2.17-55.el7.x86_64.rpm rpm -ivh cpp-4.8.2-16.el7.x86_64.rpm rpm -ivh gcc-4.8.2-16.el7.x86_64.rpm |
也可以使用如下命令统一安装:
rpm -Uvh *.rpm --nodeps --force |
都安装成功后,验证
gcc -v |
2.离线安装g++编译器
a.从CentOS7的系统安装镜像中取出需要的rpm包(也可以通过别的方式获取):解压镜像文件,进入"CentOS-7-x86_64-DVD-1708.iso\Packages"目录,里面很多rpm包,取出如下几个:
autogen-libopts-5.18-5.el7.x86_64.rpm gcc-c++-4.8.5-16.el7.x86_64.rpm keyutils-libs-devel-1.5.8-3.el7.x86_64.rpm krb5-devel-1.15.1-8.el7.x86_64.rpm libcom_err-devel-1.42.9-10.el7.x86_64.rpm libsepol-devel-2.5-6.el7.x86_64.rpm libstdc++-devel-4.8.5-16.el7.x86_64.rpm libverto-devel-0.2.5-4.el7.x86_64.rpm ntp-4.2.6p5-25.el7.centos.2.x86_64.rpm ntpdate-4.2.6p5-25.el7.centos.2.x86_64.rpm openssl098e-0.9.8e-29.el7.centos.3.x86_64.rpm openssl-1.0.2k-8.el7.x86_64.rpm openssl-devel-1.0.2k-8.el7.x86_64.rpm openssl-libs-1.0.2k-8.el7.x86_64.rpm pkgconfig-0.27.1-4.el7.x86_64.rpm tcl-8.5.13-8.el7.x86_64.rpm zlib-1.2.7-17.el7.x86_64.rpm zlib-devel-1.2.7-17.el7.x86_64.rpm |
b.将这些包上传到待安装的系统中【可安装Xftp进行上传】,使用如下命令统一安装:
rpm -Uvh *.rpm --nodeps --force |
都安装成功后,验证
g++ -v |
[root@localhost g++]# g++ -v Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper Target: x86_64-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux Thread model: posix gcc version 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) |
3.离线安装PCRE库
这是一个表达式库,Nginx中的http模块则使用到了该库来解析正则表达式,所以安装它,自己选择一个路径,这里选择了/usr/local/src
执行命令:
cd /usr/local/src wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz tar -zxvf pcre-8.37.tar.gz cd pcre-8.34 ./configure make make install |
注释:
问题1:
执行make时提示“WARNING: 'aclocal-1.14' is missing on your system.”
解决方法:
# touch configure.ac aclocal.m4 configure Makefile.am Makefile.in |
4.离线安装zlib库
zlib库用于压缩和解压缩,方式众多,Nginx也使用到了zlib,所以继续安装它,路径同样/usr/local/src
执行命令:
wget http://zlib.net/zlib-1.2.11.tar.gz tar -zxvf zlib-1.2.11.tar.gz cd zlib-1.2.11 ./configure make make install |
(二)、离线安装Nginx
到目前为止,安装Nginx的环境和库就准备好了,现在安装Nginx
1、安装---执行命令:
cd /usr/local/src wget http://nginx.org/download/nginx-1.1.10.tar.gz--已经下载好了 tar -zxvf nginx-1.1.10.tar.gz cd nginx-1.1.10 ./configure make make install ==>此时安装目录下会生成几个文件夹 ==>conf Nginx运行环境配置文件 ==>html Nginx中的页面 ==>logs Nginx打印的日志 ==>sbin Nginx可执行文件,包括启动Nginx等 |
2、启动Nginx
执行Nginx安装目录下的sbin目录下的nginx,第一个参数指定nginx配置文件路径
[root@master nginx]# pwd /usr/local/nginx [root@master nginx]# ./sbin/nginx -c conf/nginx.conf |
如果没什么错误,则表示Nginx启动完成,则可以在访问IP地址:端口,例如:192.168.52.10:8090
3、重启Nginx
执行Nginx安装目录下的sbin目录下的启动程序,添加参数-s reload
实例:
./sbin/nginx -s reload |
4、停止Nginx
pkill -9 nginx # -9 |
注:强制杀死进程,pkill用于杀死一个进程,与kill不同的是它会杀死指定名字的所有进程,类似于killall命令。
(三)、在线安装nginx本次使用此种安装
1.安装:
sudo yum install yum-utils //如果有yum则不用安装 sudo vi /etc/yum.repos.d/nginx.repo // 创建该文件并添加[nginx-stable] 和 [nginx-mainline]的内容保存
[nginx-stable] name=nginx stable repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true
[nginx-mainline] name=nginx mainline repo baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/ gpgcheck=1 enabled=0 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true
// 保存好后安装nginx的stable稳定版 sudo yum install nginx |
2.启动nginx
[root@localhost ~] sudo service nginx start Redirecting to /bin/systemctl start nginx.service [root@localhost ~] netstat -ntlp | grep 80 // 没有netstat自己安装下 sudo yum install net-tools tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1589/nginx: master // nginx服务启动,并且监听在80端口 |
3.测试
在自己的电脑输入 http://ip:80, 出现以下界面则说明安装成功
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to nginx.org. Commercial support is available at nginx.com.
Thank you for using nginx. |
a.如果出现了访问失败,则需要在访问的电脑中进行如下检测
telnet 192.168.0.101 80 // 查看nginx服务器的80端口能不能访问。 |
b.如果不能访问80端,查看服务器 selinux和firewall 是否开启了
[root@localhost ~] sudo getenforce // 查看selinux是否开启 enforcing // enforecing 则未开启了 [root@localhost ~] vi /etc/selinux/config // 永久关闭selinux,打开/etc/selinux/config编辑 SELINUX = disabled // 将 SELINUX = enforcing 改为 disabled |
可以重启服务器生效。
c.给firewalld 添加 80 端口
[root@localhost ~] sudo systemctl status firewalld // 查看firewalld是否开启了 firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled) Active: active (running) since Sun 2019-12-15 23:57:33 CST; 4min 36s ago Docs: man:firewalld(1) Main PID: 824 (firewalld) Tasks: 2 (limit: 4912) Memory: 35.4M CGroup: /system.slice/firewalld.service └─824 /usr/libexec/platform-python -s /usr/sbin/firewalld --nofork --nopid
12月 15 23:57:32 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon... 12月 15 23:57:33 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon. |
出现了上面的说明firewalld已经开启了。
[root@localhost ~] sudo firewall-cmd --zone=public --add-port=80/tcp --permanent //添加80端口 success [root@localhost ~] sudo systemctl restart firewalld // 重启下firewalld |
继续测试,应该可以访问成功了。
标签:x86,Nginx,--,rpm,nginx,64,linux,安装,el7 From: https://www.cnblogs.com/dabao150114/p/17060367.html