LNMP架构-超详细- 集群架构文档
IP地址的规划
主机名 | eth0网卡 | eth1网卡 | 服务简介 |
---|---|---|---|
lb01 | 10.0.0.5/24 | 172.16.1.5/24 | 负载服务 |
lb02 | 10.0.0.6/24 | 172.16.1.6/24 | 负载服务 |
web01 | 10.0.0.7/24 | 172.16.1.7/24 | 动态 php 服务 |
web02 | 10.0.0.8/24 | 172.16.1.8/24 | 动态 php 服务 |
web03 | 10.0.0.9/24 | 172.16.1.9/24 | 动态 java 服务 |
db01 | 10.0.0.51/24 | 172.16.1.51/24 | 数据库服务(主) |
db02 | 10.0.0.52/24 | 172.16.1.52/24 | 数据库服务(从) |
nfs01 | 10.0.0.31/24 | 172.16.1.31/24 | 存储服务(用户上传的图片和视频等) |
backup | 10.0.0.41/24 | 172.16.1.41/24 | 备份服务 |
m01 | 10.0.0.61/24 | 172.16.1.61/24 | 管理服务 |
zabbix-server | 10.0.0.71/24 | 172.16.1.71/24 | 监控服务 |
elkstack | 10.0.0.81/24 | 172.16.1.81/24 | 日志收集 |
git+jenkins | 10.0.0.91/24 | 172.16.1.91/24 | 自动化部署 |
废话不多说直接开干,注意:防止复制粘贴 ;ip规划和文章中的ip有区别,每一步都细心就好;也是为了你好!!
web01操作
#####################################################
0.创建www用户
[root@web01 ~]# groupadd -g 666 www
[root@web01 ~]# useradd -u666 -g666 -M -s /sbin/nologin www
1.配置YUM源码(Nginx PHP)
[root@web01 ~]# cat /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
1.移除旧版php
[root@nginx ~]# yum remove php-mysql-5.4 php php-fpm php-common -y
2.安装扩展源【HTTPS】
[root@web01]# yum localinstall -y http://mirror.webtatic.com/yum/el7/webtatic-release.rpm
3.安装Nginx+PHP
[root@web01 ~]# # yum -y install php71w php71w-cli php71w-common php71w-devel php71w-embedded php71w-gd php71w-mcrypt php71w-mbstring php71w-pdo php71w-xml php71w-fpm php71w-mysqlnd php71w-opcache php71w-pecl-memcached php71w-pecl-redis php71w-pecl-mongodb nginx
4.配置web站点【wordpress|wecenter】
[root@web01 ~]# sed -i ‘/^user/c user www;’ /etc/nginx/nginx.conf
[root@web01 ~]# sed -i ‘/^user/c user = www’ /etc/php-fpm.d/www.conf
[root@web01 ~]# sed -i ‘/^group/c group = www’ /etc/php-fpm.d/www.conf
修改文件上传大小vim /etc/php.ini
post_max_size = 300M
upload_max_filesize = 300M
memory_limit = 300M
编写nginx配置文件
[root@web01 conf.d]# cat wecenter.conf
server {
server_name zh.oldboy.com;
listen 80;
root /code/zh;
index index.php index.html;
location ~ \.php$ {
root /code/zh;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
[root@web01 conf.d]# cat wordpress.conf
server {
server_name blog.oldboy.com;
listen 80;
root /code/wordpress;
index index.php index.html;
location ~ \.php$ {
root /code/wordpress;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
启动服务,并加入开机自启动
[root@web01 ~]# systemctl enable nginx php-fpm
[root@web01 ~]# systemctl start nginx php-fpm
5.准备对应的代码
[root@web01 ~]# mkdir /code
[root@web01 ~]# cd /code
[root@web01 code]# wget https://wordpress.org/latest.tar.gz
解压
[root@web01 code]# unzip WeCenter_v3.2.2.zip
[root@web01 code]# tar xf latest.tar.gz
改名
[root@web01 code]# mv WeCenter322/ zh
授权
[root@web01 ~]# chown -R www.www /code/
#####################################################
6.配置数据库db01
扩展源
[root@db01 ~]# rpm -ivh http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql57-community-release-el7-10.noarch.rpm
[root@db01 ~]# yum install mysql-community-server -y
[root@db01 ~]# systemctl enable mysqld
[root@db01 ~]# systemctl start mysqld
[root@db01 ~]# mysql -uroot -p$(awk '/temporary password/{print KaTeX parse error: Expected 'EOF', got '}' at position 3: NF}̲' /var/log/mysq…(awk ‘/NR==6/{print $NF}’ /var/log/mysqld.log)
mysql> ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘Bgx123.com’;
mysql> create database wordpress;
mysql> create database zh;
mysql> create database jpress;
mysql> grant all privileges on . to ‘all’@’%’ identified by ‘Bgx123.com’;
mysql> flush privileges;
mysql> show databases;
mysql> drop database zh; 删除数据库
####################################################
7.配置windows的hosts解析,安装网站
#####################################################
web02快速扩展一台
[root@web02 ~]# groupadd -g 666 www
[root@web02 ~]# useradd -u666 -g666 -M -s /sbin/nologin www
安装nignx与php
[root@web02 ~]# scp root@172.16.1.7:/etc/yum.repos.d/* /etc/yum.repos.d/
[root@web02 ~]# yum -y install php71w php71w-cli php71w-common php71w-devel php71w-embedded php71w-gd php71w-mcrypt php71w-mbstring php71w-pdo php71w-xml php71w-fpm php71w-mysqlnd php71w-opcache php71w-pecl-memcached php71w-pecl-redis php71w-pecl-mongodb nginx
同步nginx与php配置
[root@web02 ~]# rsync -avz --delete root@172.16.1.7:/etc/nginx /etc/
[root@web02 ~]# rsync -avz --delete root@172.16.1.7:/etc/php* /etc/
在web01上打包code
[root@web01 ~]# tar czf code.tar.gz /code/
同步web01的站点目录
[root@web02 ~]# rsync -avz root@172.16.1.7:~/code.tar.gz ./
[root@web02 ~]# tar xf code.tar.gz -C /
启动服务,并加入开机自启动
[root@web02 ~]# systemctl enable nginx php-fpm
[root@web02 ~]# systemctl start nginx php-fpm
####################################################
web03 JAVA站点
安装java
[root@web03 ~]# yum install java -y
最好创建一个目录
[root@web03 ~]# mkdir /code
[root@web03 ~]# cd /code
[root@web03 code]# wget http://mirrors.shu.edu.cn/apache/tomcat/tomcat-9/v9.0.12/bin/apache-tomcat-9.0.12.tar.gz
[root@web03 code]# tar xf apache-tomcat-9.0.12.tar.gz
创建软连接或mv
[root@web03 code]# ln -s /code/apache-tomcat-9.0.12 /code/tomcat
下载jpress
[root@web03 ~]# cd /code/tomcat/webapps/ROOT
[root@web03 ~]# rz 上传jpress的war
[root@web03 ~]# unzip 包名
启动Tomcat服务
[root@web03 ~]# /code/tomcat/bin/startup.sh
加入开机自启动
[root@web03 ~]# vim /etc/rc.d/rc.local
/code/tomcat/bin/startup.sh
注意需要rc.local文件授执行权限才可以生效
[root@web03 ~]# chmod +x /etc/rc.d/rc.local
####################################################
nfs共享存储
安装
yum install nfs-utils -y
创建用户
[root@nfs ~]# groupadd -g 666 www
[root@nfs ~]# useradd -g 666 -u666 -M -s /sbin/nologin www
准备共享配置
[root@nfs ~]# cat /etc/exports
/data/blog 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)
/data/zh 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)
/data/jpress 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)
创建目录并授权
[root@nfs ~]# mkdir /data/{blog,zh,jpress} -p
[root@nfs ~]# chown -R www.www /data
[root@nfs ~]# systemctl enable nfs-server
[root@nfs ~]# systemctl start nfs-server
####################################################
web01和web02执行挂载wordpress【wecenter和jpress一样】
[root@web02 wp-content]# cp -rp uploads/ uploads_bak
[root@web02 wp-content]# mount -t nfs 172.16.1.31:/data/blog /code/wordpress/wp-content/uploads
[root@web02 wp-content]# cp -rp uploads_bak/* uploads/
web01上面直接挂载即可
[root@web01 ~]# mount -t nfs 172.16.1.31:/data/blog /code/wordpress/wp-content/uploads
写入开机自动挂载
[root@web01 ~]vim /etc/fstab
172.16.1.31:/data/blog /code/wordpress/wp-content/uploads nfs defaults 0 0
172.16.1.31:/data/zh /code/zh/uploads nfs defaults 0 0
[root@web02 ~]rsync -avz --delete root@172.16.1.7:/etc/fstat /etc/fstab
[root@web03 ~]vim /etc/fstab
172.16.1.31:/data/jpress /code/tomcat/webapps/ROOT/attachment nfs defaults 0 0
检查语法
[root@web01 ~]#mount -a
####################################################
lb01操作
拷贝web01上的yum源
[root@lb01 ~]# scp -rp root@172.16.1.7:/etc/yum.repos.d/nginx.repo /etc/yum.repos.d/
[root@lb01 ~]# yum install nginx -y
负载配置文件
[root@lb01 ~]# cat /etc/nginx/conf.d/blog_proxy.conf
upstream blog {
server 172.16.1.7:80;
server 172.16.1.8:80;
}
server {
server_name blog.oldboy.com;
listen 80;
location / {
proxy_pass http://blog;
include proxy_params;
}
}
[root@lb01 ~]# cat /etc/nginx/conf.d/zh_proxy.conf
upstream zh {
server 172.16.1.7:80;
server 172.16.1.8:80;
}
server {
server_name zh.oldboy.com;
listen 80;
location / {
proxy_pass http://zh;
include proxy_params;
}
}
[root@lb01 ~]# cat /etc/nginx/conf.d/jpress_proxy.conf
upstream java {
server 172.16.1.9:8080;
}
server {
listen 80;
server_name jpress.oldboy.com;
location / {
proxy_pass http://java;
include proxy_params;
}
}
共有优化配置文件
[root@lb01 ~]# cat /etc/nginx/proxy_params
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 30;
proxy_send_timeout 60;
proxy_read_timeout 60;
proxy_buffering on;
proxy_buffer_size 32k;
proxy_buffers 4 128k;
[root@lb01 ~]# systemctl enable nginx
[root@lb01 ~]# systemctl start nginx
###################################################
lb01操作HTTPS
1.生成ssl
2.检查当前环境
//openssl必须是1.0.2
[root@Nginx ~]# openssl version
OpenSSL 1.0.2k-fips 26 Jan 2017
//nginx必须有ssl模块
[root@Nginx ~]# nginx -V
–with-http_ssl_module
[root@Nginx ~]# mkdir /etc/nginx/ssl_key -p
[root@Nginx ~]# cd /etc/nginx/ssl_key
2.使用openssl充当CA权威机构创建私钥(生产不可能使用此方式生成证书,不被互联网CA权威承认的黑户证书)
[root@Nginx ssh_key]# openssl genrsa -idea -out server.key 2048
Generating RSA private key, 2048 bit long modulus
…+++
//记住配置密码, 我这里是1234
Enter pass phrase for server.key:
Verifying - Enter pass phrase for server.key:
3.生成自签证书,同时去掉私钥的密码
[root@Nginx ssl_key]# openssl req -days 36500 -x509
-sha256 -nodes -newkey rsa:2048 -keyout server.key -out server.crt
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:BJ
Locality Name (eg, city) [Default City]:CP
Organization Name (eg, company) [Default Company Ltd]:edu
Organizational Unit Name (eg, section) []:BOOS
Common Name (eg, your name or your server's hostname) []:BOOS
Email Address []:136