LNMP

bcakup

#统一用户
[root@backup ~]# groupadd www -g666
[root@backup ~]# useradd www -g666 -u666
[root@backup ~]# id www
uid=666(www) gid=666(www) groups=666(www)
#下载安装配置rsync
[root@backup ~]# yum install rsync -y

#配置rsync
[root@backup backup]# vim /etc/rsyncd.conf 
[root@backup backup]# cat /etc/rsyncd.conf 
uid = www
gid = www
port = 873
fake super = yes
use chroot = no
max connections = 200
timeout = 600
ignore errors
read only = false
list = false
auth users = yjl
secrets file = /etc/rsync.passwd
log file = /var/log/rsyncd.log
####################################
[database]
comment = "数据库备份模块"
path = /backup/database

[download]
comment = "下载文件备份模块"
path = /backup/download

[web]
comment = "web备份模块"
path = /backup/web

#创建备份存放的目录并授权
[root@backup backup]# mkdir backup
[root@backup backup]# mkdir web database download
[root@backup backup]# ll
total 0
drwxr-xr-x 2 root root 6 May 10 19:52 database
drwxr-xr-x 2 root root 6 May 10 19:52 download
drwxr-xr-x 2 root root 6 May 10 19:52 web
[root@backup backup]# chown www.www -R /backup/
[root@backup backup]# ll
total 0
drwxr-xr-x 2 www www 6 May 10 19:52 database
drwxr-xr-x 2 www www 6 May 10 19:52 download
drwxr-xr-x 2 www www 6 May 10 19:52 web
[root@backup backup]# tree /backup/
/backup/
├── database
├── download
└── web

#创建密码文件并给权限600
[root@backup backup]# vim /etc/rsync.passwd 
[root@backup backup]# cat /etc/rsync.passwd 
yjl:1
[root@backup backup]# chmod 600 /etc/rsync.passwd 
[root@backup backup]# ll /etc/rsync.passwd 
-rw------- 1 root root 6 May 10 20:01 /etc/rsync.passwd
#开机自启rsync
[root@backup ~]# systemctl enable --now rsyncd
Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.

nfs

#统一用户
[root@nfs ~]# groupadd www -g666
[root@nfs ~]# useradd www -g666 -u666
[root@nfs ~]# id www
uid=666(www) gid=666(www) groups=666(www)

#下载安装配置rsync
[root@nfs ~]# yum install rsync nfs-utils inotify-tools rpcbind -y

#和backup一样创建目录并授权
[root@nfs ]# mkdir backup
[root@nfs ]# mkdir web database download
[root@nfs ]# ll
total 0
drwxr-xr-x 2 root root 6 May 10 19:52 database
drwxr-xr-x 2 root root 6 May 10 19:52 download
drwxr-xr-x 2 root root 6 May 10 19:52 web
[root@nfs ]# chown www.www -R /backup/
[root@nfs ]# ll
total 0
drwxr-xr-x 2 www www 6 May 10 19:52 database
drwxr-xr-x 2 www www 6 May 10 19:52 download
drwxr-xr-x 2 www www 6 May 10 19:52 web
[root@nfs ]# tree /backup/
/nfs/
├── database
├── download
└── web
#安装sersync
[root@nfs opt]# rz -E
rz waiting to receive.
[root@nfs opt]# ll
total 712
-rw-r--r-- 1 root root 727290 Apr 22 16:03 sersync2.5.4_64bit_binary_stable_final.tar.gz
[root@nfs opt]# tar xf sersync2.5.4_64bit_binary_stable_final.tar.gz 
[root@nfs opt]# ll
total 712
drwxr-xr-x 2 root root     41 Oct 26  2011 GNU-Linux-x86
-rw-r--r-- 1 root root 727290 Apr 22 16:03 sersync2.5.4_64bit_binary_stable_final.tar.gz
[root@nfs opt]# mkdir /usr/local/sersync
[root@nfs opt]# mv GNU-Linux-x86/* /usr/local/sersync/
[root@nfs opt]# cd /usr/local/sersync/
[root@nfs sersync]# ll
total 1772
-rwxr-xr-x 1 root root    2214 Oct 26  2011 confxml.xml
-rwxr-xr-x 1 root root 1810128 Oct 26  2011 sersync2
#创建备份web的配置文件  改名字是方便认
[root@nfs sersync]# cp confxml.xml web.xml 
[root@nfs sersync]# mv confxml.xml database.xml 
[root@nfs sersync]# ll
total 1776
-rwxr-xr-x 1 root root    2214 Oct 26  2011 database.xml
-rwxr-xr-x 1 root root 1810128 Oct 26  2011 sersync2
-rwxr-xr-x 1 root root    2214 May 10 20:19 web.xml

