LNAMP架构项目一

一、第一阶段

假设:公司初期只有一台web服务器,搭建Web服务器的脚本如下:

 1 #检查环境
 2 setenforce 0 &> /dev/null
 3 sed -i s/=enforcing/=disabled/g /etc/selinux/config
 4 systemctl restart firewalld
 5 #使用CentOS系统原始源下载相关软件
 6 yum -y remove maria*
 7 echo '[mysql57-community] 
 8 name=MySQL 5.7 Community Server  
 9 baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
10 enabled=1
11 gpgcheck=0
12 ' > /etc/yum.repos.d/mysql57-community.repo
13 yum clean all && yum makecache -q
14 yum -y install epel-release -q
15 yum -y install vim bash-com* net-tools unzip nginx httpd php php-mysql mysql-com*server -q
16 #使用nginx实现动静分离,搭建网站
17 sed -i '42s/80/81/g' /etc/httpd/conf/httpd.conf
18 sed -i '38,$'c} /etc/nginx/nginx.conf
19 echo " server {
20     listen    80;
21     server_name    3344.com;
22     location ~*\.php$ {
23     proxy_pass    http://127.0.0.1:81;
24     }
25     location / {
26     root    /var/www/html;
27     }
28 }" > /etc/nginx/conf.d/3344.conf
29 systemctl restart httpd nginx
30 systemctl enable httpd nginx -q
31 firewall-cmd --add-port=80/tcp
32 firewall-cmd --add-port=80/tcp --permanent -q
33 #配置mysql数据库,开启二进制日志,创建数据库及用户
34 sed -i 4a"server-id=1\nlog-bin=binlog" /etc/my.cnf
35 systemctl restart mysqld
36 systemctl enable mysqld
37 PW=`cat /var/log/mysqld.log | grep password |head -n 1 |awk '{print $NF}'`
38 mysql -p$PW --connect-expired-password -e "alter user 'root'@'localhost' identified by 'Ryz0304/1';"
39 echo "[client]
40 user=root
41 password='Ryz0304/1'" > /root/.my.cnf #将数据库的用户密码写入配置文件中,方便登录
42 mysql -e "create database wordpress;"
43 mysql -e "grant all on wordpress.* to 'wordpress'@'localhost' identified by 'W0rdpress.';"
44 mysql -e "flush privileges;"
45 rm -rf /var/www/html/*
46 chmod -R 777 /var/www/html
47 #上传代码至nginx的工作目录/var/www/html(自定义的)
48 #浏览器访问即可
View Code

问题:

1、

2、

二、第二阶段

为防止一台服务器发生故障,需要动态添加一台新的服务器,使其成为主备关系,在第一台服务器宕机的情况下,web服务还可以正常运作: 

问题:

三、第三阶段

四、第四阶段

五、第五阶段

猜你喜欢

转载自www.cnblogs.com/renyz/p/11823150.html