1、cd nginx-1.10.1
2、cd ~/src/core/
3、vim nginx.hdefine NGINX_VER “nginx/” #为了安全,不显示版本号
4、cd -
5、cd auto/cc
vim gccdebug
CFLAGS=”$CFLAGS -g” #关闭DEBUG,减少内存
6、yum install pcre-devel openssl-devel zlib-devel -y
7、./configure –prefix=/usr/local/nginx –with-http_ssl_module –with-http_stub_status_module #需要的模块自定义
8、make
9、make install
10、cd /usr/local/nginx/sbin/
11、./nginx
1、cd /usr/local/nginx/conf
2、ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ #设置链接方便启动
3、useradd -u 800 nginx #设置一个nginx用户,方便配置
4、vim nginx.conf
user
nginx; # 设置用户身份,
worker_processes
1; # 允许同时开启几个nginx进程,
# worker_cpu_affinity 0001 0010 0100 1000 #绑定进程与cpu内核,不会随意切换
# error_log logs/error.log;
# error_log logs/error.log notice;
# error_log logs/error.log info;
# pid logs/nginx.pid;
events
{
worker_connections
65535;
# 允许客户端的最大并发量
}
http
{
upstream
xinhao
{ # 轮询策略
server
172.25
.34
.2:80;
# 轮询权重,访问几次
server
172.25
.34
.3:8080;
# 下线,backup-备份机
}
include
mime.types;
default_type
application / octet - stream;
# log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
# access_log logs/access.log main;
sendfile
on;
tcp_nopush
on;
tcp_nodelay
on;
# 降低网络延迟
# keepalive_timeout 0;
keepalive_timeout
65;
gzip
on;
# 允许上传
server
{
listen
80;
server_name
localhost;
# charset koi8-r;
# access_log logs/host.access.log main;
location / {
root
html;
index
index.html
index.htm;
}
location / status
{ # 监控模块,
stub_status
on;
access_log
off;
allow
172.25
.34
.250;
允许
deny
all;
# 拒绝其他
}
# error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page
500
502
503
504 / 50
x.html;
location = / 50
x.html
{
root
html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
# location ~ \.php$ {
# proxy_pass http://127.0.0.1;
# }
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
# location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
# }
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
# location ~ /\.ht {
# deny all;
# }
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
# server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
# }
# HTTPS server
#
server
{ # 添加https加密服务,建议打开
listen
443
ssl;
server_name
localhost;
ssl_certificate
cert.pem;
ssl_certificate_key
cert.pem;
# 证书
ssl_session_cache
shared:SSL:1
m;
ssl_session_timeout
5
m;
ssl_ciphers
HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers
on;
location / {
root
html;
index
index.html
index.htm;
}
}
server
{ # 添加多个虚拟服务1
listen
80;
server_name
www.xinhao.com;
location / { # 匹配url,这里设置了轮询
# root /www1;
# index index.html;
proxy_pass
http: // xinhao;
# 增加轮询策略
}
}
server
{ # 添加多个虚拟服务2
listen
80;
server_name
bbs.xinhao.com;
rewrite ^ (. *)$ https: // {HTTP_HOST}$1
permanent;
# 重定向,永久,临时=redirect
location / {
root / www2;
index
index.html;
}
}
}
5、vim /etc/security/limist.conf #登陆身份,及允许并发量
nginx - nofile 65535
6、cd /etc/pki/tls/certs #制作证书
7、make cert.pem
8、mv cert.pem /usr/local/nginx/conf/
9、cd /usr/local/nginx/sbin/
10、./nginx
11、nginx -s reload #重新加载服务
12、mkdir /www1
13、mkdir /www2
14、vim /www1/index.html
15、vim /www2/index.html
测试:
1、tar -zxf nginx-sticky-module-ng.tar.gz
2、cd nginx-1.10.1
3、make clean #清除缓存
4、./configure –prefix=/usr/local/nginx –with-http_ssl_module –with-http_stub_status_module –add-module=/mnt/nginx-sticky-module-ng #nginx时静态的,所以再添加模块时,需要把之前添加的都添加一遍,在最后指定需要添加的模块路径
5\make & make install
6、vim /usr/local/nginx/conf/nginx.conf
upstream xinhao {#轮询策略
#sticky;#基于cookie的负载均衡解决方案,在一定条件下保证同一客户访问同一后台服务器
#ip_hash; #添加hash算法 ,来源为同一个IP时,只访问第一次访问到的服务器,不支持backup
server 172.25.34.2:80;#轮询权重,访问几次
server 172.25.34.3:8080;#下线,backup-备份机
}7、nginx -s reload
准备工作:server1,server4为负载均衡器,是集群节点,server2,server3为后端服务器,server5为集群管理
yum install ricci -y #安装管理工具
passwd ricci
chkconfig ricci on
/etc/init.d/ricci start
yum install luci -y #安装管理工具,改工具可以单独安装在一台服务器
chkconfig luci on
/etc/init.d/luci start
复制server1上安装的nginx服务到本机并作相关设置
yum install ricci -y
passwd ricci
chkconfig ricci on
/etc/init.d/ricci start
2、在真机,安装fence工具,来管理虚拟机
yum install fence-virtd fence-virtd-libvirt fence-virtd-multicast -y
fence_virtd -c #设置fence工具
mkdir /etc/cluster
dd if=/dev/urandom of=/etc/cluster/fence_xvm.key bs=128 count=1#创建随机密钥
systemctl restart fence_virtd
netstat -antuple | grep :1229
cd /etc/cluster/
scp fence_xvm.key server1:/etc/cluster/ #分发密钥
scp fence_xvm.key server4:/etc/clusteer/
3、virt-manager #找出UUID进行绑定,进网页设置
编写nginx启动脚本并复制启动脚本到两台虚拟机,记得加可执行权限
1、加一块磁盘
2、fdisk -cu /dev/vdb #分区
3、yum install scsi-* #装需要的共享服务
4、vim /etc/tgt/targets.conf #共享路径及允许使用的主机
1、yum install iscsi-*
2、iscsiadm -m discovery -t st -p 172.25.34.3 #发现共享网络存储
3、iscsiadm -m node -l #挂载
4、fdisk -cu /dev/sda #创建主分区并设置为LVM格式
#5、mkfs.ext4 /dev/sda #只需要在一边制作文件系统格式即可
6、mount /dev/sda1 /mnt #挂载之后测试,在一边写入,另一边不会同步,需要卸载之后重新挂载才会同步
7、umount /mnt #两边都要卸载
8、clustat #找出集群名字
9、mkfs.gfs2 -j 3 -p lock_dlm -t haohao:mygfs2 /dev/sda1 #设置集群同步读写,名字必须是集群名字,否则无法识别
首先模拟磁盘容量以满,需要增加容量,在server1或server4任意一台机子作如下操作
1、umount /mnt
2、dd if=/dev/zero of=/dev/sda1 bs=1M count=10
3、partprobe
5、umount /mnt
6、pvcreate /dev/sda1
7、vgcreate cluster-vg /dev/sda1
8、lvcreate -L +4G -n demo cluster-vg
9、mkfs.ext4 /dev/cluster-vg/demo
12、lvextend -L +2G /dev/cluster-vg/demo
13、vim /etc/fstab
/dev/cluster-vg/demo /usr/local/nginx/html gfs2 _netdev 0 0
14、clustata #查看服务在那台服务器上
15、vim /usr/local/nginx/html/index.html #在上面找到的服务器上写个文件
gfs2_tool sb /dev/cluster-vg/demo all #查看集群文件系统信息
gfs2_tool journals /dev/cluster-vg/demo #查看lv的日志信息
gfs2_jadd -j 3 /dev/cluster-vg/demo #再添加3台服务器到集群clusvcadm -e server4 #启动server4的服务
clusvcadm -r nginx -m server4 #迁移服务到server4
/I0JBQkFCMA==/dissolve/70/gravity/SouthEast” alt=”这里写图片描述” title=”” />