diff --git "a/40\346\236\227\346\200\241\347\220\264/20240702_\350\241\245\345\205\205\345\221\275\344\273\244\357\274\214\351\205\215\347\275\256Apache2\347\232\204ssl\350\257\201\344\271\246.md" "b/40\346\236\227\346\200\241\347\220\264/20240702_\350\241\245\345\205\205\345\221\275\344\273\244\357\274\214\351\205\215\347\275\256Apache2\347\232\204ssl\350\257\201\344\271\246.md" new file mode 100644 index 0000000000000000000000000000000000000000..9c212f59b3894b9080df1a9fc29618c095c1abe9 --- /dev/null +++ "b/40\346\236\227\346\200\241\347\220\264/20240702_\350\241\245\345\205\205\345\221\275\344\273\244\357\274\214\351\205\215\347\275\256Apache2\347\232\204ssl\350\257\201\344\271\246.md" @@ -0,0 +1,249 @@ +# 补充命令 + +##### sort排序 + +```bash +sort 文件名 #正序 +sort -r 文件名 #倒叙 +sort -rn -t ' ' -k 2 文件名 +#-t ' '匹配分隔符 +#-k 2 比较第二列 +sort -u 文件名 #去重 +``` + +##### uniq去重 + +- sort 文件名 | uniq -c **先排序在去重 ** +- -c 统计出现次数 + +##### 统计文件行数 + +- wc -l 文件名 +- nl 文件名 +- cat -n 文件名 + +##### cut用法 + +```bash +cut -d ' ' -f 1,2 +#-d 指定分隔符 +#-f 指定要显示的列 +#-f 1-3 表示1-3列的全表示 +``` + +#### 三剑客(grep,awk,sed) + +##### grep + +- 参数 + - -i :忽略大小写 + - -v :不包含关键字的行 + - -r :归查找目录 + - -l :显示包含关键字的文件名 + - -c :计数匹配的行数 + - -n:显示匹配行的行号 + - -A:匹配行及后面 2 行 + - -B :匹配行及前面 2 行 + - -C :匹配行及前后 2 行 + +```js +grep "关键字" 文件(路径) +``` + +##### sed + +- ##### 替换 + + ```js + //把所有旧文本替换成新文本 + //g:全局,替换成所有新文本 + sed 's/旧文本/新文本/g' 文件.txt + sed 's/apple/orange/g' apple_red.txt //替换指定文本内容 + + //每一行的第一个旧文本被替换成新文本 + sed 's/旧文本/新文本/' 文件.txt + sed 's/apple/orange/' apple_red.txt + + //指定每一行的第几个旧文本替换成新文本 + sed 's/旧文本/新文本/指定第几个' 文件.txt + //指的是如果有相同的,那就指定第几个被替换 + sed 's/apple/orange/2' apple_red.txt //指定每一行的第二个旧文本替换成新文本 + + + //指定行数被替换 + sed '行数s/旧文本/新文本/g' 文件.txt + sed '2s/apple/orange/g' apple_red.txt //第二行里的apple都替换成orange + ``` + +- 删除 + + - d:删除行 + + ```js + sed '/指定内容的行/d' 文件.txt + sed '/apple/d' apple_red.txt //指定删除整行里有apple的 + ``` + +- 打印 + + - p:打印 + + ```js + sed -n '/apple/p' apple_red.txt //不加-n,会重复打印 + ``` + +- 插入 + + - a:行后追加一行 + - i:行前插入一行 + - c:整行被替换 + + ```js + //行后插入一行 + sed 'a\1' apple_red.txt //每一行行后追加1 + sed '2a\1' apple_red.txt //指定第二行行后追加1 + + //行前插入一行 + sed 'i\1' apple_red.txt //每一行行前插入1 + sed '2i\1' apple_red.txt //指定第二行行前插入1 + + //整行被替换 + sed 'c\1' apple_red.txt //每一行都被替换成1 + sed '2c\1' apple_red.txt //指定第二行被替换成1 + + //用关键字去定位所在的行,并且追加,插入,替换 + // 1. sed "/关键字/a\追加的内容" + // 2. sed "/关键字/i\插入的内容 + // 3. sed "/关键字/c\替换的内容 + sed "/apple/a\1" apple_red.txt //定位到指定的关键字,并且在行后插入内容 + sed "/apple/i\1" apple_red.txt //定位到指定的关键字,并且在行前插入内容 + sed "/apple/c\1" apple_red.txt //定位到指定的关键字,并且把它整行都被替换 + ``` + + ##### 如果不指定行数,那就每一行都会被插入/替换文本 + +- 结合多个命令**;**和-e + + ```js + sed 's/$/3333/;2s/apple/a/' apple_red.txt //在每行以3333结尾,指定第二行apple替换成a + sed -e 's/$/3333/' -e '2s/apple/a/' apple_red.txt + ``` + +- 修改文件并保存 + + - -i 直接修改 + + ```js + sed -i '修改的内容' 文件.txt + sed -i '/apple/d' apple_red.txt + ``` + + + +# 安装Apache2并且测试它 + +- 更新软件包列表 + + ```bash + apt update + ``` + +- 安装 + + ```bash + apt install apache2 + ``` + +- 启用Apache2 + + ```bash + systemctl start apache2 + ``` + +- 修改端口8080 + + ```bash + /etc/apache2/ports.conf + ``` + + ![image-20240702125638369](./imgs/image-20240702125638369.png) + +- 在阿里云创建安全组8080端口 + +- 重新启用 + + ```bash + systemctl restart apache2 + ``` + +- 网页输入http://http://47.115.204.225:8080 + + ![image-20240702130244000](./imgs/image-20240702130244000.png) + +# 配置Apache2的ssl证书 + +- Apache/创建ssl文件夹来存放证书 + + ![image-20240702114007552](./imgs/image-20240702114007552.png) + +- 启用SSL模块 + + ```bash + a2enmod ssl + ``` + +- 重新配置系统 + + ```bash + dpkg-reconfigure locales + ``` + +- 在Apache/sistes-enabled创建ssl.conf + + ```bash + + ServerName 你自己的域名 + ServerAlias 域名的别名 + ServerAdmin webmaster@localhost + DocumentRoot 你自己网站的目录 + ErrorLog ${APACHE_LOG_DIR}/error.log + CustomLog ${APACHE_LOG_DIR}/access.log combined + SSLEngine on + SSLHonorCipherOrder on + SSLProtocol TLSv1.1 TLSv1.2 TLSv1.3 + SSLCipherSuite ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4 + SSLCertificateFile 你自己的证书public.crt文件路径 + SSLCertificateKeyFile 你自己证书.key文件路径 + SSLCertificateChainFile 你自己证书chain.crt文件路径 + + ``` + + ```bash + + ServerName keleya.cn + ServerAlias www.keleya.cn + ServerAdmin webmaster@localhost + DocumentRoot /var/www/html + ErrorLog ${APACHE_LOG_DIR}/error.log + CustomLog ${APACHE_LOG_DIR}/access.log combined + SSLEngine on + SSLHonorCipherOrder on + SSLProtocol TLSv1.1 TLSv1.2 TLSv1.3 + SSLCipherSuite ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4 + SSLCertificateFile /etc/apache2/ssl/www.keleya.cn_public.crt + SSLCertificateKeyFile /etc/apache2/ssl/www.keleya.cn.key + SSLCertificateChainFile /etc/apache2/ssl/www.keleya.cn_chain.crt + + ``` + +- 在阿里云创建安全组444的 + + ![image-20240702124703847](./imgs/image-20240702124703847.png) + +- 重启 + + ```bash + systemctl restart apache2 + ``` + + \ No newline at end of file diff --git "a/40\346\236\227\346\200\241\347\220\264/20240704_\346\225\260\346\215\256\345\272\223\345\244\207\344\273\275\357\274\214\350\277\230\345\216\237.md" "b/40\346\236\227\346\200\241\347\220\264/20240704_\346\225\260\346\215\256\345\272\223\345\244\207\344\273\275\357\274\214\350\277\230\345\216\237.md" new file mode 100644 index 0000000000000000000000000000000000000000..bbdeae7e60d70e83f72f86837f87b3cd1cd36858 --- /dev/null +++ "b/40\346\236\227\346\200\241\347\220\264/20240704_\346\225\260\346\215\256\345\272\223\345\244\207\344\273\275\357\274\214\350\277\230\345\216\237.md" @@ -0,0 +1,102 @@ +1. 一般默认情况下,即备份数据又备份结构 +2. + +##### 存放数据库文件路径 + +```bash +/var/lib/mysql +``` + +#### 备份——mysqldump + +1. 只备份库,不包含建库语句,如果要恢复要指定库 + - 解决方法: + 1. 恢复是指定好数据库 + 2. 在备份文件添加库 + +#### 恢复 + +1. ##### mysql + + ```bash + mysql -u root -p 库名 < 要恢复的文件 + ##前提是库名是存在的 + ##只要库名存在,就会登录并使用库名 + ``` + +2. ##### source + + ```bash + use 库名 ##要在mysql里使用库,并且这个库是存在的 + source 备份的路 + ``` + +##### 命令用法 + +- 单个备份 + + ```BASH + mysqldump -u root -p 库名 > 备份的路径 ##备份 + mysql -u root -p 库名 < 路径 ##恢复 + ``` + +- 指定多库 + + ```bash + mysqldump -u root -p --databases 库1 库2 > 备份的路径 ##备份 + mysql -u root -p < 路径 ##恢复 + ``` + +- 所有库 + + ```bash + mysqldump -u root -p --all --databases > 备份的路径 ##备份 + mysql -u root -p 库名 < 路径 ##恢复 + ``` + +- 单个表 + + ```bash + mysqldump -u root -p 库名 表名 > 备份的路径 ##备份 + mysql -u root -p 库名 < 路径 ##恢复 + ``` + +- 多个表 + + ```bash + mysqldump -u root -p 库名 表1 表2 > 备份的路径 ##备份 + mysql -u root -p 库名 < 路径 ##恢复 + ``` + +- 备份字段结构(不要数据) + + ```bash + mysqldump -u root -p --no-data 库名 表1 > 备份的路径 + ## 如果不写表名,就会备份全部表的结构 + ## 如果写了表名,就是指定表名里的表结构 + ``` + +- 备份数据 + + ```bash + mysqldump -u root -p --no-create-info 库名 表1 > 备份的路径 + ## 如果不写表名,就会备份全部表的数据 + ## 如果写了表名,就是指定表名里的表数据 + ``` + +- 备份数据并且压缩 + + ```bash + mysqldump -u root -p 库名 |gzip > 备份的路径 + ``` + +- 解压并且还原 + + ```bash + gzip -dk < 路径 | mysqldump -u root -p 库名 + ##先解压压缩文件,并且把文件还原到数据库里,前提库名是存在的 + ## -d 解压 + ## -k 保留原压缩文件 + ``` + + \ No newline at end of file diff --git "a/40\346\236\227\346\200\241\347\220\264/20240707_Postgresql\345\256\211\350\243\205.md" "b/40\346\236\227\346\200\241\347\220\264/20240707_Postgresql\345\256\211\350\243\205.md" new file mode 100644 index 0000000000000000000000000000000000000000..63f3f16ee27c4e4588785c17cb1c8a55c7663837 --- /dev/null +++ "b/40\346\236\227\346\200\241\347\220\264/20240707_Postgresql\345\256\211\350\243\205.md" @@ -0,0 +1,116 @@ +### Postgresql安装 + +- 去官网安装下载 + + - vim postgresql.bash脚本 + + ```bash + sudo apt install curl ca-certificates + sudo install -d /usr/share/postgresql-common/pgdg + sudo curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc --fail https://www.postgresql.org/media/keys/ACCC4CF8.asc + sudo sh -c 'echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' + sudo apt update + sudo apt -y install postgresql + ``` + + - 读取脚本文件 + + ```bash + sh postgresql.bash + ``` + +- 更新 + + ```bash + apt update + ``` + +- 配置远程连接 + + 1. 编辑 /etc/postgresql/16/main/postgresql.conf 文件 + + - 修改监听 + + ![image-20240704171736177](./imgs/image-20240704171736177.png) + + 2. 编辑/etc/postgresql/16/main/pg_hba.conf 文件 + + - 允许所有IP地址通过密码连接 + + ![image-20240704173806336](./imgs/image-20240704173806336.png) + + 3. 端口 + + - 防火墙允许5432端口 + - 阿里云开5432端口 + + 4. 重启 + + ```bash + systemctl restart postgresql + ``` + +- 修改密码 + + ```bash + sudo -u postgres psql ##进入到PostgreSQL模式 + ALTER USER postgres PASSWORD '密码'; ##修改密码 + ``` + +- 远程登录 + + ```bash + psql -p 5432 -h 47.115.204.225 -U postgres ##postgres是用户名 + ``` + + ```BASH + su postgres ##切换用户 + psql ##进入postgresql界面 + ``` + +- 数据库命令 + + - \l :列出所有的数据库 + - \c 数据库:使用数据库 + - \dt:查看所有表 + - \d:查看所有表结构 + - \password:设置密码 + + + +##### apt + +- 搜索 + + ```bash + apt search * |grep 关键字 + ``` + +- 删除 + + ```bash + apt --purge remove postgreql ##卸载软件包本身,还会删除与该软件包相关的配置文件。 + apt autoremove postgresql ##卸载包 + find / -name postgre* + find / -name postgre* -exec rm -rf {} \; + ``` + +##### systemctl查看多个状态 + +```bash +systemctl status 服务名1 服务名2 +systemctl status 服务名* +``` + +##### 备份 + +```bash +pg_dump -U 用户名 -h IP地址 -d 数据库 -f 备份文件到路径 +``` + +##### 还原 + +```bash +psql -h ip地址 -U 用户名 -f 导入的数据位置 +``` + diff --git "a/40\346\236\227\346\200\241\347\220\264/Linux Debian\345\256\211\350\243\205mysql.md" "b/40\346\236\227\346\200\241\347\220\264/Linux Debian\345\256\211\350\243\205mysql.md" new file mode 100644 index 0000000000000000000000000000000000000000..47ce234327d6f6305e2c5edb8ce5a00b24d4c81b --- /dev/null +++ "b/40\346\236\227\346\200\241\347\220\264/Linux Debian\345\256\211\350\243\205mysql.md" @@ -0,0 +1,50 @@ +#### Linux Debian安装mysql + +https://www.sjkjc.com/posts/install-mysql8-on-debian-12/ + +- 更新源 + + - 先备份 + + ```bash + cp -a /etc/apt/sources.list /etc/apt/sources.list.bak + ``` + + - 编辑源 + + ```bash + vim sudo cp -a /etc/apt/sources.list + ``` + + - 更新源并且更新软件 + + ```bash + apt update && sudo apt upgrade -y + ``` + +- 安装mysql + + ```bash + apt update -y #更新 + wget https://repo.mysql.com/mysql-apt-config_0.8.30-1_all.deb -P /tmp ##30是目前最新版本 如果wget用不了就下载 + dpkg -i /tmp/mysql-apt-config_0.8.30-1_all.deb + ``` + + ![image-20240703095533460](./imgs/image-20240703095533460.png) + + ```bash + apt install -y mysql-server ##安装mysql + ##安装完后会设置密码并且确认密码 + + systemctl start mysql ##启用mysql + systemctl enable mysql ##开机自启动 + systemctl status mysql ##查看mysql状态 + + mysql -u root -p ##登录mysql(也可以修改密码) + ALTER USER 'root'@'localhost' IDENTIFIED BY '修改密码'; + exit ##退出 + ``` + + - 修改密码成功显示 + + ![image-20240703100029685](./imgs/image-20240703100029685.png) \ No newline at end of file diff --git "a/40\346\236\227\346\200\241\347\220\264/imgs/image-20240702114007552.png" "b/40\346\236\227\346\200\241\347\220\264/imgs/image-20240702114007552.png" new file mode 100644 index 0000000000000000000000000000000000000000..78420fc932d610bbe3403d02db501d4ec597171b Binary files /dev/null and "b/40\346\236\227\346\200\241\347\220\264/imgs/image-20240702114007552.png" differ diff --git "a/40\346\236\227\346\200\241\347\220\264/imgs/image-20240702124703847.png" "b/40\346\236\227\346\200\241\347\220\264/imgs/image-20240702124703847.png" new file mode 100644 index 0000000000000000000000000000000000000000..400fdb8ade401390f6a448bc28504ef85803599c Binary files /dev/null and "b/40\346\236\227\346\200\241\347\220\264/imgs/image-20240702124703847.png" differ diff --git "a/40\346\236\227\346\200\241\347\220\264/imgs/image-20240702125638369.png" "b/40\346\236\227\346\200\241\347\220\264/imgs/image-20240702125638369.png" new file mode 100644 index 0000000000000000000000000000000000000000..fbc8c922a8f157f9e8c208949eb2cc56346e59e0 Binary files /dev/null and "b/40\346\236\227\346\200\241\347\220\264/imgs/image-20240702125638369.png" differ diff --git "a/40\346\236\227\346\200\241\347\220\264/imgs/image-20240702130244000.png" "b/40\346\236\227\346\200\241\347\220\264/imgs/image-20240702130244000.png" new file mode 100644 index 0000000000000000000000000000000000000000..db3d6bb39eb9575566a76161624170142a9383c1 Binary files /dev/null and "b/40\346\236\227\346\200\241\347\220\264/imgs/image-20240702130244000.png" differ diff --git "a/40\346\236\227\346\200\241\347\220\264/imgs/image-20240703095533460.png" "b/40\346\236\227\346\200\241\347\220\264/imgs/image-20240703095533460.png" new file mode 100644 index 0000000000000000000000000000000000000000..194ae0e72d653942f23198c5a966955c7985da2a Binary files /dev/null and "b/40\346\236\227\346\200\241\347\220\264/imgs/image-20240703095533460.png" differ diff --git "a/40\346\236\227\346\200\241\347\220\264/imgs/image-20240703100029685.png" "b/40\346\236\227\346\200\241\347\220\264/imgs/image-20240703100029685.png" new file mode 100644 index 0000000000000000000000000000000000000000..d58e97d7f1d74091a3d4f8019276983216f689db Binary files /dev/null and "b/40\346\236\227\346\200\241\347\220\264/imgs/image-20240703100029685.png" differ diff --git "a/40\346\236\227\346\200\241\347\220\264/imgs/image-20240704171736177.png" "b/40\346\236\227\346\200\241\347\220\264/imgs/image-20240704171736177.png" new file mode 100644 index 0000000000000000000000000000000000000000..5ed0e6efbea0656d082109cbb35d5be65e169410 Binary files /dev/null and "b/40\346\236\227\346\200\241\347\220\264/imgs/image-20240704171736177.png" differ diff --git "a/40\346\236\227\346\200\241\347\220\264/imgs/image-20240704173806336.png" "b/40\346\236\227\346\200\241\347\220\264/imgs/image-20240704173806336.png" new file mode 100644 index 0000000000000000000000000000000000000000..3c122ee8ba847c99da43ef4087b8e5f9bd0091c3 Binary files /dev/null and "b/40\346\236\227\346\200\241\347\220\264/imgs/image-20240704173806336.png" differ