#修改sersync的配置文件
[root@nfs sersync]# vim web.xml 
[root@nfs sersync]# cat web.xml 
 ..............
  <inotify>
        <delete start="true"/>
        <createFolder start="true"/>
        <createFile start="true"/>
        <closeWrite start="true"/>
        <moveFrom start="true"/>
        <moveTo start="true"/>
        <attrib start="true"/>
        <modify start="true"/>
    </inotify>

    <sersync>
        #监控本地的目录   同步到哪个ip 用哪个模块
        <localpath watch="/nfs/web">
            <remote ip="172.16.1.41" name="web"/>
            <!--<remote ip="192.168.8.39" name="tongbu"/>-->
            <!--<remote ip="192.168.8.40" name="tongbu"/>-->
        </localpath>
        <rsync>
            <commonParams params="-az"/>
            #开启验证  rsync用的用户  密码文件位置
            <auth start="true" users="yjl" passwordfile="/etc/rsync.passwd"
  ..................        
 #database 的也基本上一样就不写了
 
 #启动sersync
 [root@nfs sersync]# ./sersync2 -dro web.xml
 [root@nfs sersync]# ./sersync2 -dro database.xml
 
 #设置挂载点
[root@nfs sersync]# vim /etc/exports
[root@nfs sersync]# cat /etc/exports
/nfs/web      172.16.1.0/20(rw,sync,all_squash,anonuid=666,anongid=666)
/nfs/database 172.16.1.0/20(rw,sync,all_squash,anonuid=666,anongid=666)
/nfs/download 172.16.1.0/20(rw,sync,all_squash,anonuid=666,anongid=666)
#启动并检查挂载点
[root@nfs ~]# systemctl enable --now nfs-server.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service
[root@nfs sersync]# showmount -e
Export list for nfs:
/nfs/download 172.16.1.0/20
/nfs/database 172.16.1.0/20
/nfs/web      172.16.1.0/20

web

#官方源配置nginx
[root@web01 ~]# cd /etc/yum.repos.d/
[root@web01 yum.repos.d]# vim nginx.repo
[root@web01 yum.repos.d]# vim php.repo
#清除缓存生成缓存
[root@web01 yum.repos.d]# yum clean all
[root@web01 yum.repos.d]# yum makecache
#下载nginx
[root@web01 yum.repos.d]# yum install nginx -y

#修改nginx的配置的用户
[root@web01 nginx]# vim /etc/nginx/nginx.conf
[root@web01 opt]# cat /etc/nginx/nginx.conf 

user  www;

#下载安装解压php
[root@web01 opt]# rz -E
rz waiting to receive.
[root@web01 opt]# ll
total 19424
-rw-r--r-- 1 root root 19889622 Apr 21 16:59 php.tar.gz
[root@web01 opt]# tar xf php.tar.gz

#如果前面安装过其他版本的php要卸载掉之前上课是安装的5.4
[root@web01 opt]# yum remove php-mysql-5.4 php php-fpm php-common
[root@web01 opt]# yum localinstall *.rpm -y
#修改php的配置用户
[root@web01 opt]# vim /etc/php-fpm.d/www.conf 
[root@web01 opt]# cat /etc/php-fpm.d/www.conf 
; Start a new pool named 'www'.
[www]

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
; RPM: apache Choosed to be able to access some dir as httpd
user = www
; RPM: Keep a group allowed to write in log dir.
group = www

#设置开机自启nginx、php
[root@web01 opt]# systemctl enable --now nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@web01 opt]# systemctl enable --now php-fpm.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.

