项目实施报告
一、项目需求:
构建公司的网站平台,通过web方式向客户展示公司产品。
二、项目分析:
1、用nginx构建web服务,提供web网站访问,并部署2台web主机,实现业务的负载均衡 2、用dns的轮询解析实现web主机的负载均衡 3、2台web主机需要给客户提供一致的、相同的访问内容,用nfs构建网络存储,为2台web主机提供存储。 4、用rsync实现nfs服务器的异地灾备 5、为了确保安全,整个web平台的服务器管理通过跳板机实现。
三、项目实施:
项目环境
各个服务器配置
- 配置各个虚拟机IP地址,关闭firewall,selinux,配置yum源,改主机名。
- 堡垒机配置 (1) 建立普通用户admin并提权 (2) 用admin进入系统并生成秘钥 (3) 把公钥导入,堡垒机私钥导入Windows (4) 用Xshell秘钥连接虚拟机 (5) sudo -i进入root账号 (6) 生成秘钥并且把秘钥导入各个服务器 (7) 用ssh远程链接各个服务器进行管理和维护
jumpserver://只在跳板机生成一对秘钥对
useradd admin
passwd admin
visudo //提权
admin ALL=/bin/bash
sudo -i //切换到root用户
su - admin
ssh-keygen -t rsa //生成密钥对,可以不设秘钥对密码。
ssh-copy-id -i admin@192.168.70.100
//把公钥传给跳板机自己,私钥用winscp拖拽到windows管理机。
web01;web02;nfs1;nfs2;dnsserver://分别创建admin_user
useradd admin_user
passwd admin_user
visudo //提权
admin_user ALL=/bin/bash
jumpserver:
ssh-copy-id -i admin_user@192.168.70.102 //其余五台设备的ip,把公钥传给五台设备,私钥留在本机。
ssh abmin_user@192.168.70.102 //其余五台的设备ip
sudo -i
DNS服务器的配置
(1)安装DNS服务器 (2) 在客户端配置 DNS服务器地址 (3)创建named.conf主配置文件,提供test.com域的正向解析 (4)配置区域文件 (5) 区域数据文件的归属属性
[root@dnsserver ~]# cat /etc/named.conf
options {
listen-on port 53 { 192.168.70.102; };
listen-on-v6 port 53 { any; };
directory "/var/named";
allow-query { any; };
recursion yes;
forwarders { 8.8.8.8; 114.114.114.114; };
};
zone "." IN {
type hint;
file "named.ca";
};
zone "test.com" IN {
type master;
file "test.com.zone";
allow-transfer { 192.168.70.103;192.168.70.104; };
};
[root@dnsserver ~]# cat /var/named/test.com.zone
$TTL 1D
@ IN SOA @ root.test.com. (
0
1D
1H
1W
3H )
test.com. IN NS dnsserver.test.com.
dnsserver.test.com. IN A 192.168.70.102
www.test.com. IN A 192.168.70.103
www.test.com. IN A 192.168.70.104
* IN A 192.168.70.120
web服务器配置
(1) 源码编译及安装 1)解包 2)配置 3)编译及安装
(2) 优化执行路径`
- web01
echo "www.test.com/web01" > /usr/local/nginx/html/index.html
vim /usr/local/nginx/conf/nginx.conf
events {
worker_connections 1024;
use epoll;
}
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;
server {
listen 80;
server_name www.test.com test.com;
charset utf-8;
access_log logs/test.access.log main;
location / {
root /usr/local/nginx/html;
index index.html index.php;
}
}
- 在windows主机上修改hosts文件,添加web站点和ip地址
- 192.168.70.103 www.test.com
- 192.168.70.104 www.test.com
- 测试在浏览器上输入域名或者IP:看输出是否为
- www.test.com/web01
- www.test.com/web02
- web02
echo "www.test.com/web02" > /usr/local/nginx/html/index.html
配置同web01
- web01和web02开机自启nginx 和自动挂载NFS服务器
/usr/local/nginx/sbin/nginx
mount 192.168.70.105:/webroot /usr/local/nginx/html
配置NFS服务
- nf1为主服务器,nf2为备份服务器。
- 挂载点为nf1 的/webroot
- web01,web02,nf1,nfs2 装包 NFS和rpc
[root@nfs1 ~]# cat /etc/exports
/webroot 192.168.70.0/24(rw,no_root_squash)
配置实时同步
- rsync+sersync
- nfs2为服务端,nfs1为客户端。采用推数据的方式,在nfs1配置sersync。
- nfs1的/webroot目录 同步到 nfs2的 /usr/local/nginx/html目录
- 配置nfs2 的rsync服务端
[root@nfs2 ~]# cat /etc/rsyncd.conf
uid = root
gid = root
address = 192.168.70.106
port = 873
hosts allow = 192.168.70.0/24
use chroot = yes
max connections = 5
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /var/log/rsycnd.log
motd file = /etc/rsyncd.motd
[webroot]
path = /usr/local/nginx/html/
comment = xxxxxxxxxxxxxxx
read only = false
list =yes
auth users = backuper
secrets file = /etc/rsync.passwd
- 设置自动挂载nfs1和开机自启rsync
cat /etc/rc.d/rc.loacl
mount 192.168.70.105:/webroot /usr/local/nginx/html/
rsync --daemon --config=/etc/rsyncd.conf
- 配置nfs1 的sersync客户端
- 下载sersync,安装
- 配置sersync
[root@nfs1 ~]# cat /etc/rc.d/rc.local
/opt/sersync/sersync2 -d -r -o /opt/sersync/confxml.xml
[root@nfs1 ~]# cd /opt/sersync/
[root@nfs1 sersync]# ls
confxml.xml confxml.xml.bak sersync2
[root@nfs1 sersync]# cat confxml.xml
24 <localpath watch="/usr/local/nginx/html">
25 <remote ip="192.168.70.106" name="webroot"/>
31 <auth start="ture" users="backuper" passwordfile="/etc/rsync.passwd"/>
项目验收
- 70.105
[root@nfs1 ~]# cd /webroot
[root@nfs1 webroot]# echo "622799abb" > index.html
- 70.106
[root@nfs2 opt]# cd /usr/local/nginx/html
[root@nfs2 html]# watch cat /usr/local/nginx/html