1 ##初始化 2 #D:备份2020备份电脑学习主要vmvare虚拟主机58期-web01服务器-10.0.0.7 3 name=web02 4 ipp=8 5 hostnamectl set-hostname $name 6 sed -i "s#.7#.${ipp}#g" /etc/sysconfig/network-scripts/ifcfg-eth[01] 7 grep $ipp /etc/sysconfig/network-scripts/ifcfg-eth[01] 8 sed -i '/UUID/d' /etc/sysconfig/network-scripts/ifcfg-eth[01] 9 grep UUID /etc/sysconfig/network-scripts/ifcfg-eth[01] 10 mkdir -p /backup/ /server/scripts /var/html/www/ /app/logs/ /server/tools 11 systemctl restart network 12 sed -i 's@keepcache=0@keepcache=1@g'/etc/yum.conf 13 yum install sshpass -y 14 #- 15 16 ##rsync-客户端配置 17 echo "oldboy123" >/etc/rsync.password 18 chmod 600 /etc/rsync.password 19 rsync -avz /etc/hosts rsync_backup@176.16.1.41::backup --password-file=/etc/rsync.password 20 #- 21 ##rsync-客户端命令行-备份+推送操作 22 rm /backup/* -fr 23 ip=10.0.0.7 24 mkdir -p /backup/$ip/ 25 mkdir -p /backup/ /server/scripts /var/html/www/ /app/logs/ 26 cd / 27 tar zchf /backup/system_backup_$(date +%F_week%w).tar.gz ./var/spool/cron/root ./etc/rc.local ./server/scripts ./etc/sysconfig/iptables 28 tar zchf /backup/www_backup_$(date +%F_week%w).tar.gz ./var/html/www 29 tar zchf /backup/www_log_backup_$(date +%F_week%w).tar.gz ./app/logs 30 ls /backup/ 31 find /backup/ -type f -mtime -1 ! -name "finger*"|xargs md5sum >/backup/$ip/finger.txt 32 rsync -avz /backup/ rsync_backup@176.16.1.41::backup --password-file=/etc/rsync.password 33 tree /backup 34 #- 35 ##rsync-全网备份-脚本 36 cat>>/server/scripts/backup.sh<<EOF 37 #/bin/bash 38 Backup_dir="/backup" 39 IP_info=$(hostname -i) 40 mkdir -p $Backup_dir/$IP_info 41 cd / 42 tar zchf $Backup_dir/$IP_info/system_backup_$(date +%F_week%w).tar.gz ./var/spool/cron/root ./etc/rc.local ./server/scripts ./etc/sysconfig/iptables 43 find $Backup_dir -type f -mtime +7|xargs rm 2>/dev/null 44 find $Backup_dir -type f -mtime -1 ! -name "finger*"|xargs md5sum >$Backup_dir/$IP_info/finger.txt 45 rsync -az /$Backup_dir/ rsync_backup@176.16.1.41::backup --password-file=/etc/rsync.password 46 EOF 47 chmod +x /server/scripts/backup.sh 48 sh /server/scripts/backup.sh 49 #- 50 ##rsync-inotify+sersync 51 #inotify 52 yum install -y inotify-tools 53 inotifywait -mrq --timefmt "%F" --format "T %w %f" 事件信息:%e" /data -e CREAT 54 55 #sersync 56 rz -y 57 tar xvf sersync2.5.4_64bit_binary_stable_final.tar.gz 58 mkdir /usr/local/sersync/{bin/,conf/,log/} -p 59 mv GNU-Linux-x86/sersync2 /usr/local/sersync/bin/ 60 mv GNU-Linux-x86/confxml.xml /usr/local/sersync/ 61 cd /usr/local/sersync/ 62 cp confxml.xml{,.bak} 63 sed -i -r "24s#opt/tongbu#data#g" confxml.xml 64 sed -i -r "25s#127.0.0.1(.*)tongbu1#176.16.1.411backup#g" confxml.xml 65 sed -i -r "30s#artuz#az#g" confxml.xml 66 sed -i -r "31s#false(.*)root(.*)pas#true1rsync_backup2password#g" confxml.xml 67 export PATH="$PATH:/usr/local/sersync/bin" 68 sersync2 -dro /usr/local/sersync/confxml.conf 69 echo "sersync2 -dro /usr/local/sersync/confxml.xml">>/etc/rc.local 70 #关闭sersync 71 yum install psmisc -y 72 killall sersync 73 74 #- 75 76 ##nfs-共享存储客户端配置 77 yum install -y nfs-utils 78 cd / 79 mount -t nfs 176.16.1.31:/data /mnt 80 showmount -e 176.16.1.31 81 ls /mnt 82 #- 83 ##nfs-开机自启动挂载 84 echo "mount -t -o nosuid,noexec, nfs 172.16.1.31:/data /mnt" >>/etc/rc.local 85 mount -a 86 umount -lf /mnt 87 #- 88 89 ##nginx--基础 90 #================================================yum安装 91 vim /etc/yum.repos.d/nginx.repo 92 [nginx-stable] 93 name=nginx stable repo 94 baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ 95 gpgcheck=1 96 enabled=1 97 gpgkey=https://nginx.org/keys/nginx_signing.key 98 yum install -y nginx 99 echo $? 100 #- 101 ##nginx-搭建三个网站 102 #创建用户www 103 useradd -M -s /sbin/nologin www 104 sed -i '/user/s@nginx@www@' /etc/nginx/nginx.conf 105 #配置文件/etc/nginx/conf.d/www.conf 106 cd /etc/nginx/conf.d/ 107 mv default.conf default.conf.bak 108 egrep -v "#|^$" default.conf.bak>default.conf 109 for name in {www,bbs,blog};do cp default.conf ${name}.conf;done 110 手动改下server标签 111 112 for name in {www,bbs,blog};do echo "10.0.0.7 $name.oldboy.com" >/html/$name/index.html;done 113 for name in {www,bbs,blog};do cat /html/$name/index.html;done 114 systemctl restart nginx 115 116 #=============================================安装密码文件,设置网站登录========== 117 yum install httpd-tools -y 118 cd /etc/nginx/password 119 htpasswd -bc ./htpasswd oldboy 123456 120 chmod 600 htpasswd 121 chown www htpasswd 122 curl www.oldboy.com -u oldboy:123456 123 124 125 #=================================conf文件详细配置================== 126 cat www.conf 127 server { 128 listen 80; 129 server_name www.oldboy.com oldboy.com; 130 if ($host ~* "^oldboy.com$") { 131 rewrite ^/(.*) http://www.etiantian.org/$1 permanent; 132 } 133 location /AV { 134 #deny 10.0.0.0/24; 135 #allow 176.16.1.0/24; 136 137 autoindex on 138 charset utf-8; 139 140 auth_basic "closed site"; 141 auth_basic_user_file password/htpasswd; 142 143 root /html/www; 144 index oldboy.html index.htm; 145 } 146 147 error_page 500 502 503 504 /50x.html; 148 location = /50x.html { 149 root /html/www; 150 } 151 } 152 ============== 153 #- 154 155 ##LNMP-安装 156 #=====================mysql================== 157 yum install mariadb-server mariadb -y 158 systemctl start mariadb.service 159 systemctl enable mariadb.service 160 mysqladmin -u root password 'oldboy123' 161 mysql -u root -poldboy123 162 163 #==================php===================== 164 yum remove php-mysql php php-fpm php-common 165 rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm 166 rpm -ivh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm 167 yum install -y 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 168 sed -i 's@user = apache@user = www@g' /etc/php-fpm.d/www.conf 169 systemctl start php-fpm 170 systemctl enable php-fpm.service 171 #- 172 ##LNMP-php+nginx 173 cat test_sh.php 174 <?php 175 phpinfo(); 176 ?> 177 cat blog.conf 178 server { 179 listen 80; 180 server_name blog.oldboy.com; 181 location / { 182 root /html/blog; 183 index index.html index.htm; 184 } 185 186 location ~ .php$ { 187 root /html/blog; 188 fastcgi_index index.php; 189 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 190 fastcgi_pass 127.0.0.1:9000; 191 include fastcgi_params; 192 } 193 error_page 500 502 503 504 /50x.html; 194 location = /50x.html { 195 root /usr/share/nginx/html; 196 } 197 } 198 #- 199 ##LNMP-php+mysql 200 systemctl start mariadb 201 #在网页创建wordpress,填写数据库访问信息时,自动修改了w 202 203 cat test_mysql.php 204 <?php 205 $servername = "localhost"; 206 $username = "root"; 207 $password = "oldboy123"; 208 //$link_id=mysql_connect('主机名','用户','密码'); 209 //mysql -u用户 -p密码 -h 主机 210 $conn = mysqli_connect($servername, $username, $password); 211 if ($conn) { 212 echo "mysql successful by root ! "; 213 }else{ 214 die("Connection failed: " . mysqli_connect_error()); 215 } 216 ?> 217 #- 218 ##LNMP-建立数据库 219 create database wordpress; 220 show databases; 221 grant all on wordpress.* to 'wordpress'@'localhost' identified by 'oldboy123'; 222 select user,host from mysql.user; 223 quit 224 use wordpress; 225 show tables; 226 use mysql; 227 show tables; 228 #- 229 ##LNMP-解除上传限制 230 server{ 231 client_max_body_size 50M; 232 } 233 vim /etc/php.ini 234 upload_max_filesize = 50M 235 #- 236 ##LNMP-wordpress-图片挂载nfs共享存储 237 cd /html/blog/wp-content/uploads 238 mv 2020/ /tmp/ 239 mount -t nfs 176.16.1.31:/data/blog /html/blog/wp-content/uploads 240 #- 241 ##LNMP-wordpress-数据库数据转移到数据库服务器db01 242 mysqldump -uroot -poldboy123 --all-database >/tmp/web_back.sql 243 scp -rp /tmp/web_back.sql 176.16.1.51:/tmp 244 #- 245 ##LNMP-wordpress-db01环境搭建好测试连接 246 mysql -uwordpress -poldboy123 -h 176.16.1.51 247 show databases; 248 sed -i 's@localhost@176.16.1.51@g' /html/blog/wp-config.php 249 systemctl disable mariadb 250 systemctl stop mariadb 251 #- 252 253 ##负载均衡动静分离 254 mkdir /html/www/static -p 集群-10.0.0.7:80 255 echo static-web集群_10.0.0.7 >/html/www/static/oldboy.html 256 257 mkdir /html/www/upload -p 集群-10.0.0.8:80 258 echo "upload-web集群_10.0.0.8" >/html/www/upload/oldboy.html 259 260 mkdir /html/www -p 集群-10.0.0.9:80 261 echo "default-web集群_10.0.0.9" >/html/www/oldboy.html 262