• 12 LNMP搭建


    所有机器统一用户

    backup

    #安装rsync
    [root@backup ~]# yum install rsync -y
    
    #编辑配置文件
    [root@backup ~]# vim /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 = baimo
    secrets file = /etc/rsync.passwd
    log file = /var/log/rsyncd.log
    
    [web]
    comment = welcome to my backup!
    path =/backup/web
    [conf]
    comment = conf backup
    path =/backup/conf
    [mysql]
    comment = mysql backup
    path =/backup/mysql_backup
    
    
    #配置密码文件并授权600
    [root@backup ~]# echo "baimo:123" >> /etc/rsync.passwd 
    [root@backup ~]# cat /etc/rsync.passwd 
    baimo:123
    [root@backup ~]# chmod 600 /etc/rsync.passwd
    
    #根据配置文件添加目录并设置权限
    [root@backup ~]# mkdir /backup/mysql_backup -p
    [root@backup ~]# mkdir /backup/web -p
    [root@backup ~]# mkdir /backup/conf -p
    [root@backup ~]# chown -R www.www /backup/
    
    #启动服务本机推送测试
    [root@backup ~]# rsync -az ./1_.txt baimo@backup::conf
    Password: 
    [root@backup ~]# ll /backup/
    total 4
    -rw-r--r-- 1 www www 3901 Apr 23 20:12 1_.txt
    drwxr-xr-x 2 www www    6 Apr 29 19:40 mysql_backup
    #测试成功
    

    NFS

    #安装nfs&rpcbind&rsync
    [root@nfs ~]# yum install rsync nfs-utils inotify-tools rpcbind -y
    
    #下载sersync(2.5.4稳定版本)
    wget http://down.whsir.com/downloads/sersync2.5.4_64bit_binary_stable_final.tar.gz
    
    #安装sersync(二进制包)
    [root@nfs ~]# tar xf sersync2.5.4_64bit_binary_stable_final.tar.gz
    
    #移动并改名
    [root@nfs ~]# mv GNU-Linux-x86 /usr/local/sersync
    
    #创建挂载目录web和conf并授权用户
    [root@nfs ~]# mkdir /web && chown -R www.www /web
    [root@nfs ~]# mkdir /conf && chown -R www.www /conf
    
    [root@nfs sersync]# cp -a nginx.xml web.xml
    [root@nfs sersync]# cp -a nginx.xml conf.xml	#这里是拷贝默认文件,我之前改过名字了
    
    #配置.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>
            <localpath watch="/web">
                <remote ip="192.168.15.41" name="web"/>	#还有一个改成conf
                <!--<remote ip="192.168.8.39" name="tongbu"/>-->
                <!--<remote ip="192.168.8.40" name="tongbu"/>-->
            </localpath>
            <rsync>
                <commonParams params="-az"/>
                <auth start="true" users="baimo" passwordfile="/etc/rsync.passwd"/>
    
    #启动
    [root@nfs sersync]# ./sersync2 -dro conf.xml
    [root@nfs sersync]# ./sersync2 -dro web.xml
    #自行测试,此处省略
    
    #编写挂载目录的配置文件
    [root@nfs /]# vim /etc/exports
    /web 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)
    /conf 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)
    
    #启动并检查
    [root@nfs /]# systemctl start rpcbind nfs
    [root@nfs /]# showmount -e
    Export list for nfs:
    /conf 172.16.1.0/24
    /web  172.16.1.0/24
    [root@nfs /]# cat /var/lib/nfs/etab
    /conf	172.16.1.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,all_squash,no_subtree_check,secure_locks,acl,no_pnfs,anonuid=666,anongid=666,sec=sys,rw,secure,root_squash,all_squash)
    /web	172.16.1.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,all_squash,no_subtree_check,secure_locks,acl,no_pnfs,anonuid=666,anongid=666,sec=sys,rw,secure,root_squash,all_squash)
    

    db01

    #安装数据库
    [root@db01 ~]# yum install mariadb* -y
    
    #启动mariadb并开机自启
    [root@db01 ~]# systemctl start mariadb.service
    [root@db01 ~]# systemctl enable mariadb.service 
    Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
    
    #创建用户并登录
    [root@db01 ~]# mysqladmin -uroot password '***'
    [root@db01 ~]# mysql -uroot -p***
    
    #创建数据库
    MariaDB [(none)]> create database wordpress;
    Query OK, 1 row affected (0.00 sec)
    
    MariaDB [(none)]> create database zhihu;
    Query OK, 1 row affected (0.00 sec)
    
    # 创建用户给予web以及其它网站使用
    MariaDB [mysql]> grant all privileges on *.* to baimo@'%' identified by 'baimo';
    Query OK, 0 rows affected (0.01 sec)
    
    MariaDB [mysql]> flush privileges;#刷新
    Query OK, 0 rows affected (0.00 sec)
    

    web(1)(2)(3)

    ========================共同操作部分==========================
    #安装Nginx、php、nfs、rpcbind
     cat > /etc/yum.repos.d/nginx.repo <<EOF
    [nginx-stable]
    name=nginx stable repo
    baseurl=http://nginx.org/packages/centos/7/$basearch/
    gpgcheck=1
    enabled=1
    gpgkey=https://nginx.org/keys/nginx_signing.key
    module_hotfixes=true
    
    cat >/etc/yum.repos.d/php.repo<<EOF
    [php-webtatic]
    name = PHP Repository
    baseurl = http://us-east.repo.webtatic.com/yum/el7/x86_64/
    gpgcheck = 0
    EOF
    
    #清空重载缓存
    [root@web01 ~]# yum clean all && yum makecache
    
    #安装php
    [root@web01 ~]# yum remove php-mysql-5.4 php php-fpm php-common
    [root@web01 ~]# yum -y install php71w php71w-cli php71w-common php71w-devel php71w-embedded php71w-gd php71w-mcrypt php71w-mbstring php71w-pdo php71wxml php71w-fpm php71w-mysqlnd php71w-opcache php71w-pecl-memcached php71wpecl-redis php71w-pecl-mongodb
    
    #更改php配置文件改为用户和组为www
    [root@web01 ~]# vim /etc/php-fpm.d/www.conf
    # 启动php
    [root@web01 ~]# 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.
    
    
    #安装Nginx
    [root@web01 ~]# yum install nginx -y
    
    #更改配置文件改为用户和组为www
    [root@web01 ~]# vim /etc/nginx/nginx.conf
    
    #启动nfs,rpcbind
    [root@web01 ~]# systemctl start nfs rpcbind
    
    #查看挂载点
    [root@web01 ~]# showmount -e 172.16.1.31
    Export list for 172.16.1.31:
    /conf 172.16.1.0/24
    /web  172.16.1.0/24
    
    #创建挂载目录授权并挂载
    [root@web01 ~]# mkdir /web
    [root@web01 ~]# chown -R www.www /web/
    [root@web01 ~]# mount -t nfs 172.16.1.31:/web /web/
    [root@web01 ~]# mount -t nfs 172.16.1.31:/conf /etc/nginx/conf.d/
    
    #查看
    [root@web01 ~]# df -h
    Filesystem               Size  Used Avail Use% Mounted on
    172.16.1.31:/web          99G  2.6G   97G   3% /web
    172.16.1.31:/conf         99G  2.6G   97G   3% /etc/nginx/conf.d
    
    ===================单独操作部分=================
    #上传代码到web目录下并解压
    [root@nfs web]# ll
    total 4
    drwxr-xr-x  5 1006 1006 4096 Jan 11  2019 wordpress
    drwxr-xr-x 14 root root  296 Jun  4  2018 zhihu
    
    #授权
    [root@nfs web]# cd ..
    [root@nfs /]# chown -R www.www /web/
    
    #编写Nginx配置
    server {
            listen 80;
            server_name zhihu.cluster.local.com;
            root /web/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;
            }
    }
    #检查启动
    [root@web01 conf.d]# nginx -t
    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful
    [root@web01 conf.d]# systemctl start nginx
    #关联数据库
    

    #安装成功分别测试其他两台机
    #我是都OK的,哈哈哈哈
    

    #博客
    server {
            listen 80;
            server_name wps.cluster.local.com;
            root /web/wordpress;
            client_max_body_size 10m;
            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;
            }
            location =/wp-admin {
                    auth_basic "你码呢?";
                    auth_basic_user_file /etc/nginx/conf.d/auth_basic;
                    index index.php;
            }
    }
    

    #测试其他三台机
    #反正我三台测试都√,哈哈哈
    

    数据库备份

    db01端定时任务

    #!/bin/bash
    #baimo
    #mysql_backup
    
    DATE=`date +%F`
    BACKUP="/databases"
    
    cd $BACKUP
    mysqldump -uroot -p123 --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
    md5sum mysql-all-${DATE}.tar.gz > flag
    
    export RSYNC_PASSWORD=123
    rsync -az $BACKUP/ baimo@192.168.15.41::mysql
    
    #加入定时任务
    crontab -e
    0 1 * * * /bin/bash /root/mysql_backup.sh
    

    backup端校验+发邮件

    #!/bin/bash
    #baimo
    #mysql_check
    
    DATE=`date +%F`
    #校验文件
    md5sum -c /backup/mysql/flag > /root/result.txt
    
    #将校验结果发送给管理员邮箱
    mail -s "$DATE备份文件 校验的结果" 1466705884@qq.com < $DIR/result.txt
    
    rm -rf /root/result.txt
    
    #加入定时任务
    crontab -e
    0 1 * * * /bin/bash /root/mysql_check.sh
    
  • 相关阅读:
    Vue 实现前进刷新,后退不刷新的效果
    chrome浏览器的跨域设置——包括版本49前后两种设置
    Promise.all和Promise.race区别,和使用场景
    滚动条默认最底部
    使用react进行父子组件传值
    java 数组基础学习(一维二维数组)
    react项目 使用echarts
    Python的hasattr() getattr() setattr() 函数使用方法详解
    【线性判别】Fisher线性判别(转)
    【semantic segmentation】Pyramid Scene Parsing Network(转)
  • 原文地址:https://www.cnblogs.com/zhaokunhao/p/14720199.html
Copyright © 2020-2023  润新知