#挂载nfs
[root@web01 opt]# mount -t nfs 172.16.1.31:/nfs/web/conf /etc/nginx/conf.d/
[root@web01 opt]# mount -t nfs 172.16.1.31:/nfs/download/ /www/
[root@web01 www]# df
Filesystem                1K-blocks    Used Available Use% Mounted on
/dev/mapper/centos-root    18860032 2285636  16574396  13% /
devtmpfs                     485792       0    485792   0% /dev
tmpfs                        497960       0    497960   0% /dev/shm
tmpfs                        497960    7764    490196   2% /run
tmpfs                        497960       0    497960   0% /sys/fs/cgroup
/dev/sda1                   1038336  135596    902740  14% /boot
tmpfs                         99596       0     99596   0% /run/user/0
172.16.1.31:/nfs/web       18860032 1888512  16971520  11% /etc/nginx/conf.d
172.16.1.31:/nfs/download  18860032 1888512  16971520  11% /www
 

db01

#下载mariadb
[root@db01 ~]# yum install mariadb* -y
#设置mariadb开机自启
[root@db01 ~]# systemctl enable --now mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.servi
#创建数据库密码
[root@db01 ~]# mysqladmin -uroot password '1'
[root@db01 ~]# mysql -uroot -p1
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.68-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.01 sec)
#创建数据库用户给web及其他用户使用
MariaDB [mysql]> grant all privileges on *.* to yjl@'%' identified by '1';
Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> 

#创建/database目录并授权
[root@db01 ~]# mkdir /database
[root@db01 ~]# chown www.www -R /database
#备份脚本
[root@db01 ~]# vim mysql_dump.sh
[root@db01 ~]# cat mysql_dump.sh 
#!/bin/bash
DATE=`date +%F`
BACKUP="/database"
cd $BACKUP
mysqldump -uroot -p1 --all-databases --single-transaction > mysql-all-${DATE}.sql
tar -czf mysql-all-${DATE}.tar.gz mysql-all-${DATE}.sql
rm -rf mysql-all-${DATE}.sql
#挂载到nfs
[root@db01 ~]# mount -t nfs 172.16.1.31:/nfs/database /database/
#测试
[root@db01 ~]# ll /database/
total 0
[root@db01 ~]# ./mysql_dump.sh 
[root@db01 ~]# ll /database/  #本机.sh备份的
total 140
-rw-r--r-- 1 www www 139780 May 11 09:49 mysql-all-2021-05-11.tar.gz
[root@nfs database]# ll       #挂载的同步过来的
total 140
-rw-r--r-- 1 www www 139780 May 11 09:49 mysql-all-2021-05-11.tar.gz
[root@backup ~]# ll /backup/database/   #通过nfs的sersync实时监控同步过来的
total 140
-rw-r--r-- 1 www www 139782 May 11 09:49 mysql-all-2021-05-11.tar.gz

搭建wordpress

#上传安装包解压
[root@web01 www]# rz -E
rz waiting to receive.
[root@web01 www]# tar xf wordpress
#配置conf文件
[root@web01 www]# cd /etc/nginx/conf.d/
[root@web01 conf.d]# vim wordpress.conf
[root@web01 conf.d]# cat wordpress.conf 
server {
	listen 80;      #指定端口
	server_name linux.wps.cluster.local.com;   #指定域名
	root /www/wordpress;  #指定根目录
	location / {
		index index.php;  #指定访问的文件类型
	}
	location ~* \.php$ {          #关联php
		fastcgi_pass 127.0.0.1:9000;
		fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
		include fastcgi_params;
	}
}
#重新启动nginx
[root@web01 www]# systemctl restart nginx

#域名解析:去Windows的hosts文件中解析域名  在本机域名 后加上这个指定的域名 就能用本机ip访问nginx

#创建wordpress的数据库
[root@db01 ~]# mysql -uroot -p1
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 5.5.68-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.04 sec)

MariaDB [(none)]> 

搭建wecenter

#上传安装包解压
[root@web01 www]# rz -E
rz waiting to receive.
[root@web01 www]# unzip WeCenter_3-2-1.zip
#创建wencenter的conf文件
[root@web01 www]# cd /etc/nginx/conf.d/
[root@web01 conf.d]# vim wencenter.conf
[root@web01 conf.d]# cat wencenter.conf 
server {
        listen 80;
        server_name linux.wecenter.cluster.local.com;
        root /www/zhihu;
        
        location / {
                index index.php;
        }
        location ~* \.php$ {
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }
}
#重新启动nginx
[root@web01 www]# systemctl restart nginx

#创建wecenter的数据库
[root@db01 ~]# mysql -uroot -p1
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 5.5.68-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create database wecenter;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> 
posted on 2021-05-11 11:45  一打7  阅读(91)  评论(0编辑  收藏  举报