Centos7-64bit-编译安装配置Nginx stream四层负载均衡 动态加载

2018-08-10 17:12

分享人:老牛

yum install screen -y && screen -S nginx

sudo yum -y groupinstall "Development Tools" && yum -y epel-release wget gc autoconf automake pcre-devel zlib-devel openssl-devel

----------------------yum安装nginx(默认未编译stream模块,如果需要用按下面方法编译)------------------------------

安装nginx

sudo yum install nginx -y

设置nginx开机启动

sudo systemctl enable nginx

-----------------------通过编译安装nginx(开启stream模块 动态加载方式)-----------------------------

编译安装nginx

sudo yum check-update || sudo yum update -y

yum groupinstall -y 'Development Tools'

yum install -y epel-release

yum install -y wget perl perl-devel perl-ExtUtils-Embed libxslt libxslt-devel libxml2 libxml2-devel gd gd-devel GeoIP GeoIP-devel

wget https://nginx.org/download/nginx-1.13.2.tar.gz && tar zxvf nginx-1.13.2.tar.gz

wget https://ftp.pcre.org/pub/pcre/pcre-8.40.tar.gz && tar xzvf pcre-8.40.tar.gz

wget https://www.zlib.net/zlib-1.2.11.tar.gz && tar xzvf zlib-1.2.11.tar.gz

wget https://www.openssl.org/source/openssl-1.1.0f.tar.gz && tar xzvf openssl-1.1.0f.tar.gz

rm -rf *.tar.gz

cd ~/nginx-1.13.2

cp ~/nginx-1.13.2/man/nginx.8 /usr/share/man/man8

gzip /usr/share/man/man8/nginx.8

man nginx

./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --user=nginx --group=nginx --build=CentOS --builddir=nginx-1.13.2 --with-select_module --with-poll_module --with-threads --with-file-aio --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --with-mail=dynamic --with-mail_ssl_module --with-stream=dynamic --with-stream_ssl_module --with-stream_realip_module --with-stream_geoip_module=dynamic --with-stream_ssl_preread_module --with-compat --with-pcre=../pcre-8.40 --with-pcre-jit --with-zlib=../zlib-1.2.11 --with-openssl=../openssl-1.1.0f --with-openssl-opt=no-nextprotoneg --with-debug

make

make install

ln -s /usr/lib64/nginx/modules /etc/nginx/modules

nginx -V

useradd --system --home /var/cache/nginx --shell /sbin/nologin --comment "nginx user" --user-group nginx

nginx -t

mkdir -p /var/cache/nginx && sudo nginx -t

vi /usr/lib/systemd/system/nginx.service

写入以下内容

[Unit]

Description=nginx - high performance web server

Documentation=https://nginx.org/en/docs/

After=network-online.target remote-fs.target nss-lookup.target

Wants=network-online.target

[Service]

Type=forking

PIDFile=/var/run/nginx.pid

ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf

ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf

ExecReload=/bin/kill -s HUP $MAINPID

ExecStop=/bin/kill -s TERM $MAINPID

[Install]

WantedBy=multi-user.target

启动nginx 设置开机启动nginx

systemctl start nginx.service && sudo systemctl enable nginx.service

检查nginx是否开机启动

systemctl is-enabled nginx.service

检查nginx是否正常运行

sudo systemctl status nginx.service

ps aux | grep nginx

curl -I 127.0.0.1

shutdown -r now

rm /etc/nginx/koi-utf /etc/nginx/koi-win /etc/nginx/win-utf

mkdir ~/.vim/

