1 nvm介绍

  • NVM(Node version manager)顾名思义,就是Node.js的版本管理软件,可以轻松的在Node.js各个版本间切换,项目源码在GitHub;
#安装git客户端
[root@node-v1 ~]# yum install git-core -y
[root@node-v1 ~]# cd /usr/local/src/
[root@node-v1 src]# git clone https://github.com/cnpm/nvm.git
[root@node-v1 src]# cd nvm/
[root@node-v1 nvm]# ./install.sh
[root@node-v1 nvm]# source nvm.sh
[root@node-v1 nvm]# nvm install 8
######################################################################## 100.0%
WARNING: checksums are currently disabled for node.js v4.0 and later
Now using node v8.9.4 (npm v5.6.0)
[root@node-v1 bin]# echo "export PATH=/usr/local/src/nvm/versions/node/v8.9.4/bin:$PATH" >> /etc/profile 
[root@node-v2 .nvm]# cat >>/etc/profile<<EOF
> export NVM_DIR="/usr/local/src/nvm"
> [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
> EOF
  • 使用方法
  1. 列出所有可安装的版本nvm list-remote;  
  2. 安装相应的版本使用nvm install 8;还可以直接安装 各个版本;
  3. 查看一下你当前已经安装的版本:nvm ls;
  4. 切换版本;nvm use v0.12.4;
  5. 设置默认版本 nvm alias default v0.12.4
  6. 注意:具体操作很简单,使用帮助通过nvm help;

1.1 编写hello.js试验

[root@node-v1 ~]# cat hello.js
var http = require('http'); var server = http.createServer(function(req, res) {
res.writeHead(200, {'Content-Type' : 'text/html'});
res.write('<head><meta charset="utf-8"/></head>');
res.end("Hello world node-v1");
}); server.listen(3000, '10.0.0.7');

  • node-v2也是如此

1.2 安装forever让node永久运行

[root@node-v1 ~]# npm install forever -g
[root@node-v1 ~]# forever start hello.js
[root@node-v1 ~]# forever stop hello.js

2 安装Haproxy

[root@haproxy ~]# yum install -y haproxy
[root@haproxy ~]# cp /etc/haproxy/haproxy.cfg{,.bak} 

2.1 Haproxy开启日志记录

[root@haproxy ~]# mkdir /var/log/haproxy
[root@haproxy ~]# chmod a+w /var/log/haproxy
[root@haproxy ~]# egrep -v "#|^$" /etc/rsyslog.conf
$ModLoad imudp
$UDPServerRun 514
$WorkDirectory /var/lib/rsyslog
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
$IncludeConfig /etc/rsyslog.d/*.conf
$OmitLocalLogging on
$IMJournalStateFile imjournal.state
*.info;mail.none;authpriv.none;cron.none /var/log/messages
authpriv.* /var/log/secure
mail.* -/var/log/maillog
cron.* /var/log/cron
*.emerg :omusrmsg:*
uucp,news.crit /var/log/spooler
local7.* /var/log/boot.log

2.2 修改“/etc/sysconfig/rsyslog”文件,内容如下  

[root@haproxy ~]# cat /etc/sysconfig/rsyslog
# Options for rsyslogd
# Syslogd options are deprecated since rsyslog v3.
# If you want to use them, switch to compatibility mode 2 by "-c 2"
# See rsyslogd(8) for more details
SYSLOGD_OPTIONS="-r -m 0 -c 2"

2.3 修改Haproxy的配置文件如下:

[root@haproxy ~]# cat /etc/haproxy/haproxy.cfg
global
log 127.0.0.1 local0 info #定义全局syslog服务,127.0.0.1表示将日志发送到本地保存
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 25600 #最大连接数
user haproxy #用户名
group haproxy #组
daemon #以守护进程方式运行
stats socket /var/lib/haproxy/stats # turn on stats unix socket defaults #为frontend和backend提供默认参数
mode http #模式
log global #日志
option httplog #详细记录http日志
option dontlognull #不记录健康检查的日志信息
retries 3 #3次连接失败则认为服务不可用
option redispatch #ServerID对应的服务器宕机后,强制定向到其他运行正常的服务器
maxconn 30000 #默认的最大连接数
contimeout 5000 #连接超时
clitimeout 5000 #客户端超时
srvtimeout 5000 #服务器超时
timeout check 1s #心跳检测超时
timeout http-request 10s #默认http请求超时时间
timeout queue 1m #默认队列超时时间
timeout connect 10s #默认连接超时时间
timeout client 1m #默认客户端超时时间
timeout server 1m #默认服务器超时时间
timeout http-keep-alive 10s #默认持久连接超时时间 listen stats
mode http
bind 0.0.0.0:8090 #指定IP地址与Port
stats enable #开启Haproxy统计状态
stats refresh 3s #统计页面自动刷新时间间隔
stats hide-version #状态页面不显示版本号
stats uri /haproxyadmin?stats #统计页面的uri为"/haproxyadmin?stats"
stats realm Haproxy\ Statistics #统计页面认证时提示内容信息
stats auth admin:admin #统计页面的用户名与密码
stats admin if TRUE #启用或禁用状态页面 frontend node #定义前端服务器
bind *:80
mode http
option httpclose #每次请求完成主动关闭http连接
option forwardfor #后端服务器获取客户端的IP地址,可以从http header中获取
acl url_static path_end -i .html .jpg .gif #定义ACL规则以如".html"结尾的文件;-i:忽略大小写
acl url_dynamic path_end -i .php
default_backend node-web #客户端访问时默认调用后端服务器地址池
backend node-web #定义后端服务器
balance roundrobin #定义算法;基于权重进行轮询
server node1 10.0.0.7:3000 check rise 2 fall 1 weight 2
server node2 10.0.0.8:3000 check rise 2 fall 1 weight 2
  • 访问

  

3 配置 Haproxy+ssl

3.1 Haproxy配置http跳转https

[root@haproxy_v1 haproxy]# cat haproxy.cfg
global
log 127.0.0.1 local0 info #定义全局syslog服务,127.0.0.1表示将日志发送到本地保存
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 25600 #最大连接数
user haproxy #用户名
group haproxy #组
daemon #以守护进程方式运行
tune.ssl.default-dh-param 2048
stats socket /var/lib/haproxy/stats # turn on stats unix socket defaults #为frontend和backend提供默认参数
mode http #模式
log global #日志
option httplog #详细记录http日志
option dontlognull #不记录健康检查的日志信息
retries 3 #3次连接失败则认为服务不可用
option redispatch #ServerID对应的服务器宕机后,强制定向到其他运行正常的服务器
maxconn 30000 #默认的最大连接数
#contimeout 5000 #连接超时
#clitimeout 5000 #客户端超时
#srvtimeout 5000 #服务器超时
timeout check 1s #心跳检测超时
timeout http-request 10s #默认http请求超时时间
timeout queue 1m #默认队列超时时间
timeout connect 10s #默认连接超时时间
timeout client 1m #默认客户端超时时间
timeout server 1m #默认服务器超时时间
timeout http-keep-alive 10s #默认持久连接超时时间 listen stats
mode http
bind 0.0.0.0:8090 #指定IP地址与Port
stats enable #开启Haproxy统计状态
stats refresh 3s #统计页面自动刷新时间间隔
stats hide-version #状态页面不显示版本号
stats uri /haproxyadmin?stats #统计页面的uri为"/haproxyadmin?stats"
stats realm Haproxy\ Statistics #统计页面认证时提示内容信息
stats auth admin:admin #统计页面的用户名与密码
stats admin if TRUE #启用或禁用状态页面 frontend node #定义前端服务器
bind *:80
acl is_http hdr_beg(host) 10.0.0.60
redirect scheme https if ! { ssl_fc }
bind *:443 ssl crt /etc/haproxy/xiao.pem
use_backend node-web if is_http backend node-web #定义后端服务器
balance roundrobin #定义算法;基于权重进行轮询
server node1 10.0.0.7:3000 check rise 2 fall 1 weight 2
server node2 10.0.0.8:3000 check rise 2 fall 1 weight 2
  • 证书的处理,需要将网站的根证书和key简单的合并在一起: 

[root@haproxy_v1 haproxy]# pwd
/etc/haproxy
[root@haproxy_v1 haproxy]# ll
total 16
-rw-r--r-- 1 root root 3165 Jan 6 00:00 haproxy.cfg
-rw-r--r-- 1 root root 3142 Jan 5 00:11 haproxy.cfg.bak
-rw-r--r-- 1 root root 1675 Jan 17 2018 privatekey.pem
-rw-r--r-- 1 root root 1184 Jan 17 2018 server.pem
[root@haproxy_v1 haproxy]# cat server.pem privatekey.pem |tee xiao.pem

 访问10.0.0.60跳转到https://10.0.0.60

Haproxy+ssl+nvm+forever的更多相关文章

  1. Haproxy ssl 配置方式

    通过haproxy redirect请求重定向的方法实现HTTP跳转HTTPS 配置实现http跳转到https,采用redirect重定向的做法,只需在frontend端添加: frontend h ...

  2. haproxy ssl相关配置

    ssl-default-bind-options [<option>]... This setting is only available when support for OpenSSL ...

  3. haproxy反向代理环境部署(http和https代理)

    操作背景:前方有一台haproxy代理机器(115.100.120.57/192.168.1.7),后方两台realserver机器(192.168.1.150.192.168.1.151,没有公网i ...

  4. 负载均衡服务之HAProxy https配置、四层负载均衡以及访问控制

    前文我们聊了下haproxy的访问控制ACL的配置,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/12817773.html:今天我们来聊一聊haproxy的h ...

  5. haproxy 2.2代理后端https服务

    globalmaxconn 100000chroot /usr/local/haproxystats socket /var/lib/haproxy/haproxy.sock mode 600 lev ...

  6. HAProxy配置SSL

    前沿 据悉苹果强制APP在2016年底使用ATS协议,所以公司准备将部分站点http统一替换成https.所有我们就得测试下 1.首先原有的haproxy1.5升级到了1.7版本支持ssl 2.查看相 ...

  7. 配置Nginx支持SSL SNI(一个IP绑定多个证书) 以及Haproxy实现多域名证书

    概述 传统的每个SSL证书签发,每个证书都需要独立ip,假如你编译openssl和nginx时候开启TLS SNI (Server Name Identification) 支持,这样你可以安装多个S ...

  8. haproxy 关闭ssl 3.0 加密

    global log 127.0.0.1 local3 maxconn 65535 chroot /usr/local/haproxy uid 500 gid 500 daemon ssl-defau ...

  9. haproxy配置基于ssl证书的https负载均衡

    本实验全部在haproxy1.5.19版本进行测试通过,经过测试1.7.X及haproxy1.3版本以下haproxy配置参数可能不适用,需要注意版本号. 一.业务要求现在根据业务的实际需要,有以下几 ...

随机推荐

  1. js中的attributes和Attribute的用法和区别。

    一:Attribute的几种用法和含义(attributes和Attribute都是用来操作属性的) getAttribute:获取某一个属性的值: setAttribute:建立一个属性,并同时给属 ...

  2. 爬取拉勾网python工程师的岗位信息并生成csv文件

    转载自:https://www.cnblogs.com/sui776265233/p/11146969.html 代码写得很好,但是目前只看得懂前一部分 一.爬取和分析相关依赖包 Python版本: ...

  3. Python 2 将死,你准备好了吗?

    Python 软件基金会宣布,到 2020 年元旦,将不再为编程语言 Python 2.x 分支提供任何支持.这一天将标志着一出延续多年的戏剧的高潮:Python 从较旧的.功能较弱的.广泛使用的版本 ...

  4. luoguP1079 Vigenère 密码 题解(NOIP2012)

    P1079 Vigenère 密码 题目 #include<iostream> #include<cstdlib> #include<cstdio> #includ ...

  5. 二维码相关---java生成二维码名片,而且自己主动保存到手机通讯录中...

    版权声明:本文为博主原创文章,未经博主credreamer 同意不得转载 违者追究法律责任. https://blog.csdn.net/lidew521/article/details/244418 ...

  6. python 图像的离散傅立叶变换

    图像(MxN)的二维离散傅立叶变换可以将图像由空间域变换到频域中去,空间域中用x,y来表示空间坐标,频域由u,v来表示频率,二维离散傅立叶变换的公式如下: 在python中,numpy库的fft模块有 ...

  7. ubuntu16.04安装docker11.09

    1.    安装Docker 操作系统 ubuntu16.04 1.1.   配置源文件 $sudo apt-get update #允许 apt 命令 HTTPS 访问 Docker 源 $sudo ...

  8. Golang 读书

    var a map[string] int  类似Key\Value var( 多个变量,避免多次声明var ) 声明变量 多重赋值 i,j=j,i 匿名变量 _ literal 字面常量   con ...

  9. Ubuntu18.04安装Tensorflow1.14GPU

    软件要求 必须在系统中安装以下 NVIDIA® 软件: https://www.pytorials.com/how-to-install-tensorflow-gpu-with-cuda-10-0-f ...

  10. 四、IDS4建立Authorization server和Client

    一.准备 创建一个名为QuickstartIdentityServer的ASP.NET Core Web 空项目(asp.net core 2.2),端口5000创建一个名为Api的ASP.NET C ...