源码编译安装
scp /linux-soft/1/tools.tar.gz root@192.168.4.7:/root
ls /root
tar -tf /root/tools.tar.gz
tar -xf /root/tools.tar.gz -C /
tar -xf /tools/inotify-tools-3.13.tar.gz -C /usr/local #tar解包
yum -y install gcc make #安装开发工具gcc与make
rpm -q gcc make
cd /usr/local/inotify-tools-3.13
./configure #配置
./configure --help
./configure --prefix=/opt/myrpm
ls Makefile
make #编译
make install #安装
编译安装inotify-tools软件包
rsync 同步操作
- 同步与复制的差异
- 复制:完全拷贝源到目标
- 同步:增量拷贝,只传输变化过的数据
sync操作选项
选项 |
解析 |
-n |
测试同步过程,不做实际修改 |
--delete |
删除目标文件夹内多余的文档 |
-a |
归档模式,相当于-rlptgoD |
-v |
显示详细操作信息 |
-z |
传输过程中启用压缩/解压 |
本地同步
mkdir /mydir /todir
cp /etc/passwd /mydir
touch /mydir/1.txt
ls /mydir
rsync -av /mydir /todir
ls /todir
rsync -av /mydir/ /todir
ls /todir
touch /mydir/2.txt
rsync -av /mydir/ /todir
ls /todir
echo 123 > /mydir/1.txt
rsync -av /mydir/ /todir
ls /todir
rsync -av --delete /mydir/ /todir/
ls /mydir/
ls /todir/
touch /todir/a.txt
ls /todir/
rsync -av --delete /mydir/ /todir/
ls /todir/
ls /mydir/
远程同步
- 下行:rsync [...] user@host:远程目录 本地目录
下载
(将另一台虚拟机的数据同步到本地)
- 上行:rsync [...] 本地目录 user@host:远程目录
上传
(将本地的数据同步到另一台虚拟机)
- 虚拟机A的/mydir目录的内容与虚拟机B的/opt进行同步
rsync -av --delete /mydir/ root@192.168.4.207:/opt #虚拟机A
ls /opt/ #虚拟机B
实时数据同步
- 虚拟机A的/mydir/目录的内容与虚拟机B的/opt进行同步
ssh-keygen #虚拟机A
ls /root/.ssh/ #虚拟机A
ssh-copy-id root@192.168.4.207 #虚拟机B
rsync -av --delete /mydir/ root@192.168.4.207:/opt
inotifywait基本用法
inotifywait [选项] 目标文件夹
常用命令选项
选项 | 解析
---|---
-m | 持续监控(捕获一个事件后不退出)
-r | 递归监控、包括子目录及文件
-q | 减少屏幕输出信息
-e | 指定监视的 modify、move、create、delete、attrib 等
书写shell脚本(了解)
- 脚本:可以运行一个文件,实现某种功能
- 中文:新建用户zhangsan shell: useradd zhangsan
- 死循环:while循环
while 条件
do
重复执行的事情
done
vim /etc/rsync.sh
while /opt/myrpm/bin/inotifywait -rqq /mydir/
do
rsync -a --delete /mydir/ root@192.168.4.207:/opt
done
chmod a+x /etc/rsync.sh
/etc/rsync.sh &
jobs -l
kill 17707
数据库服务基础
- 数据库:存放数据的仓库
- 在数据库系统中,有很多的数据库,在每一个库中有很多的表格
常见的关系型 数据库管理系统
微软 |
SQL Server |
IBM |
DB2 |
甲骨文 |
Oracle、MySQL |
社区开源版 |
MariaDB |
部署MariaDB 数据库系统
yum -y install mariadb-server
systemctl restart mariadb
MariaDB基本使用
- Linux系统的管理指令不能使用
- 所有的数据库系统指令都必须以 ; 结尾
- 数据库系统的指令大部分不支持tab补全
mysql
create database nsd01;
show databases;
drop database nsd01;
show databases;
exit;
mysql
use mysql;
show tables;
show databases;
use test;
exit;
为数据库系统管理员设置密码
- mysqladmin [-u用户名] [-p[旧密码]] password '新密码'
- 数据库系统管理员:对于数据库系统有最高权限,名字为root,能够登陆数据系统的用户信息有mysql库中user表进行储存
- Linux系统管理员: 对于Linux系统有最高权限,名字为root,能够登陆Linux系统的用户信息/etc/passwd进行储存
mysqladmin -u root password '123'
mysql -u root -p
mysql -u root -p456
mysqladmin -u root -p123 password '456'
mysql -u root -p456
mysql -u root -p456
create database nsd01;
show databases;
exit;
传递备份好的数据文件users.sql到虚拟机A中
- 点击真机root选择其他位置,输入连接到服务器ftp地址
172.96.8.78
进入2104把users.sql拖动到真机的root下
ls /root
scp /root/users.sql root@192.168.4.7:/root
恢复数据到数据库
mysql -u root -p456 nsd01 < /root/users.sql
mysql -u root -p456
MariaDB [(none)]> use nsd01;
MariaDB [nsd01]> show tables;
+-------------------+
| Tables_in_nsd01 |
+-------------------+
| base |
| location |
+-------------------+
表格操作
- 增(insert) 删(delete) 改(update) 查(select)
–表字段、表记录
查(select)
- 格式: select 表字段,表字段,…… from 库名.表名;
select * from base;
select * from location;
use test;
select * from nsd01.base;
use nsd01;
select id,name from base;
select * from base where password='456';
select * from base where id='4';
select * from base where id='4' and password='123';
select * from base where id='4' or password='123';
增(insert)
- insert 表名 values (‘值’,‘值’,‘值’);
MariaDB [nsd01]> insert base values('10','dc','789');
MariaDB [nsd01]> insert base values('11','tcc','369');
MariaDB [nsd01]> select * from base ;
改(update)
- update 表名 set 表字段=‘新值’ where 表字段=’值’;
select * from base ;
update base set password='8888' where id='1';
select * from base ;
update base set password='9999' where id='2';
select * from base ;
删(delete)
delete from base where id='4' ;
select * from base ;
delete from base where id='3' ;
select * from base ;
制作链接 (连接)文件(制作快捷方式)
- 格式:ln -s /路径/源数据 /路径/快捷方式的名称 #软链接
ln -s /etc/sysconfig/network-scripts/ /ns
ls /
ls -l /ns
touch /ns/haha.txt
touch /ns/maohehaozi.txt
touch /ns/shukehebeita.txt
ls /etc/sysconfig/network-scripts/
- 软连接优势:可以针对目录与文件制作快捷方式
- 软连接缺点:源数据消失,快捷方式失效
- 格式:ln /路径/源数据 /路径/快捷方式的名称 #硬链接
rm -rf /opt/*
echo 123 > /opt/A.txt
ln -s /opt/A.txt /opt/B.txt
ln /opt/A.txt /opt/C.txt
ls /opt/
cat /opt/B.txt
cat /opt/C.txt
rm -rf /opt/A.txt
ls /opt/
cat /opt/B.txt
cat /opt/C.txt
- 硬链接优势:源数据消失,快捷方式仍然有效
- 硬链接缺点:只能针对文件制作快捷方式,不支持支持跨分区
加上-s就是软链接,不加-s就是硬链接。