cp -r ~/nginx-1.13.2/contrib/vim/* ~/.vim/

rm /etc/nginx/*.default

-------------------------------nginx编译安装完毕------------------------------------------

-----------------------防火墙管理(未设置nginx 80端口可能无法访问)-----------------------------

启动防火墙

systemctl start firewalld.service

添加防火墙规则(添加80 443端口)--刚编译的 若未添加 可能无法访问

sudo firewall-cmd --permanent --zone=public --add-service=http

sudo firewall-cmd --permanent --zone=public --add-service=https

sudo firewall-cmd --reload

如需要可关闭防火墙

systemctl stop firewalld.service

关闭防火墙开机启动

systemctl disable firewalld.service

设置防火墙开机启动

systemctl enable firewalld.service

Centos7 防火墙 相关控制命令

systemctl is-enabled nginx.service #查询nginx是否开机启动

systemctl enable nginx.service #开机运行nginx

systemctl disable nginx.service #取消开机运行nginx

systemctl start nginx.service #启动nginx

systemctl stop nginx.service #停止nginx

systemctl restart nginx.service #重启nginx

systemctl reload nginx.service #重新加载nginx配置文件

systemctl status nginx.service #查询nginx运行状态

systemctl --failed #显示启动失败的服务

#查看端口监听情况

ss -tlnp|grep :80

nginx服务器默认root路径

/usr/share/nginx/html

nginx服务器默认配置文件

/etc/nginx/nginx.conf

追加配置文件路径(会自动加载.conf结尾的文件)

/etc/nginx/conf.d

---------------------------负载均衡配置------------------------------

清空nginx配置

cp /etc/nginx/nginx.conf /etc/nginx/nginx.confbackup

cat /dev/null > /etc/nginx/nginx.conf

vi /etc/nginx/nginx.conf

根据实际情况添加负载均衡配置

worker_processes 1;

load_module  "modules/ngx_stream_module.so";

events {

worker_connections  1024;

}

stream {

upstream backend {

hash $remote_addr consistent;

server 176.58.111.12:80 weight=5 max_fails=3 fail_timeout=30s;

server 178.79.163.35:80 weight=5  max_fails=3 fail_timeout=30s;

}

server {

listen 80;

proxy_connect_timeout 1s;

proxy_timeout 3s;

proxy_pass backend;

}

}

linux nginx 安装stream,Centos7-64bit-编译安装配置Nginx stream四层负载均衡 动态加载相关推荐

  1. centos7二进制安装php,Centos7下编译安装配置Nginx+PHP+MySql环境

    序言 这次玩次狠得.除了编译器使用yum安装,其他全部手动编译.哼~ 看似就Nginx.PHP.MySql三个东东,但是它们太尼玛依赖别人了. 没办法,想用它们就得老老实实给它们提供想要的东西. 首先 ...

  2. Linux下的静态库、动态库和动态加载库

    from: http://www.techug.com/linux-static-lib-dynamic-lib 库的存在极大的提高了C/C++程序的复用性,但是库对于初学者来说有些难以驾驭,本文从L ...

  3. Linux动态库的动态加载与静态加载以及加载依赖了其他动态库的动态库

    Linux动态库加载 在Linux下,动态库格式一般为libxxx.so或者libxxx.so.3这种格式. 通常我们在网上下载下来源码包,编译之后会是libxxx.so软连接libxxx.so.1链 ...

  4. CentOS7.6编译安装nginx

    配置阿里云yum源 cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak wget -O /etc/yu ...

  5. Linux随笔16-主从DNS服务搭建以及智能DNS服务搭建、基于CentOS7.6编译安装MySQL-5.7.32

    Contents 1. DNS主从服务器搭建 1.1. DNS简介 1.2. DNS主从服务搭建 1.2.1. 主DNS服务器配置 1.2.2. 从DNS服务器配置 1.2.3. Web服务器准备 1 ...

  6. centos5.6 (64bit)编译安装vsftpd-2.3.4的配置(两种用户登录)[连载之电子商务系统架构]...

    centos5.6 (64bit)编译安装vsftpd-2.3.4的配置(两种用户登录) 出处:http://jimmyli.blog.51cto.com/我站在巨人肩膀上Jimmy Li 作者:Ji ...

  7. ubuntu14.04 nginx php编译安装,Ubuntu 14.04 编译安装 Nginx

    在Ubuntu 14.04下编译安装 Nginx过程笔记. 下载源码包 nginx 地址: http://nginx.org/en/download.html 编译前先安装两个包: 直接编译安装会碰到 ...

  8. php-7.2.13的安装,Centos7.2编译安装php-7.0.13

    Centos7.2编译安装php-7.0.13 1- 安装依赖 yum install wget autoconf libjpeg libjpeg-devel libpng libpng-devel ...

  9. linux 安装源码网卡包,【linux命令】Linux通过yum 或者源码编译安装vnstat查看网卡流量...

    Linux通过vnstat查看网卡流量有两种安装方式: yum 安装或者源码编译安装. 1,yum安装. 直接运行yum install vnstat  -y 安装完后测试: [[email prot ...

最新文章

  1. 修改 jar 的一些体会
  2. Python --金字塔
  3. Linux shell类型
  4. 利用python从网页查找数据_利用Python模拟淘宝的搜索过程并对数据进行可视化分析...
  5. 高阶函数 map,reduce, filter的用法
  6. 【SwitchHosts】安装使用
  7. 华为摄像头搜索软件_ZOOM会议软件简要操作说明-安卓手机版
  8. java中的date_Java中Date类型详解
  9. java.lang.NoSuchMethodError 之 依赖冲突解决方案
  10. 表白公式计算机,【理工男表白公式大全】_理工男写“公式体”情书表白图
  11. jQuery boxy
  12. 什么是服务器的上行带宽和下行带宽
  13. 2018校招笔试真题汇总 精
  14. Web服务http日志收集
  15. csdn 修改博客皮肤
  16. UGUI优化之路- Image的Sliced优化
  17. 微信机器人服务器成本,微信机器人案例汇总
  18. 聊一聊Java如何接入招行一网通支付功能
  19. FFmpeg从入门到入魔(2):保存流到本地MP4
  20. 不小心点了计算机一键还原怎么操作,教你电脑一键还原怎么操作

热门文章

  1. php类中双冒号和-的区别
  2. [转载]用UglifyJS2合并压缩混淆JS代码——javascript系列
  3. 使用SQL Server存储ASP.NET Session变量
  4. 离婚从来不是解决家庭危机的唯一办法
  5. 沉下来,沉下来,别让自己太浮躁
  6. spring学习笔记02-spring-bean创建的细节问题
  7. 【计算机网络复习】1.1.1 概念、组成、功能和分类
  8. 用python设计学生管理系统_基于python和tkinter实现的一个简单的学生信息管理系统...
  9. python画roc曲线需要什么数据,我如何根据这些数据绘制ROC曲线?
  10. 如何实现对外部php文件的调用,laravel如何引用外部文件