1、安装nginx服务器
1)挂载光盘安装依赖软件
[root@centos01 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@centos01 ~]# yum -y install pcre-devel zlib-devel
[root@centos02 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@centos02 ~]# yum -y install pcre-devel zlib-devel
2)切换光盘解压nginx到本地
[root@centos01 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@centos01 ~]# tar zxvf /mnt/nginx-1.6.0.tar.gz -C /usr/src/
[root@centos01 ~]# scp /mnt/nginx-1.6.0.tar.gz [email protected]:/root
[root@centos02 ~]# tar zxvf nginx-1.6.0.tar.gz -C /usr/src/
3)创建管理nginx的用户
[root@centos01 ~]# useradd -M -s /sbin/nologin nginx
[root@centos02 ~]# useradd -M -s /sbin/nologin nginx
4)配置nginx
[root@centos01 ~]# cd /usr/src/nginx-1.6.0/
[root@centos01 nginx-1.6.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx
[root@centos02 ~]# cd /usr/src/nginx-1.6.0/
[root@centos02 nginx-1.6.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx
5)编译安装nginx
[root@centos01 nginx-1.6.0]# make && make install
[root@centos02 nginx-1.6.0]# make && make install
6)优化nginx
[root@centos01 nginx-1.6.0]# ln -s /usr/local/nginx/sbin/* /usr/local/sbin/
[root@centos02 nginx-1.6.0]# ln -s /usr/local/nginx/sbin/* /usr/local/sbin/
7)编辑主页测试文件
[root@centos01 ~]# echo "www.benet.com" > /usr/local/nginx/html/index.html
[root@centos02 ~]# echo "www.accp.com" > /usr/local/nginx/html/index.html
8)启动服务
[root@centos01 ~]# nginx
[root@centos02 ~]# nginx
2、配置apache服务
1)安装httpd
[root@centos05 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@centos05 ~]# yum -y install httpd
2)编辑测试文件
[root@centos05 ~]# echo "www.xsh.com" > /var/www/html/index.html
3)启动服务并设置开机自启
[root@centos05 ~]# systemctl start httpd
[root@centos05 ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
4)客户端访问
3、安装配置haproxy
1)安装依赖程序
[root@centos03 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@centos03 ~]# yum -y install pcre-devel bzip2-devel
2)解压haproxy到本地
[root@centos01 ~]# scp /mnt/haproxy-1.4.24.tar.gz [email protected]:/root
[root@centos03 ~]# tar zxvf haproxy-1.4.24.tar.gz -C /usr/src/
3)编译haproxy支持64位系统
[root@centos03 ~]# cd /usr/src/haproxy-1.4.24/
[root@centos03 haproxy-1.4.24]# make TARGET=linux26
4)安装haproxy
[root@centos03 haproxy-1.4.24]# make install
5)创建保存haproxy配置文件目录
[root@centos03 haproxy-1.4.24]# mkdir /etc/haproxy
6)生成主配置文件
[root@centos03 haproxy-1.4.24]# cp examples/haproxy.cfg /etc/haproxy/
7)创建haproxy服务控制脚本设置执行权限
[root@centos03 haproxy-1.4.24]# cp examples/haproxy.init /etc/init.d/haproxy
[root@centos03 haproxy-1.4.24]#chmod +x /etc/init.d/haproxy
8)添加系统服务设置开机自启
[root@centos03 haproxy-1.4.24]# chkconfig --add haproxy
[root@centos03 haproxy-1.4.24]# chkconfig --level 35 haproxy on
9)优化程序执行命令
[root@centos03 haproxy-1.4.24]# cp haproxy /usr/sbin/
10)创建服务运行的临时目录
[root@centos03 haproxy-1.4.24]# mkdir -p /usr/share/haproxy
11)修改主配置文件
[root@centos03 ~]# vim /etc/haproxy/haproxy.cfg
global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
#log loghost local0 info
maxconn 4096
chroot /usr/share/haproxy
uid 99
gid 99
daemon
#debug
#quiet
defaults
log global
mode http
option httplog
option dontlognull
retries 3
redispatch
maxconn 2000
contimeout 10
clitimeout 10
srvtimeout 10
listen nginx 192.168.100.30:80
balance roundrobin
server web1 192.168.100.10:80 check inter 2000 fall 3
server web2 192.168.100.20:80 check inter 2000 fall 3
server web3 192.168.100.50:80 check inter 2000 fall 3 weight 1
12)启动服务
[root@centos03 ~]# /etc/init.d/haproxy start
Starting haproxy (via systemctl): [ 确定 ]
4、配置dns
1)安装dns服务
[root@centos04 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@centos04 ~]# yum -y install bind bind-chroot
2)编辑主配置文件
[root@centos04 ~]# echo "" > /etc/named.conf
[root@centos04 ~]# vim /etc/named.conf
options {
listen-on port 53 { any; };
directory "/var/named";
};
zone "bdqn.com" IN {
type master;
file "bdqn.com.zone";
};
3)编辑正向解析文件
[root@centos04 ~]# vim /var/named/bdqn.com.zone
$TTL 86400
@ SOA bdqn.com. root.bdqn.com. (
2019120901
1H
15M
1W
1D
)
@ NS centos04.bdqn.com.
centos04 A 192.168.100.40
www A 192.168.100.30
4)添加权限
[root@centos04~]# chmod +x /var/named/benet.com.zone
[root@centos04 ~]# chown named:named /var/named/benet.com.zone
5)设置网卡添加DNS
[root@centos04 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens32
DNS1=192.168.100.40
6)重启网卡
[root@centos04 ~]# systemctl retart network
7)启动dns服务并设置开机自启
[root@centos04 ~]# systemctl start named
[root@centos04 ~]# systemctl enable named
Created symlink from /etc/systemd/system/multi-user.target.wants/named.service to /usr/lib/systemd/system/named.service.