1.试验环境:两台服务器为华为云提供的IaaS云
server1:CentOS Linux release 7.4.1708 (Core) 192.168.1.244/24
server2:CentOS Linux release 7.4.1708 (Core) 192.168.1.189/24
2.server1和server2共同配置
1.配置yum源,使用华为自己的yum源
华为云源地址: https://support.huaweicloud.com/ecs_faq/zh-cn_topic_0106199430.html
注意:其update部分的enabled=1改成0 ==》该镜像有些问题
rm -rf /etc/yum.repos.d/*
rm -rf /etc/yum.repos.d/huawei.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
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://mirrors.myhuaweicloud.com/centos/$releasever/os/$basearch/
gpgcheck=1
enabled=1
gpgkey=http://mirrors.myhuaweicloud.com/centos/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates
# mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=http://mirrors.myhuaweicloud.com/centos/$releasever/updates/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.myhuaweicloud.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
# mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
baseurl=http://mirrors.myhuaweicloud.com/centos/$releasever/extras/$basearch/
gpgcheck=1
enabled=1
gpgkey=http://mirrors.myhuaweicloud.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
# mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
baseurl=http://mirrors.myhuaweicloud.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.myhuaweicloud.com/centos/RPM-GPG-KEY-CentOS-7
yum clean all ; yum repolist ==>1万多个包出现即可以正常使用
2.server1搭建lnmp+redis
(1).网上下载redis需要用到的包:redis-4.0.8.tar.gz php-redis-2.2.4.tar.gz nginx-1.12.2.tar.gz
(2).搭建nginx
useradd nginx
tar -xf nginx-1.12.2.tar.gz
yum -y install gcc make zlib-devel pcre-devel
cd nginx-1.12.2
./configure --prefix=/usr/local/nginx
make && make install
/usr/local/nginx/sbin/nginx
echo lnmp >/usr/local/nginx/html/index.html
vim /usr/local/nginx/conf/nginx.conf
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi.conf;
}
/usr/local/nginx/sbin/nginx -s reload
curl 127.0.0.1
yum -y install php-fpm
systemctl restart php-fpm php-mysqlnd php-redis
vim /usr/local/nginx/html/test.php
<?php phpinfo();?>
curl 127.0.0.1/test.php
(3).搭建mariadb服务器
yum -y install mariadb mariadb-server
systemctl restart mariadb
systemctl enable mariadb
mysqladmin -uroot -p password "Lh123456"
mysql -uroot -p "Lh123456"
(4).搭建redis服务器,安装php-redis
tar -xf redis-4.0.8.tar.gz
cd redis-4.0.8
yum -y install gcc gcc-c++
make
make install
cd utils/
./install_server.sh
/etc/init.d/redis_6379 start
ss -anptu | grep :6379
redis-cli
tar -xf php-redis-2.2.4.tar.gz
cd phpredis-2.2.4/
phpize
./configure --with-php-config=/usr/bin/php-config
make && make install
vim /etc/php.ini
extension="redis.so"
extension_dir = "/usr/lib64/php/modules/"
systemctl restart php-fpm
php -m | grep -i redis ==>出结果,就能解析redis了
3.server2上可以搭建mariadb-server,server1的web网站连接server2进行正常访问
总结:server1上可以绑定一个弹性公网ip,用户访问这个公网ip,他连接server2的mysql数据库,能够正常展示数据,表示成功!