一.10.0.0.31安装部署NFS
1.服务端与客户端安装nfs-utils rpcbind包
[root@web03 html]# yum install -y nfs-utils rpcbind
mkdir -p /data/{wordpress,zhihu} /code/phpshe
2.修改服务端配置文件/etc/exports,添加3个共享目录,指定用户及读写权限
[root@nfs01 ~]# vim /etc/exports
/code/phpshe 172.16.1.0/24(rw,all_squash,anonuid=1111,anongid=1111)
/data/wordpress 172.16.1.0/24(rw,all_squash,anonuid=1111,anongid=1111)
/data/zhihu 172.16.1.0/24(rw,all_squash,anonuid=1111,anongid=1111)
3.创建共享目录及创建指定用户&用户组并授权
[root@nfs01 ~]# groupadd -g 1111 www-data
[root@nfs01 ~]# useradd -s /sbin/nologin -M -g 1111 -u 1111 www-data
[root@nfs01 ~]# chown -R www-data /code/phpshe
[root@nfs01 ~]# chown -R www-data /data/wordpress
[root@nfs01 ~]# chown -R www-data /data/zhihu/
4.启动nfs,rpcbind服务
systemctl start rpcbind
systemctl enable rpcbind #开机启动
systemctl start nfs
systemctl enable nfs
5.web01客户端测试nfs,查看挂载点
[root@web01 ~]# showmount -e 172.16.1.31
Export list for 172.16.1.31:
/data/zhihu 172.16.1.0/24
/data/wordpress 172.16.1.0/24
/code/phpshe 172.16.1.0/24
6.客户端测试挂载
[root@web01 ~]# mount -t nfs 172.16.1.31:/data/zhihu /mnt/
[root@web01 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 475M 0 475M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 14M 473M 3% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/mapper/centos-root 17G 2.5G 15G 15% /
/dev/sda1 1014M 138M 877M 14% /boot
tmpfs 98M 0 98M 0% /run/user/0
172.16.1.31:/data/zhihu 17G 2.4G 15G 14% /mnt
一.10.0.0.51安装部署mariadb server
1.yum安装mariadb-server安装包
[root@db01 ~]# yum install mariadb-server -y
2.启动服务,查看是否启动
[root@db01 ~]# systemctl start mariadb
[root@db01 ~]# systemctl enable mariadb
[root@db01 ~]# ss -anpl|grep 3306
tcp LISTEN 0 50 *:3306 *:* users:(("mysqld",pid=2700,fd=14))
3.修改数据库root用户密码
[root@db01 ~]# mysqladmin -uroot password “加密码”
4.在mysql数据库添加授权给所有ip以root用户登录访问
MariaDB [(none)]> select host,user,authentication_string from mysql.user;
+-----------+------+-----------------------+
| host | user | authentication_string |
+-----------+------+-----------------------+
| localhost | root | |
| db01 | root | |
| 127.0.0.1 | root | |
| ::1 | root | |
| localhost | | |
| db01 | | |
+-----------+------+-----------------------+
6 rows in set (0.00 sec)
MariaDB [(none)]> create user 'root'@'%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
三.10.0.0.7安装部署nginx
1.添加centos官方nginx yum源,安装最新版本
[root@web01 ~]# vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
2.开始yum安装
yum install -y nginx
3.修改nginx 默认虚拟主机配置文件,添加一个域名测试
[root@web01 ~]# vim /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name blog.oldboy.com;#指定一个域名
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
4.测试nginx配置启动
[root@web01 ~]# nginx -t
[root@web01 ~]# systemctl start nginx
[root@web01 ~]# systemctl enable nginx
5.在windows中配置hosts文件添加域名
10.0.0.8 blog.oldboy.com
6.测试:浏览器访问blog.oldboy.com
四10.0.0.7安装部署php
1、配置php yum源
[root@web01 ~]# cat /etc/yum.repos.d/php.repo
[webtatic-php]
name = php Repository
baseurl = http://us-east.repo.webtatic.com/yum/el7/x86_64/
gpgcheck = 0
2.安装php7.1及模块
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
3、修改php进程启动用户为nginx,配置文件/etc/php-fpm.d/www.conf
[root@web01 ~]# sed -i 's/apache/nginx/g' /etc/php-fpm.d/www.conf
[root@web01 ~]# egrep '^user|^group' /etc/php-fpm.d/www.conf
user = nginx
group = nginx
4、重启服务
systemctl start php-fpm
systemctl enable php-fpm
5.修改ngnx配置文件,添加一个location支持php文件解析
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000; #php服务监听端口
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #把用户RUI请求的路径丢给php
include fastcgi_params; #引用这个文件,将 Nginx 中的变量翻译成 PHP 中能够理解的变量
}
6.重启加载nginx配置
nginx -t
systemctl reload nginx
7.在web01测试:nginx是否解析php代码,写一个php测试代码连接远程db01 mysql数据库
[root@web01 html]# cat a.php
<?php
$link = mysqli_connect('172.16.1.51:3306', 'root', '123456');
if (!$link) {
die('Could not connect: ' . mysqli_error());
}
echo 'Mysql Connected successfully!,Hello PHP';
mysqli_close($link);
?>
8.windows配置host文件
10.0.0.8 oldboy.web.com
#浏览器访问 http://blog.oldboy.com/a.php
五.在10.0.0.7创建4个本地目录,挂载NFS服务端共享目录
1.作为wordpress,zhihu,phpshe站点根目录,相应代码存储在NFS服务端
mkdir -p /code/{wordpress,zhihu,phpshe,log}
[root@web01 tools]# mount -t nfs 172.16.1.31:/data/wordpress /code/wordpress/
[root@web01 tools]# mount -t nfs 172.16.1.31:/data/zhihu /code/zhihu/
[root@web01 tools]# mount -t nfs 172.16.1.31:/code/phpshe /code/phpshe/
2.加入开机自动挂载
172.16.1.31:/data/wordpress /code/wordpress nfs defaults 0 0
172.16.1.31:/data/zhihu /code/zhihu nfs defaults 0 0
172.16.1.31:/code/phpshe /code/phpshe nfs defaults 0 0
六10.0.0.7安装wordpress
1.解压安装包复制到对应目录
tar zxvf latest-zh_CN.tar.gz
cp -rf wordpress/* /code/wordpress/
2.在db服务器上创建wordpress库
mysql -uroot -p123456
create database wordpress ;
3.将wordpress库授权给所有通过root用户及密码登录访问者
grant all on wordpress.* to 'root'@'%' identified by '123456' with grant option;
4.增加一个nginx虚拟主机站点,指定域名及站点目录
[root@web01 conf.d]# vim blog.oldboy.com.conf
server {
listen 80;
server_name blog.oldboy.com;
root /code/wordpress;
location / {
index index.php index.html;
}
location ~* \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
5.重启加载nginx配置
nginx -t
systemctl reload nginx
6.windows配置host文件
10.0.0.7 blog.oldboy.com
浏览器访问http://blog.oldboy.com 开始安装即可
七、10.0.0.7安装部署wecenter
1.新建目录,把安装包解压到这个目录,解压完把所以文件复制到/code/zhizhu
mkdir -p WE
unzip WeCenter_3-6-1.zip
cp -rf * /code/zhihu/
修改下文件权限
chmod 777 /code/zhihu/*
2、新建一个nginx虚拟主机配置文件,指定域名&访问的网站根目录为/code/zhihu
[root@web01 conf.d]# cat wecenter.server.conf
server {
listen 80;
server_name www.oldboy.com;
root /code/zhihu;
location / {
index index.php index.html;
}
location ~* \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
3、重启加载nginx配置
nginx -t
systemctl reload nginx
4.在db01数据库服务器新建一个数据库表wecenter
mysql -uroot -p123456
mysql -uroot -p123456
5.将wecenter库授权给所有通过root用户及密码登录访问者
grant all on wecenter .* to 'root'@'%' identified by '123456' with grant option;
windows配置host文件
10.0.0.7 www.oldboy.com
######## 6、在浏览器访问www.oldboy.com 配置相关信息安装即可
八、10.0.0.7安装部署phpshe
1.安装rar命令需要解压php安装包。添加一条yum源
rpm -ivh http://mirrors.whsir.com/centos/whsir-release-centos.noarch.rpm
yum install -y rar
2、创建she目录把安装放里解压,解压完复制到/code/phpshe/
mkdir -p she
cp phpshe1.7.rar she/
rar x phpshe1.7.rar
cp -rf * /code/phpshe/
解压完进行修改文件权限
chmod -R 777 /code/phpshe/*
3.新建一个nginx虚拟主机配置文件,指定域名&访问的网站根目录为/code/phpshe
[root@web01 conf.d]# cat phpshe.server.conf
server {
listen 80;
server_name shop.oldboy.com;
root /code/phpshe;
location / {
index index.php index.html;
}
location ~* \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
4、重启加载nginx配置
nginx -t
systemctl reload nginx
5、为phpshe创建命名为phpshe数据库
mysql -uroot -p123456 -e "create database phpshe;"
6.将phpshe库授权给所有通过root用户及密码登录访问者
grant all on phpshe .* to 'root'@'%' identified by '123456' with grant option;
7、修改phpshe数据库连接配置文件
[root@web01 phpshe]# vim /app/phpshe/config.php
<?php
$pe['db_host'] = '127.0.0.1'; //数据库主机地址
$pe['db_name'] = 'phpshe'; //数据库名称
$pe['db_user'] = 'root'; //数据库用户名
$pe['db_pw'] = '123456'; //数据库密码
$pe['db_coding'] = 'utf8'; //数据库编码
$pe['url_model'] = 'pathinfo';//url模式,可选项(pathinfo/pathinfo_safe/php)
define('dbpre','pe_'); //数据库表前缀
?>
8、修改php存储session数据文件属主权限,不然在管理员登录时数据写不进去会报错。
chown nginx.nginx /var/lib/php/session
windows配置host文件
10.0.0.8 shop.oldboy.com
9、浏览器访问网页开始安装phpshe
http://shop.oldboy.com/install/
在网页中配置数据库信息及管理员账号,完成安装
http://shop.oldboy.com/admin.php
九、10.0.0.7安装部署goaccess
1、安装goaccess所有需要的lib
yum install -y GeoIP-devel
yum install -y ncurses-devel
2、下载编译安装
wget http://tar.goaccess.io/goaccess-1.2.tar.gz
tar zxvf goaccess-1.2.tar.gz
./configure --enable-utf8 --enable-geoip=legacy --prefix=/usr/local/goaccess
make && make install
3、修改goaccess配置文件
[root@web03 goaccess-1.2]# vim /usr/local/goaccess/etc/goaccess.conf
#修改goaccess分析日志格式与nginx日志格式对应
time-format %H:%M:%S
date-format %d/%b/%Y
log-format %h %^[%d:%t %^] "%r" %s %b "%R" "%u"
4、命令路径太长,创建命令软连接
ln -s /usr/local/goaccess/bin/goaccess /usr/bin/goaccess
5、分析nginx access.log 在/code/log生成nginx.html
goaccess /var/log/nginx/access.log -o /code/log/nginx.html
6、新建一个nginx虚拟主机配置文件,指定域名&访问的网站根目录为code/log及默认主页
server {
listen 80;
server_name status.oldboy.com;#域名
root /code/log;#根目录
location / {
index nginx.html;#默认主页
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
7、重启加载nginx配置
nginx -t
systemctl reload nginx
windows配置host文件
10.0.0.8 status.oldboy.com
8、浏览器访问status.oldboy.com即可
十、10.0.0.7配置监控nginx status
1、修改nginx虚拟主机配置文件,增加一个location,限制只能通过某IP才能获取nginx状态
[root@web01 conf.d]# cat goaccess-status.conf
server {
listen 80;
server_name status.oldboy.com;
root /code/log;
location / {
index nginx.html;
}
location /stauts {
stub_status;
allow 172.16.1.0/24; #白名单
allow 10.0.0.1;
deny all;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
2、重启加载nginx配置
nginx -t
nginx -t
######## 3、浏览器访问http://status.oldboy.com/stauts 即可
网友评论