0
点赞
收藏
分享

微信扫一扫

架构第一天(第二阶段)

架构介绍

架构相关名词

项目:独立的一个网站,或者独立的一个app应用
架构:用来维护或者运行一个项目的一组服务器
集群:为解决某个特定问题将多台计算机组合起来形成的单个系统(单点故障)
高可用:当一台服务器不可用,另一台服务器自动接管,保证业务不down机
负载均衡:将用户的请求,分摊到多个操作单元上执行,为了解决服务器压力不均衡的问题

架构演变

## 用户请求,针对用户设计的架构
在浏览器中输入:https://blog.driverzeng.com
1.DNS域名解析服务器 ==》将blog.driverzeng.com解析成IP地址:114.80.187.8
2.浏览器和该IP地址(114.80.187.8)的服务器(https:// 443)端(http:// 80)口建立连接
3.请求要经过114.80.187.8服务器的防火墙,如果允许你的IP(101.229.206.48)访问服务器的443端口
- 防火墙:过滤用户请求,防止恶意请求,针对IP和端口进行限制
- 关闭防火墙,关闭Selinux
- CentOS6之前:iptables
- CentOS7开始:firewalld,也可以使用iptables
- 硬件防火墙
4.请求通过防火墙后,访问到负载均衡服务器
- Nginx
- HAproxy
- LVS
- F5(硬件)
5.请求通过负载均衡后会被下发到后面的web服务器
- Nginx
- Apache
- Tomcat(Java)
- PHP(PHP代码容器)
6.前端代码会请求后端的代码,后端代码请求数据库
- MySQL
- Oracle
- SQLServer
- MariaDB
7.数据库之前会有缓存服务器,如果缓存中有请求的数据,则直接通过缓存返回给用户
- Redis
- MangoDB
- Memcache
8.文件服务器(共享存储服务器)专门用来存储图片,视频,二进制类型的数据
- NFS
- GFS
- FastDFS
- ceph

## 运维自动化工具
所有服务器,至少要有两块网卡(有两个IP地址)
外网IP地址:针对用户访问,给用户提供服务
内网IP地址:服务器之间互相可以访问
跳板机,VPN:访问内网服务器
- pptpvpn
- jumpserver
监控:检测服务器上的应用状态,硬件状态,网络状态,系统状态,业务状态
- zabbix
- nagios
- open-falcon
- promethues
- cacti
数据备份服务器:用来备份所有重要数据
- rsync
批量管理服务器
- ansible
- saltstack
日志服务器
- ELK
- flume
代码发布服务器
- Jenkins
代码存储服务器
- Gitlab

架构模板机准备

架构第一天(第二阶段)_centos

架构第一天(第二阶段)_服务器_02

架构第一天(第二阶段)_linux_03

架构第一天(第二阶段)_服务器_04

架构第一天(第二阶段)_linux_05

架构第一天(第二阶段)_centos_06

添加网卡

架构第一天(第二阶段)_服务器_07

架构第一天(第二阶段)_centos_08

设置LAN区段

架构第一天(第二阶段)_服务器_09

架构第一天(第二阶段)_服务器_10

架构第一天(第二阶段)_centos_11

开机装系统

架构第一天(第二阶段)_linux_12

修改网卡名

架构第一天(第二阶段)_服务器_13

架构第一天(第二阶段)_服务器_14

net.ifnames=0 biosdevname=0

架构第一天(第二阶段)_服务器_15

架构第一天(第二阶段)_服务器_16

/boot:500M
swap:真实内存的1-2倍,最多给8G 1024
/:剩下都给/

架构第一天(第二阶段)_centos_17

架构第一天(第二阶段)_centos_18

架构第一天(第二阶段)_linux_19

配置网卡

## 编辑第一块网卡
vi /etc/sysconfig/network-scripts/ifcfg-eth0
删除UUID
BOOTPROTO=dhcp => BOOTPROTO=static 或者 BOOTPROTO=none
ONBOOT=no => ONBOOT=yes
IPADDR=10.0.0.100
NETMASK=255.255.255.0
GATEWAY=10.0.0.2
DNS1=223.5.5.5

## 编辑第二块网卡
vi /etc/sysconfig/network-scripts/ifcfg-eth1
删除UUID
BOOTPROTO=dhcp => BOOTPROTO=static 或者 BOOTPROTO=none
ONBOOT=no => ONBOOT=yes
IPADDR=172.16.1.100
NETMASK=255.255.255.0

## 重启网卡
systemctl restart network

使用Xshell连接模板机

架构第一天(第二阶段)_服务器_20

架构第一天(第二阶段)_linux_21

系统基础优化

# 1.更改yum源
## 删除所有系统内置yum源
[root@localhost <sub>]# rm -fr /etc/yum.repos.d/*

## Base源
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

## Epel源
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

## 查看源文件
[root@localhost </sub>]# ll /etc/yum.repos.d/
-rw-r--r--. 1 root root 2523 May 12 20:02 CentOS-Base.repo
-rw-r--r--. 1 root root 664 May 12 20:03 epel.repo

## 优化阿里云的源(删除多余的baseurl)
[root@localhost <sub>]# cat /etc/yum.repos.d/CentOS-Base.repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

# 2.安装基础命令和环境
yum install net-tools vim tree htop iftop gcc gcc-c++ glibc iotop lrzsz sl wget unzip telnet nmap nc psmisc dos2unix bash-completion bash-completion-extra sysstat rsync nfs-utils httpd-tools -y

# 3.关闭防火墙
## 关闭防火墙服务
[root@localhost </sub>]# systemctl stop firewalld
## 取消防火墙开机自启
[root@localhost <sub>]# systemctl disable firewalld

# 4.关闭selinux
## 查看selinux
[root@localhost </sub>]# getenforce
Enforcing ## 开启状态

## 临时关闭
[root@localhost <sub>]# setenforce 0
## 永久关闭
[root@localhost </sub>]# vim /etc/sysconfig/selinux
SELINUX=enfocing => SELINUX=disabled

# 5.优化文件描述符
## 查看文件描述
[root@lb01 <sub>]# ulimit -n
65535

[root@lb01 </sub>]# ulimit -a

## 设置文件描述符为65535
echo '* - nofile 65535' >> /etc/security/limits.conf

# 6.修改主机名和IP的脚本
[root@localhost ~]# vim host_ip.sh
#!/bin/bash

read -p 'Please input HOSTNAME:' h
read -p 'Please input IP:' IP

hostnamectl set-hostname $h
sed -i "s#100#$IP#g" /etc/sysconfig/network-scripts/ifcfg-eth{0,1}
systemctl restart network

架构第一天(第二阶段)_服务器_22

架构第一天(第二阶段)_服务器_23

架构第一天(第二阶段)_服务器_24

架构第一天(第二阶段)_centos_25

架构第一天(第二阶段)_服务器_26

架构第一天(第二阶段)_服务器_27


举报

相关推荐

0 条评论