搭建lnmp平台
1、安装Nginx(192.168.8.10):
使用Nginx官方提供的rpm包
vim /etc/yum.repos.d/nginx.repo [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/7/$basearch/ gpgcheck=0 enabled=1 执行yum安装 yum install nginx -y systemctl start nginx systemctl enable nginx
2、使用第三方扩展epel源安装PHP7:
第一种方法:
vim /etc/yum.repos.d/nginx.repo [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/7/$basearch/ gpgcheck=0 enabled=1 执行yum安装 yum install nginx -y systemctl start nginx systemctl enable nginx
第二种方法:
vim /etc/yum.repos.d/nginx.repo [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/7/$basearch/ gpgcheck=0 enabled=1 执行yum安装 yum install nginx -y systemctl start nginx systemctl enable nginx
启动 php
systemctl restart php73-php-fpm
注:因为网速问题,直接复制php-rpm包本地安装
cd php-rpm
yum -y localinstall *.rpm
systemctl start php-fpm
systemctl enable php-fpm
3、安装mysql(mariadb):
rpm -ivh http://repo.mysql.com/yum/mysql-5.6-community/el/7/x86_64/mysql-community-release-el7-5.noarch.rpm yum install mysql-community-server -y systemctl start mysqld systemctl enable mysqld 修改mysql密码:mysql_secure_installation
4.应用1:搭建wordpress
(1)下载wordpress源码包
(2)复制wordpress安装包,到虚拟机/,解压并赋权
unzip wordpress-4.9.4-zh_CN.zip
chmod -R 777 /wordpress
(3)创建虚拟主机配置文件
vim /etc/nginx/conf.d/blog.conf
添加:
server { listen 80; server_name blog.benet.com; root /wordpress; index index.php index.html; location ~ \.php$ { root /wordpress; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
保存退出
systemctl reload nginx
(4)创建blog数据库和管理用户
登录数据库:mysql -uroot -p123.com
创建数据库:create database blog;
设置管理用户及密码:grant all on blog.* to lisi@localhost identified by '123.com';
(5)客户端通过域名访问blog,安装并配置
登录后台
http://blog.benet.com/wp-admin
5.应用2:搭建知乎wecenter
(1)下载wecenter源码包
(2)复制wecenter安装包,到虚拟机/zh目录下,赋权,并复制/zh目录到php服务器
cd /zh
unzip wecenter_3-3-4.zip
chmod -R 777 /zh
(3)创建虚拟主机配置文件
vim /etc/nginx/conf.d/zh.conf
添加:
server { listen 80; server_name zh.benet.com; root /zh; index index.php index.html; location ~ \.php$ { root /zh; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
保存退出
systemctl reload nginx
(4)创建blog数据库和管理用户
登录数据库:mysql -uroot -p123.com
创建数据库:create database zh;
设置管理用户及密码:grant all on zh.* to wangwu@localhost identified by '123.com';
(5)客户端通过域名访问zh,安装并配置
登录后台
===================================================================
nginx: 192.168.8.10
mysql: 192.168.8.20
php: 192.168.8.30
1.lnmp实现mysql数据库迁移(192.168.8.10)
为了实现mysql独立运行,拆分lnmp
(1)另起一台centos7(192.168.8.20),安装mysql
rpm -ivh http://repo.mysql.com/yum/mysql-5.6-community/el/7/x86_64/mysql-community-release-el7-5.noarch.rpm
yum install mysql-community-server -y
systemctl start mysqld
systemctl enable mysqld
修改mysql密码:mysql_secure_installation
(2)把原lnmp服务器(192.168.8.10)上的数据库文件导出,并复制到新的mysql(192.168.8.20)上
mysqldump -uroot -p123.com --all-databases > mysql-all.sql
scp mysql-all.sql root@192.168.8.20:/root
(3)在新的mysql服务器(192.168.8.20)上导入数据库文件
mysql -uroot -p123.com < /root/mysql-all.sql
systemctl restart mysqld
(4)在新mysql服务器上创建同名管理用户和密码
mysql -uroot -p123.com #登录
grant all on blog.* to lisi@'%' identified by '123.com';
grant all on zh.* to wangwu@'%' identified by '123.com';
(5)在原服务器上修改blog、zh的配置文件,重新指定数据库服务器ip
先查看blog的配置位置:
cd /wordpress #切换到blog网页根目录
grep -R 123.com #搜索保存密码的配置文件位置
vim /wordpress/wp-config.php
修改:
define('DB_NAME', 'blog'); #WordPress数据库的名称
define('DB_USER', 'lisi'); #MySQL数据库用户名
define('DB_PASSWORD', '123.com'); #MySQL数据库密码
define('DB_HOST', '192.168.8.20'); #新MySQL主机ip
保存退出
先查看zh的配置文件位置:
cd /zh
grep -R 123.com
vim /zh/system/config/database.php
修改:
'host' => '192.168.8.20', #新MySQL主机ip
'username' => 'wangwu', #MySQL数据库用户名
'password' => '123.com', #MySQL数据库密码
'dbname' => 'zh', #zh数据库的名称
保存退出
2.拆分php(192.168.8.30)
(1)启动一台centos7,安装php
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-gd php72w-mbstring php72w-pdo php72w-xml php72w-fpm php72w-mysqlnd php72w-opcache
(2)修改nginx服务器上的配置文件,重新指向新的php服务器(zh步骤相同)
vim /etc/nginx/conf.d/blog.conf
修改为:
server { listen 80; server_name zh.benet.com; root /zh; index index.php index.html; location ~ \.php$ { root /zh; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
保存退出
systemctl restart nginx
(3)修改php服务器的配置文件
vim /etc/php-fpm.d/www.conf
定位并修改为:
listen = 192.168.8.30:9000
listen.allowed_clients = 192.168.8.10
保存退出
重启php:systemctl restart php-fpm
(4)从原服务器复制wordpress和zh的安装目录到php服务器
scp -rp /wordpress root@192.168.8.30:/
scp -rp /zh root@192.168.8.30:/
(5)客户端验证访问