共计 9218 个字符,预计需要花费 24 分钟才能阅读完成。
@TOC
06_Linux 根底 -NGINX 和浏览器、网页的关系 - 云服务器 ssh 登陆 - 装置 NGINX- 上传网页 - 压缩命令 -xz-gzip-bzip2-zip-tar- 配置 NGINX 服务器反对下载性能 - 备份脚本
一. NGINX 和浏览器、网页的关系
nginx 是一个 web 服务器
html 语言编写网页
cd /usr/local/nginx html
cd html/(注:寄存网页门路)
思考:1. 网页和 nginx 的关系
nginx 将网页发送给浏览器
2. 浏览器和 nginx 的关系
浏览器问 nginx 要网页
nginx 将网页发送给浏览器
3. 浏览器和网页的关系
浏览器是能读懂网页的 html,js,css 代码,渲染出成果
web: 网站
表单信息放到数据库里去,nginx 只能拜访动态页面,Python 把信息传到数据库里。Python——》flask web 后端——》user 表
如何判断 nginx 是否运行?1. 看过程
ps aux|grep nginx
2. 看端口
netstat -anplut
项目组:1. 前端
2. 后端
3. 运维
4. 测试
5.dba
6. 项目经理
cd /usr/local/nginx/html/ 放网页
rz 只能传文件,不能传文件夹
二. 云服务器 ssh 登陆 - 装置 NGINX- 上传网页
本人的虚拟机的 linux 零碎里呢?(如何上传本人的网页到 linux 零碎呢)Xshell 连过来
本人的云服务器,如何上传本人的网页到云服务器呢?1.xshell --》公网 ip(云服务器的公网 ip)106.54.83.86(注:xshell 连贯)用户名 root --》明码是有个初始密码(注:passwd 改明码)2. 本人去编译装置 nginx--》倡议应用脚本装置 --> 启动 nignx
3. 上传本人的网页到 nginx 的 html 目录下(注:scp 或上传 Windows【中间环节】)4. 去拜访 106.54.83.86
(注)脚本:# cat onekey_install_nginx_v2.sh
#!/bin/bash
#1. 下载 nginx 软件包
mkdir -p /nginx2
cd /nginx2
curl -O http://nginx.org/download/nginx-1.19.2.tar.gz
#2. 解压, 进入文件夹
tar xf nginx-1.19.2.tar.gz
cd nginx-1.19.2
#3. 编译前的配置
#新建用户 sanchuang9
useradd sanchuang9
#装置 gcc 和 pcre-devel 软件包,因为 nginx 须要这些软件,解决软件的依赖关系
yum install gcc make pcre-devel zlib-devel -y
#配置 nginx,指定装置门路和启动 nginx 的用户名
./configure --prefix=/usr/local/nginx2 --user=sanchuang9
#4. 编译
make
#5. 编译装置
make install
#6. 敞开防火墙服务和设置开机不要启动
service firewalld stop
systemctl disable firewalld
#7. 批改 PATH 变量,不便能够间接应用 nginx
echo "PATH=$PATH:/usr/local/nginx2/sbin" >>/root/.bashrc
ip add 看的是私网 IP
scp 近程 copy
/usr/local/nginx/sbin/nginx 启动 nginx
ps aux|grep nginx 查看 nginx 过程
搞一个本人的网站
1. 购买一个云服务器 --》阿里云或者腾讯云,华为云,亚马逊收费试用 --》学生版 10 元 / 月
2. 购买域名 5 元 / 年
在哪里购买的云服务器,就在哪里买域名,不便备案
3. 备案
如果不备案,不能失常的应用域名去拜访
cat /etc/centos-release 查看 centos 版本
三. 压缩命令 -xz-gzip-bzip2-zip-tar- 配置 NGINX 服务器反对下载性能
次要内容:压缩命令 -tar(重点)对文件和文件夹进行压缩
==tar -czf -->.tar.gz== ==tar cjf -->.tar.bz2== ==tar cJf -->.tar.xz== ==tar tf \*.tar.\*== ==tar xf \*.tar.\*== \# tar xf boot_log_passwd.tar.gz ==-C== /zhanghuayou/ 压缩命令 -xz-gzip-bzip2-zip:都只能对文件进行压缩 zip -->.zip gzip -->.gz xz --->.xz bzip2 -->.bz2 zip yum install zip unzip -y ==zip chenpeng.txt.zip chenpeng.txt== ==unzip passwd.zip== gzip ==gzip hosts== ==gunzip hosts.gz== ==zcat messages.gz== xz ==xz hosts== ==unxz hosts.xz== ==xzcat messages.xz== bzip2 yum install bzip2 -y ==bzip2 passwd== ==bunzip2 passwd.bz2== ==bzcat passwd.bz2== 配置 nginx 服务器反对下载性能
压缩命令 -xz-gzip-bzip2-zip-tar
为什么要打压缩包?备份的时候,能节约空间
网络传送的时候,能节约工夫
windows 里有哪些解压缩软件?winrar
7z
好压
快压
Zip
windows 里的.rar 压缩文件传递到 linux 里,是否能关上
sc.rar(注:rar 解压不了,linux 里没这个软件,须要装置才有)sc.zip -->linux 默认反对
windows 能解压 linux 里的所有的压缩文件
nginx-1.19.2.tar.gz linux 里的压缩文件
压缩文件红色的,可执行文件绿色的
zip
zip
zip 只能对文件进行压缩,不能对文件夹进行压缩
yum install zip unzip -y ==(注:zip 须要装置)==
zip 打压缩包
unzip 解压的
\# ==zip chenpeng.txt.zip chenpeng.txt==(注:== 用法 ==)
压缩后的文件 源文件
[root@sanchuang-linux lianxi]# zip passwd.zip passwd
adding: passwd (deflated 61%)(注:deflated 压缩,气馁)
ll -h 看大小
passwd.zip
\# ==unzip passwd.zip 解压 ==
Archive: passwd.zip
inflating: passwd
\# ls
passwd passwd.zip
==zip 的毛病:有源文件和新文件 ==
gzip
gzip
gzip 能够间接在源文件上压缩,后缀名是.gz(注:与 zip 的区别,了解为 zip 的升级版)
==(注:gzip 不须要装置)==
hosts passwd passwd.zip
\# ==gzip hosts(用法)== gzip + 源文件
\# ls
hosts.gz passwd passwd.zip
\# ==gunzip hosts.gz(解压)==
\# ==zcat messages.gz(查看压缩文件)==
xz
xz ==(注:xz 不须要装置)==
https://cdn.kernel.org/pub/li…
\# ==xz hosts(用法)==
\# ls
hosts.xz passwd passwd.zip
\# ==unxz hosts.xz(解压)==
\# ls
hosts passwd passwd.zip
\# ==xzcat messages.xz(查看压缩文件)==
gz 与 xz 比拟,xz 成果好
举荐应用 xz
bzip2
bzip2 ==(注:bzip2 须要装置)==
yum install bzip2 -y
\# ==bzip2 passwd(用法)==
passwd.bz2
\# ==bunzip2 passwd.bz2(解压)==
passwd
\# ==bzcat passwd.bz2(查看压缩文件)==
zip –>.zip
gzip –>.gz
xz —>.xz
bzip2 –>.bz2
tar
tar --> 合并了 gzip,xz,bzip2
tarball --> 应用 tar 命令打的压缩包 --》归档文件 --》压缩文件 --》一个压缩包里能够蕴含很多的文件
tar 是能够对文件和文件夹进行压缩的
Compressed TAR Archive [compressed 压缩的 archive 归档]
https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.8.11.tar.xz
http://nginx.org/download/nginx-1.19.2.tar.gz
mysql-8.0.21-linux-glibc2.12-i686.tar.xz
https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/httpd-2.4.46.tar.bz2
配置 NGINX 服务器反对下载性能
(autoindex auto 主动 index 索引)
\# cd /usr/local/nginx/conf/ ==(注:配置目录)==
\#
\# vim nginx.conf ==(注 2:批改配置文件)即加上 autoindex on;这一行 ==
location / {
root html;(注 4:指定 nginx 的寄存网页的目录为 html--》网页根目录)index index.html index.htm;(注 5:配置 nginx 服务器反对的首页为 index.html 或者 index.htm index.html 的优先级要高,没有 index.html 的时候,就会去查找 index.htm)==autoindex on;(注 3:增加配置,让 nginx 反对显示文件夹里的内容)==
}
\# /usr/local/nginx/sbin/nginx -s reload 从新加载 nginx
压缩包上传
四. tar 命令
tar 命令
用处:制作归档文件、开释归档文件
格局:tar [选项]… 归档文件名 源文件或目录
tar [选项]... 归档文件名 [-C 目标目录]
常用命令选项
-c:创立 .tar 格局的包文件 create
-x:解开.tar 格局的包文件 extract 提取
-v:输入详细信息 verbose 冗余的
-f:示意应用归档文件 file
-t:列表查看包内的文件 list
常用命令选项
-C:解包时进入指定的指标文件夹
==-z:调用 gzip 程序进行压缩或解压 ==
==-j:调用 bzip2 程序进行压缩或解 ==
==-J:调用 xz 程序进行压缩或解压 ==
\=\=\= ==(经典组合)==
== 创立压缩包 ==
==tar -czf -->.tar.gz== ==tar cjf -->.tar.bz2== ==tar cJf -->.tar.xz==
== 创立压缩包到指定的门路 应用绝对路径 ==
\# tar czf /zhanghuayou/passwd.tar.gz ==/etc/passwd==
tar: 从成员名中删除结尾的“/”
== 查看压缩包里的内容 ==
==tar tf \*.tar.\*==
== 解压 –》默认解压到当前目录 ==
==tar xf \*.tar.\*== ==-C 解压到指定的门路 ==
\# tar xf boot_log_passwd.tar.gz ==-C== /zhanghuayou/
\# mkdir tar
\# cd tar
\# ls
\# tar czf passwd.tar.gz ==/etc/passwd==
==tar: 从成员名中删除结尾的“/”==
\# ls
passwd.tar.gz
\# tar tf passwd.tar.gz
==etc/passwd(注:/ 没有了)==
[root@sanchuang-linux tar]# ls
passwd.tar.gz
\# tar xf passwd.tar.gz
\# ls
==etc== passwd.tar.gz ==(注 2:解压后是文件夹 etc, 没有“/”)==
\# cd etc/
\# ls
passwd
\#
== 给文件夹打压缩包 ==
\# tar cJf boot.tar.xz /boot
\# tar czf boot.tar.gz /boot
\# tar cjf boot.tar.bz2 /boot
\# ==time tar czf boot.tar.gz /boot(注:压缩命令前接 time 能够看工夫)==
tar: 从成员名中删除结尾的“/”
real 0m8.467s
user 0m6.851s
sys 0m2.226s
\#
==(注:↓接 v 能够看过程,信息输入。个别写脚本不接 v)==
\# tar czvf boot_log_passwd.tar.gz /boot /var/log /etc/passwd ==(注:文件和目录)==
\# tar czf boot_log_passwd.tar.gz /boot /var/log /etc/passwd
tar: 从成员名中删除结尾的“/”
tar: 从硬连贯指标中删除结尾的“/”
\#
== 前面打包的文件如果压缩文件的名字一样,会笼罩 ==
五. 压缩练习 - 备份脚本
次要内容:
排错多个文件 exclude 排除 ==(难点)==
\# tar ==–exclude==\=/boot/{grub2,efi,loader} ==-czvf== no_grub_boot.tar.gz /boot
\# ==date +%Y%m%d%H%M%S==
20200924170954
以后的日期往后面推 10 天
\# ==date -d “10 days”==
如何失去命令的执行后果赋值给变量
== 办法 1:==
ctime=$(date +%F)
== 办法 2:反引号 ==
ctime=\`date +%F\`
命令的嵌套
== 设置工夫 -s==
\# ==date -s ‘2020-10-10’(注:调工夫)==
\# date -s ==’2020-10-10 9:53:00′(注:指定小时分钟秒)==
\# ==cal 看日历 == calendar(日历)
\# ==cal 2020== 看 2020 年日历
压缩练习:1. 在 windows 里应用 winrar 软件压缩 2 个文件,一个是.rar 格局的文件,一个是.zip 的文件,具体压缩那个文件,你本人定义
2. 将文件传输到 linux 零碎的 /lianxi 目录下,尝试解压.zip 的文件
# unzip
3. 复制 /etc/passwd 文件到 /lianxi 目录下,将 /lianxi 目录下的 passwd 文件压缩成 passwd.xz
# cp /etc/passwd . # xz passwd
4. 复制 /etc/ssh/sshd_config 文件到 /lianxi 目录下,而后进行压缩为 sshd_config.gz
# cp /etc/ssh/sshd_config . # gzip sshd_config
5. 查看 passwd.xz 里的内容,查看 sshd_config.gz 里的内容
# xzcat passwd.xz # zcat sshd_config.gz
6. 新建文件夹 /backup_sc,而后复制 /lianxi 下的 passwd.xz 和 sshd_config.gz 到 /backup_sc 目录里
7. 到 /backup_sc 目录里解压 passwd.xz 和 sshd_config.gz 文件
8. 将 /lianxi 下的 sshd_config.gz 传到 windows 零碎里看是否能够解压?
练习 8:
1. 创立一个目录在 /lianxi 下叫 tar
\# mkdir /lianxi/tar
2. 进入 tar 目录,复制 /etc/hosts 文件和 /etc/passwd 到 tar 目录下
\# cd /lianxi/tar # cp /etc/hosts . # cp /etc/passwd .
3. 复制 /boot 目录到 tar 目录下
\# cp /boot . -r
4. 将当前目录下的 boot 目录打包放在 /lianxi/tar 目录下叫 boot.tar.gz
\# tar czf boot.tar.gz boot
5. 查看 boot.tar.gz 文件里的内容
\# tar tf boot.tar.gz
6. 将 hosts 文件和 passwd 文件打包放到 host_passwd.tar.bz2 文件
\# tar cjf host_passwd.tar.bz2 hosts passwd
7. 查看 host_passwd.tar.bz2 文件里的内容
\# tar tf host_passwd.tar.bz2
8. 将 /boot/ 目录和 /etc/passwd、/var/log 目录备份到 /lianxi 目录下叫 boot_pw_log.tar.xz
\# tar cJf /lianxi/boot_pw_log.tar.xz /boot /etc/passwd /var/log
9. 新建 /bak 目录,而后将 /lianxi 目录下的 boot_pw_log.tar.xz 解压到 /bak 目录下
\# mkdir -p /bak # tar xf boot_pw_log.tar.xz -C /bak
10. 将 /boot 目录下的除 grub2 目录以外的所有文件都备份到 /bak 目录下叫 no-grub.tar.gz
tar czvf –exclude ==(难点)==
\# tar ==–exclude=/boot/grub2 -czvf== no_grub_boot.tar.gz /boot
centos8 里的(注:==–exclude=/boot/grub2 -czvf 前后不能错,grub2 不能接 /,-czvf - 不能省略 ==)
\# tar ==–exclude=/boot/grub2 -czvf== no_grub_boot.tar.gz /boot
centos7 里的
\# tar czvf no_grub2_boot.tar.gz /boot ==–exclude=/boot/grub2==
排错多个文件 exclude 排除 ==(难点)==
\# tar ==–exclude==\=/boot/{grub2,efi,loader} ==-czvf== no_grub_boot.tar.gz /boot
(注:目录构造 {} 示意多个)
练习:编写一个脚本实现备份 /var/log 目录下的所有文件到 /bak 目录下,要求文件名是蕴含当天日期,准确到秒,文件名例如:2013-6-6-2_30_20-log.tar.gz。同时要求删除 /bak 目录下七天前的备份文件,只保留最近 7 天的文件。
需要剖析:
== 年月日小时分钟秒 ==
== 工夫戳:年月日小时分钟秒 ==
取得以后的日期 date %Y year ==(注:年)== %m month (01..12) ==(注:月)== %M minute (00..59) ==(注:分钟)==
%d day of month (e.g., 01) ==(注:日)==
%H hour (00..23) ==(注:小时)==
%S second (00..60) ==(注:秒)==
%F full date; same as %Y-%m-%d ==(注:年月日)==
\# ==date +%Y%m%d%H%M%S==
20200924170954
\# ==date +%Y-%m-%d%H%M%S==
2020-09-24171008
\# ==date +%Y-%m-%d_%H_%M_%S==
2020-09-24_17_10_31
\#
以后的日期往后面推 10 天 ==(推迟时间)==
\# ==date -d “10 days”==
2020 年 10 月 04 日 星期日 17:21:27 CST
\# ==date -d 10days==
2020 年 10 月 04 日 星期日 17:21:37 CST
\#
\# ==date -d 10hours==
2020 年 09 月 25 日 星期五 03:22:13 CST
\#
如何失去命令的执行后果赋值给变量
== 办法 1:$()(更好,因为能够嵌套)==
ctime=$(date +%F)
== 办法 2:反引号(不能嵌套)==
ctime=\`date +%F\`
\# ==ctime=$(date +%F)==
\# echo $ctime
2020-09-24
\# ==sctime=\`date +%F\`==
\# echo $sctime
2020-09-24
\#
\# ==touch $(date +%F).txt==
\# sg=zhanghuayou
\# echo $sg
zhanghuayou
\# echo $sg1
(注:该行输入为空)
\# echo ==${sg}==1
zhanghuayou==1==
\#
删除 /bak 目录下七天前的备份文件
find /bak -type f -mtime +7 -name “*.tar.gz” -exec rm -rf {} \;
脚本名字:
backup_log.sh
命令的嵌套
\# which mkdir
/usr/bin/mkdir
\# rpm -qf /usr/bin/mkdir
coreutils-8.30-6.el8_1.1.x86_64
\# softname\===$(rpm -qf $(which mkdir))(注:$() 好,能够嵌套)==
\# echo $softname
==coreutils-8.30-6.el8_1.1.x86_64==
\# softname2\===\`rpm -qf \`which mkdir\`\`==
==rpm:未给出要查问的参数 ==
==mkdir: 短少操作数 ==
请尝试执行 “mkdir –help” 来获取更多信息。
\#
编写一个脚本实现 == 备份 ==/var/log 目录下的所有文件到 /bak 目录下,要求文件名是蕴含当天日期,准确到秒,文件名例如:2013-6-6-2_30_20-log==.tar.gz==。同时要求删除 /bak 目录下七天前的备份文件,只保留最近 7 天的文件。
== 通过文件名晓得应用 tar 命令,而不是 cp==
\# mkdir /lianxi/9_25
\# cd /lianxi/9_25
\# vim backup_log.sh
\#!/bin/bash
\# 取得以后的工夫,准确到秒
ctime=$(date +%Y%m%d%H%M%S)
\# 备份
mkdir -p /bak
tar czf /bak/${ctime}-log.tar.gz /var/log
\# 删除 7 天前的 == 备份文件 ==,只保留最近的 7 天内的文件
find /bak -type f -mtime +7 ==-name“*log.tar.gz”== -exec rm -rf {} \;
怎么验证删除 7 天前的文件?
答:调工夫
== 设置工夫 -s==
\# date
2020 年 09 月 25 日 星期五 09:53:18 CST
\# ==date -s ‘2020-10-10’(注:调工夫)==
2020 年 10 月 10 日 星期六 00:00:00 CST
\#
\# date -s ==’2020-10-10 9:53:00′(注:指定小时分钟秒)==
2020 年 10 月 10 日 星期六 09:53:00 CST
\#
\# date -s ‘2020-9-25 9:55:00’
2020 年 09 月 25 日 星期五 09:55:00 CST
\#
\# ==cal 看日历 == calendar(日历)
\# ==cal 2020== 看 2020 年日历