首页
统计
墙纸
留言
Search
1
PVE8优化
12 阅读
2
内核版本 4.9 以上的 Linux 系统开启/关闭 BBR 的方法
10 阅读
3
MySQL创建数据库与创建用户以及授权
7 阅读
4
选择相机的曝光模式
6 阅读
5
jenkins根据分支、文件夹打包
5 阅读
web前端
Vue
CSS
javascript
React
那些年爬过过的坑
ES6
TypeScrippt
ES7
javascript图灵 - 总结
Node
面试总结
React-Native
Web优化
基础
AngularJS
拍摄
Flutter
Dart
Docker
Linux
mysql
PVE
登录
/
注册
Search
标签搜索
vue+elementui
Cicada
累计撰写
151
篇文章
累计收到
6
条评论
首页
栏目
web前端
Vue
CSS
javascript
React
那些年爬过过的坑
ES6
TypeScrippt
ES7
javascript图灵 - 总结
Node
面试总结
React-Native
Web优化
基础
AngularJS
拍摄
Flutter
Dart
Docker
Linux
mysql
PVE
页面
统计
墙纸
留言
搜索到
142
篇与
的结果
2024-04-28
Debian 12 / Ubuntu 22.04 使用源安装 LAMP 教程
本文将介绍使用官方源和第三方源在 Debian 12 和 Ubuntu 22.04 安装最新版 Apache 2 + PHP + MySQL 的教程,并且可以自行选择 PHP 版本。PS:本文同时适用于 Debian 11 Bullseye,Debian 10 Buster,Ubuntu 20.04 Focal 以及 Ubuntu 22.04 Jammy以下操作需要在 root 用户下完成,请使用 sudo -i 或 su root 切换到 root 用户进行操作。[](#1、更新系统并安装部分必要软件)1、更新系统并安装部分必要软件apt update apt upgrade -y apt dist-upgrade -y apt install curl vim wget gnupg dpkg apt-transport-https lsb-release ca-certificates如果您通过 iso 方式安装 Debian 11 并且设置了 root 密码,则默认不带 sudo 包,使用 apt install sudo 安装即可[](#2、增加-ondrej-sury-大神打包的-php-源并安装-php-8-x)2、增加 Ondřej Surý 大神打包的 PHP 源并安装 PHP 8.x和 LEMP 安装方法一样,我们还是使用 Ondřej Surý 大佬打包的 PHP 源。至于为啥先装 PHP 再装 Apache 2,因为装了 PHP 以后 Apache 2 会识别你 PHP 版本然后生成对应的配置文件?[](#2-1-debian-和-ubuntu-安装-lamp-区别)2.1 Debian 和 Ubuntu 安装 LAMP 区别唯一区别就是 PHP 和 Apache 2 的安装添加源方法不一样,其他的步骤都一毛一样。[](#2-2-加入大神做好的源)2.2 加入大神做好的源wget -O /usr/share/keyrings/php.gpg https://packages.sury.org/php/apt.gpg echo "deb [signed-by=/usr/share/keyrings/php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.listadd-apt-repository ppa:ondrej/php[](#2-3-更新系统源)2.3 更新系统源apt update apt upgrade -y[](#2-4-安装自己需要的-php-版本)2.4 安装自己需要的 PHP 版本这个源目前默认的 PHP 是 8.3.x,如果您需要其他版本,那么请修改对应的 PHP 版本号 (注意配置文件哦)。这里举例 WordPress 需要的部分 PHP 包安装 PHP 8.3.x:apt install php8.3-{fpm,cli,mysql,curl,gd,mbstring,xml,zip,imap,opcache,soap,gmp,bcmath} -y安装 PHP 8.2.x:apt install php8.2-fpm php8.2-cli php8.2-mysql php8.2-curl php8.2-gd php8.2-mbstring php8.2-xml php8.2-zip php8.2-imap php8.2-opcache php8.2-soap php8.2-gmp php8.2-bcmath -y安装 PHP 8.1.xapt install php8.1-fpm php8.1-cli php8.1-mysql php8.1-curl php8.1-gd php8.1-mbstring php8.1-xml php8.1-zip php8.1-imap php8.1-opcache php8.1-soap php8.1-gmp php8.1-bcmath -y以下版本 PHP 已经 EOL,PHP 官方不再提供支持,请尽快更新您的程序兼容最新的 PHP,如果您的程序还未兼容,建议鞭策开发者安装 PHP 8.0.xapt install php8.0-fpm php8.0-cli php8.0-mysql php8.0-curl php8.0-gd php8.0-mbstring php8.0-xml php8.0-zip php8.0-imap php8.0-opcache php8.0-soap php8.0-gmp php8.0-bcmath -y安装 PHP 7.4.xapt install php7.4-fpm php7.4-cli php7.4-mysql php7.4-curl php7.4-gd php7.4-mbstring php7.4-xml php7.4-xmlrpc php7.4-zip php7.4-json php7.4-imap php7.4-opcache php7.4-soap php7.4-gmp php7.4-bcmath -y安装 PHP 7.3.xapt install php7.3-fpm php7.3-mysql php7.3-curl php7.3-gd php7.3-mbstring php7.3-xml php7.3-xmlrpc php7.3-zip php7.3-opcache安装 PHP 7.2.x (PHP 7.2 开始已经不支持 mcrypt 组件)apt install php7.2-fpm php7.2-mysql php7.2-curl php7.2-gd php7.2-mbstring php7.2-xml php7.2-xmlrpc php7.2-zip php7.2-opcache安装 PHP 7.1.xapt install php7.1-fpm php7.1-mysql php7.1-curl php7.1-gd php7.1-mbstring php7.1-mcrypt php7.1-xml php7.1-xmlrpc php7.1-zip php7.1-opcache安装 PHP 7.0.xapt php7.0-fpm php7.0-mysql php7.0-curl php7.0-gd php7.0-mbstring php7.0-mcrypt php7.0-xml php7.0-xmlrpc php7.0-zip php7.0-opcache安装 PHP 5.6.xapt install php5.6-fpm php5.6-mysql php5.6-curl php5.6-gd php5.6-mbstring php5.6-mcrypt php5.6-xml php5.6-xmlrpc php5.6-zip php5.6-opcache如果希望安装其他组件,可以通过搜索看看有没有对应的包apt-cache search php8.3* | grep php修改 php.ini 防止跨目录攻击,如果安装的 PHP 8.2.x 请相应修改 /etc/php/8.3/fpm/php.ini PHP 7.4.x 请相应修改 /etc/php/7.4/fpm/php.inised -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/' /etc/php/8.3/fpm/php.ini 修改 php.ini 增加上传大小限制sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 10M/' /etc/php/8.3/fpm/php.ini sed -i 's/post_max_size = 8M/post_max_size = 10M/' /etc/php/8.3/fpm/php.ini您也可以同时安装多个 PHP 版本,然后使用以下命令选择系统默认的 PHP 版本:update-alternatives --config php[](#3、增加-ondrej-sury-大神打包的-apache-2-源并安装)3、增加 Ondřej Surý 大神打包的 Apache 2 源并安装这里我们推荐 Ondřej Surý 打包的 Apache 2 源。[](#3-1-debian-和-ubuntu-安装-lamp-区别)3.1 Debian 和 Ubuntu 安装 LAMP 区别唯一区别就是 Apache 2 和 PHP 的安装添加源方法不一样,其他的步骤都一毛一样。[](#3-2-首先增加-apache-源)3.2 首先增加 Apache 源wget -O /usr/share/keyrings/apache2.gpg https://packages.sury.org/apache2/apt.gpg echo "deb [signed-by=/usr/share/keyrings/apache2.gpg] https://packages.sury.org/apache2/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/apache2.listadd-apt-repository ppa:ondrej/apache2[](#3-3-接着更新并接安装-apache-2-4)3.3 接着更新并接安装 Apache 2.4apt update apt upgrade -y apt install apache2 -y安装完毕后,我们可以使用 apache2 -v 命令看到 Apache 2 已经是最新的 2.4 版本了root@debian ~ # apache2 -v Server version: Apache/2.4.54 (Debian) Server built: 2022-06-08T16:00:36[](#3-4-apache-2-开启-php-fpm-支持)3.4 Apache 2 开启 PHP-FPM 支持首先,需要开启 Apache 2 的 PHP-FPM 支持,我们以 PHP 8.3 为例,按照自己的需求,可以开启如下模块a2enconf php8.3-fpm a2enmod proxy_fcgi a2enmod headers a2enmod http2 a2enmod remoteip a2enmod ssl a2enmod rewrite a2enmod expires a2enmod deflate a2enmod mime a2enmod setenvif然后我们重启 PHP-FPM 服务systemctl restart php8.3-fpm对应 PHP 7.4.x 命令如下systemctl restart php7.4-fpmApache 2 参考配置文件如下,因为默认 Debian 的 Apache 2 默认配置已经使用了 example.com 这个域名,所以我们以 example.org 为例,新建立个 /etc/apache2/sites-available/example.org.confcat >> /etc/apache2/sites-available/example.org.conf << EOF <VirtualHost *:80> ServerName example.org DocumentRoot /var/www/example.org DirectoryIndex index.php index.html index.htm ErrorLog ${APACHE_LOG_DIR}/example.org.error.log CustomLog ${APACHE_LOG_DIR}/example.org.access.log combined <Directory /var/www/example.org> Options FollowSymLinks AllowOverride All Require all granted </Directory> </VirtualHost> EOF然后使用 a2ensite 命令使其生效a2ensite example.org.conf如果不需要这个 vhost 的时候可以使用 a2dissite example.org.conf 命令移除检测是否已经软链接到 /etc/apache2/sites-enabled 目录root@debian ~ # ls /etc/apache2/sites-enabled 000-default.conf example.org.conf到这里基本没有问题,我们可以执行 apache2ctl configtest 命令检查配置文件是否出错root@debian ~ # apache2ctl configtest Syntax OK显示 Syntax OK 则说明所有配置文件均无问题,可以重启 Apache 2 使我们的配置生效systemctl restart apache2我们的目录在 /var/www/example.org,我们先创建这个目录mkdir -p /var/www/example.org然后创建一个 phpinfo.php 并输入 phpinfo() 函数cat >> /var/www/example.org/phpinfo.php << EOF <?php phpinfo(); ?> EOF好了,此时在浏览器输入 http://example.org/phpinfo.php,如果看到经典的 phpinfo 页面则说明安装成功,如果不成功,请仔细对比步骤查找哪里出错或在烧饼博客下方留言。[](#4、安装-mariadb)4、安装 MariaDB这里我们使用 MariaDB 作为 MySQL 的代替[](#4-1-首先,添加并导入-mariadb-的官方源)4.1 首先,添加并导入 Mariadb 的官方源按照官方的教程导入 GPG下载 GPG Key:curl -sSL https://mariadb.org/mariadb_release_signing_key.asc | gpg --dearmor > /usr/share/keyrings/mariadb.gpg然后添加 MariaDB 的源echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/mariadb.gpg] https://mirror-cdn.xtom.com/mariadb/repo/10.11/debian $(lsb_release -sc) main" > /etc/apt/sources.list.d/mariadb.listecho "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/mariadb.gpg] https://mirror-cdn.xtom.com/mariadb/repo/10.11/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/mariadb.list国内可以用清华 TUNA 的源echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/mariadb.gpg] https://mirrors.tuna.tsinghua.edu.cn/mariadb/repo/10.6/debian $(lsb_release -sc) main" > /etc/apt/sources.list.d/mariadb.listecho "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/mariadb.gpg] https://mirrors.tuna.tsinghua.edu.cn/mariadb/repo/10.6/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/mariadb.list您也可以在这儿找到更多的 MariaDB 源[](#4-2-接着更新一下系统)4.2 接着更新一下系统[](#4-3-然后直接安装最新稳定版-mariadb)4.3 然后直接安装最新稳定版 MariaDBapt install mariadb-server mariadb-client安装完毕后强烈推荐使用 mariadb-secure-installation 命令做一次安全设置[](#4-4-创建数据库并测试)4.4 创建数据库并测试开启数据库之前,您可以使用 pwgen 这个小工具或者随机密码生成器生成一个强大的随机密码,比如 32 位,然后随意挑选一个使用apt install pwgen pwgen 32使用 MySQL root 用户登陆,因为默认使用 Unix domain socket 模式,所以本机不需要 MySQL root 密码即可登录创建数据库 example_databaseCREATE DATABASE example_database DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;创建用户名 example_user 并赋予权限GRANT ALL ON example_database.* TO 'example_user'@'localhost' IDENTIFIED BY '这里改成您要设置的强大的没人能猜出来的随机的密码';刷新 MySQL 权限没问题以后就可以退出了新建立一个 /var/www/example.org/mysql-test.php 文件并测试cat >> /var/www/example.org/mysql-test.php << EOF <?php \$dbname = 'example_database'; //MySQL 数据库名 \$dbuser = 'example_user'; //MySQL 用户名 \$dbpass = '您的强大的没人可以猜出来的密码'; \$dbhost = 'localhost'; //安装在本地就用 localhost \$link = mysqli_connect(\$dbhost, \$dbuser, \$dbpass) or die("Unable to Connect to '\$dbhost'"); mysqli_select_db(\$link, \$dbname) or die("Could not open the db '\$dbname'"); \$test_query = "SHOW TABLES FROM \$dbname"; \$result = mysqli_query(\$link, \$test_query); \$tblCnt = 0; while(\$tbl = mysqli_fetch_array(\$result)) { \$tblCnt++; #echo \$tbl[0]."<br />\n"; } if (!\$tblCnt) { echo "MySQL is working fine. There are no tables."; } else { echo "MySQL is working fine. There are \$tblCnt tables."; } ?> EOF创建完毕后访问 http://example.org/mysql-test.php 如果出现 MySQL is working fine. There are no tables. 则说明 MySQL 工作正常。[](#5、安装-mysql-8-0-可选)5、安装 MySQL 8.0 (可选)如果您必须使用某些 MySQL 8.0 才有的功能,那么可以按照 MySQL 官网的教程安装 MySQL 8.0*注意:*除非您知道您在做什么,否则不要同时安装 MySQL 和 MariaDB[](#5-1-添加-apt-源)5.1 添加 apt 源wget https://repo.mysql.com/mysql-apt-config_0.8.29-1_all.deb dpkg -i mysql-apt-config_0.8.29-1_all.deb国内的机器可以在添加完成后修改为清华 TUNA 源,您可以修改 /etc/apt/sources.list.d/mysql-community.list 文件,替换成如下内容deb https://mirrors.tuna.tsinghua.edu.cn/mysql/apt/debian $(lsb_release -sc) mysql-5.6 mysql-5.7 mysql-8.0 mysql-tools[](#5-2-安装-mysql-8-0)5.2 安装 MySQL 8.0apt update apt install mysql-server -y默认 MySQL 会安装最新的 8.0 版本,如果您需要更低的版本,比如 5.6 或 5.7,可以使用如下命令:dpkg-reconfigure mysql-apt-config您可能需要设置一个强大的 root 密码,接下来的步骤和 MariaDB 基本相同,把 mariadb 命令换成 mysql 命令即可,本文不再赘述。好了,以上就是基本的 Debian 11.x “Bullseye” 安装最新版 LAMP 的教程,如有问题可以随时发评论留言讨论。
2024年04月28日
2 阅读
0 评论
0 点赞
2024-04-28
Debian12 跟换软件源
设置网络代理export https_proxy=http://userName:password@127.0.0.1:1080export http_proxy=http://userName:password@127.0.0.1:1080安装vimapt install vim更换源vim /etc/apt/sources.list中科大源deb https://mirrors.ustc.edu.cn/debian/ bookworm main contrib non-free non-free-firmware deb-src https://mirrors.ustc.edu.cn/debian/ bookworm main contrib non-free non-free-firmware deb https://mirrors.ustc.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware deb-src https://mirrors.ustc.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware deb https://mirrors.ustc.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware deb-src https://mirrors.ustc.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware deb https://mirrors.ustc.edu.cn/debian-security/ bookworm-security main contrib non-free non-free-firmware deb-src https://mirrors.ustc.edu.cn/debian-security/ bookworm-security main contrib non-free non-free-firmware阿里源deb https://mirrors.aliyun.com/debian/ bookworm main non-free non-free-firmware contrib deb-src https://mirrors.aliyun.com/debian/ bookworm main non-free non-free-firmware contrib deb https://mirrors.aliyun.com/debian-security/ bookworm-security main deb-src https://mirrors.aliyun.com/debian-security/ bookworm-security main deb https://mirrors.aliyun.com/debian/ bookworm-updates main non-free non-free-firmware contrib deb-src https://mirrors.aliyun.com/debian/ bookworm-updates main non-free non-free-firmware contrib deb https://mirrors.aliyun.com/debian/ bookworm-backports main non-free non-free-firmware contrib deb-src https://mirrors.aliyun.com/debian/ bookworm-backports main non-free non-free-firmware contrib更新apt update跟新依赖apt upgrade
2024年04月28日
1 阅读
0 评论
0 点赞
2024-04-26
戴尔R630
网络配置服务器开机按F2进入System Setup并选择iDRAC Settings。然后选择Network。确认Enable NIC为Enable状态, NIC Selection下 选择Dedicated(专用网口) 或者LOM1~LOM4(共享服务器1-4号网口)并正确连接网线。IDRAC Enterprise版本推荐使用Dedicated的方式进行连接。下拉右侧的滚动条,找到IPV4 SETTINGS的选项,启用IPV4并设置IP地址、网关和子网掩码。(例如:192.168.100.50、192.168.100.1、255.255.255.0)。注:如果iDrac密码忘记,可以使用以下步骤。服务器开机按提示,我们按F10进入到IDRAC设置项:(或者开机启动后按F2、进入BIOS页面)选择iDRAC Settings。3、找到User Configuration、进入。4、选择Change Password、回车重置密码。5、再输入一遍确认:RAID阵列1、启动物理服务器F2进入BIOS2、选择 Device settings3、选择带有RAID标识的项4、选择Configuration Management注:如果是之前做过RAID,那么你最好是clean清理下硬盘中的内容再来做RAID,免得因为残存数据影响使用。5、接着Create Virtual Disk6、选择你要做的RAID的级别 + Select Physical Disks选择硬盘,接着选择Apply Changes
2024年04月26日
3 阅读
0 评论
0 点赞
2024-04-17
workers
将Cloudflare的免费节点固定IP,防止IP不稳定,解锁GPT、NETFLIX,把节点挂在APPLE TV上,享受4K的流媒体,享受workers反代CDN的vless节点的乐趣!获得CF的CDN IP工具:1、https://github.com/badafans/better-cloudflare-ip2、https://github.com/XIU2/CloudflareSpeedTest一、如果获取CF中转IP(即反代IP)1、zip.baipiao.eu.org2、电报机器人:@cf\_push3、合并多个txt文档技巧:新建txt文件,输入type *.txt>>all.txt,重命名格式为.bat后,运行。自动合并生成。4、文本排重工具:https://www.toolhelper.cn/Char/TextFilter5、在线批量IP地理位置查找工具:https://reallyfreegeoip.org/bulk6、利用“CloudflareSpeedTest”工具来测速:7、在该软件当时文件栏上输出:cmd,回车键8.1、直接软件测:CloudflareST.exe -tll 40 -tl 200 -f 文件名.txt(下载速度测不了)8.2、有测速地址:CloudflareST.exe -url https://down.heleguo.top/download/300MB.zip -tl 200 -sl 5 -tlr 0.2 -f 文件名.txt*表示启动cloudflare工具,利用https://down.heleguo.top/download/300MB.zip测速地址测速。tll延迟下限是40,tl延迟上限是200,sl最低速度5M,tlr丢包率小于0.2,-f表示针对文件名.txt文件内IP测速。*参数设置请看这里:https://github.com/XIU2/CloudflareSpeedTest#-cmd-%E5%B8%A6%E5%8F%82%E6%95%B0%E8%BF%90%E8%A1%8C-cloudflarest*查找更多测速地址:https://github.com/XIU2/CloudflareSpeedTest/issues/168二、如何获取CF的CDN IP1、https://stock.hostmonit.com/CloudFlareYes2、http://ip.flares.cloud/3、https://github.com/hello-earth/cloudflare-better-ip/tree/main/cloudflare4、better-cloudflare-ip(本地优选)5、CloudflareSpeedTest(本地优选)6、https://fofa.info/*打开fofa网站搜索:server="cloudflare" && country="US" && city="Chicago" && port="443"*意思是筛选CF的CDN IP,国家是美国,地区是芝加哥,端口4437、利用“CloudflareSpeedTest”工具来测速:三、查当前IP地址及测速1、查IP:https://ip.gs/2、查IP纯净度:https://scamalytics.com/3、测速度:https://www.speedtest.net/-----------------------------C:\>CloudflareST.exe -hCloudflareSpeedTest vX.X.X测试 Cloudflare CDN 所有 IP 的延迟和速度,获取最快 IP (IPv4+IPv6)!https://github.com/XIU2/CloudflareSpeedTest参数: -n 200 延迟测速线程;越多延迟测速越快,性能弱的设备 (如路由器) 请勿太高;(默认 200 最多 1000) -t 4 延迟测速次数;单个 IP 延迟测速的次数;(默认 4 次) -dn 10 下载测速数量;延迟测速并排序后,从最低延迟起下载测速的数量;(默认 10 个) -dt 10 下载测速时间;单个 IP 下载测速最长时间,不能太短;(默认 10 秒) -tp 443 指定测速端口;延迟测速/下载测速时使用的端口;(默认 443 端口) -url https://cf.xiu2.xyz/url 指定测速地址;延迟测速(HTTPing)/下载测速时使用的地址,默认地址不保证可用性,建议自建; -httping 切换测速模式;延迟测速模式改为 HTTP 协议,所用测试地址为 [-url] 参数;(默认 TCPing) 注意:HTTPing 本质上也算一种 网络扫描 行为,因此如果你在服务器上面运行,需要降低并发(-n),否则可能会被一些严格的商家暂停服务。 如果你遇到 HTTPing 首次测速可用 IP 数量正常,后续测速越来越少甚至直接为 0,但停一段时间后又恢复了的情况,那么也可能是被 运营商、Cloudflare CDN 认为你在网络扫描而 触发临时限制机制,因此才会过一会儿就恢复了,建议降低并发(-n)减少这种情况的发生。 -httping-code 200 有效状态代码;HTTPing 延迟测速时网页返回的有效 HTTP 状态码,仅限一个;(默认 200 301 302) -cfcolo HKG,KHH,NRT,LAX,SEA,SJC,FRA,MAD 匹配指定地区;地区名为当地机场三字码,英文逗号分隔,支持小写,支持 Cloudflare、AWS CloudFront,仅 HTTPing 模式可用;(默认 所有地区) -tl 200 平均延迟上限;只输出低于指定平均延迟的 IP,各上下限条件可搭配使用;(默认 9999 ms) -tll 40 平均延迟下限;只输出高于指定平均延迟的 IP;(默认 0 ms) -tlr 0.2 丢包几率上限;只输出低于/等于指定丢包率的 IP,范围 0.00~1.00,0 过滤掉任何丢包的 IP;(默认 1.00) -sl 5 下载速度下限;只输出高于指定下载速度的 IP,凑够指定数量 [-dn] 才会停止测速;(默认 0.00 MB/s) -p 10 显示结果数量;测速后直接显示指定数量的结果,为 0 时不显示结果直接退出;(默认 10 个) -f ip.txt IP段数据文件;如路径含有空格请加上引号;支持其他 CDN IP段;(默认 ip.txt) -ip 1.1.1.1,2.2.2.2/24,2606:4700::/32 指定IP段数据;直接通过参数指定要测速的 IP 段数据,英文逗号分隔;(默认 空) -o result.csv 写入结果文件;如路径含有空格请加上引号;值为空时不写入文件 [-o ""];(默认 result.csv) -dd 禁用下载测速;禁用后测速结果会按延迟排序 (默认按下载速度排序);(默认 启用) -allip 测速全部的IP;对 IP 段中的每个 IP (仅支持 IPv4) 进行测速;(默认 每个 /24 段随机测速一个 IP) -v 打印程序版本 + 检查版本更新 -h 打印帮助说明-----------------------------
2024年04月17日
4 阅读
0 评论
0 点赞
2024-03-27
TypeScript 内置工具详谈
前言TypeScript 提供了几种实用程序类型来助力常见的类型转换。这些实用程序是全局可用的。也就是说全局声明了一些Type, 调用Type就可以方便地进行一些类型转换或者创建新的类型。 不会这些函数一样能写TypeScript你不会真的就不看下文了吧?, 但是掌握后能让你写TypeScript事半功倍。 且掌握这些内置Type是十分必要的。本文章主要对一些比较少用或者难理解的类型做了比较详细的说明。比如 ThisType<T> 等1、Partial 将一个类型的属性全部变为可选定义type Partial<T> = { [P in keyof T]?: T[P]; };从上面的代码中可以看出来该Type使用时需要传入一个泛型T。内部遍历T的所有属性然后创建一个新的 Type,新的Type的所有属性使用 ? 标识,使之为可选。keyof会遍历一个Interface的所有属性名称(key), 生成一个联合类型 "name" | "age" ...,然后可以得到下面代码P in "name" | "age" 这就很明白能看出来了,表明了P为右侧类型使用案例interface UserInfo { name:string; age:number; } // 这里会将 UserInfo 所有的属性变为可选 const foo:Partial<UserInfo> = { name:"张三" }2、Required 将一个类型的属性全部变为必选定义type Required<T> = { [P in keyof T]-?: T[P]; };该Type和Partial刚好是相反的。 从上面的代码中可以看出来该Type实用时需要传入一个泛型T。内部使用-?将T的每个属性去除可选标识使之变成为必填。使用案例interface UserInfo { name?:string; age?:number; } // 这里会将 UserInfo 所有可选的属性变为必选 const foo:Required<UserInfo> = { name:"张三", age:18 }3、Readonly 将一个类型的属性全部变为只读状态定义type Readonly<T> = { readonly [P in keyof T]: T[P]; };从上面的代码中可以看出来该Type实用时需要传入一个泛型T。内部使用readonly将T的每个属性去除可选标识使之变成为只读。使用案例interface UserInfo { name?:string; age?:number; } const foo:Readonly<UserInfo> = { name:"张三", age:18 } foo.name = '李四';// error: 无法分配到 "name" ,因为它是只读属性4、Record 构造一个字面量对象 Type定义type Record<K extends keyof any, T> = { [P in K]: T; };Record 用于方便地构造一个字面量对象。其作用和 { [propName:string]:any } 有些许类似。Record 只需要传入两个 Type 即可创建一个新的 Type,相比于 { [propName:string]:any } 能方便一些。当然除了方便外功能也比它强大,因为Record第一个参数可接收一组key,这样就可以做到定义出一个完整的 Type 了。使用案例// 这是通过 interface 定义出来的。 interface UserInfo { name:string; age:number; } // 我们用 Record 来实现一遍 UserInfo 。 // 注意:后面一个形参和 UserInfo 的是不一样的,因为 Record 第二个参数只能接受一个类型。所以这里要么用 any,要么用这种联合类型。 type UserInfoT = Record<"name" | "age", string | number> // 结果 // type UserInfoT = { // name:string | number; // age:string | number; // }5、Pick 从一个 Type 中选取一些属性来构造一个新的对象 Type定义type Pick<T, K extends keyof T> = { [P in K]: T[P]; };Pick 也用于方便地构造一个字面量对象。其作用和 Record 有些许类似。使用案例interface UserInfo { name:string; age:number; } // 这时候我们只需要 UserInfo 的 name 属性。 type UserInfoT = Pick<UserInfo, "name">6、Omit 从一个对象类型中删除一些属性来构造一个新的对象 Type定义type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;日常使用中Omit 是一个使用频率可能比较高的。和 Pick 刚刚相反,用于排除不需要的属性。使用案例interface UserInfo { name:string; age:number; } // 这时候我们不需要 UserInfo 的 name 属性。 type UserInfoT = Omit<UserInfo, "name">7、Exclude 排除一个联合类型中的某一些类型来构造一个新 Type定义type Exclude<T, U> = T extends U ? never : T;上面说的 Omit 和 Pick 都是对一个字面量对象 Type 的操作。如果要对一个联合类型操作的话需要用到 Exclude 和 Extract使用案例// 排除掉 "name" type UserInfoT = Exclude<"name" | "age", "name">; // 等价于 type UserInfoA = "age";8、Extract 提取出一个联合类型中的某一些类型来构造一个新 Type定义type Extract<T, U> = T extends U ? T : never;和 Exclude 恰好相反。使用案例// 从 T1 中 提取出 T2 type T1 = "name" | "age" | "hob"; type T2 = "name" | "age"; type UserInfoT = Extract<T1, T2>; // 等价于 type UserInfoA = "name" | "age";既然是提出哪为啥不直接用定义好的 T2?因为这样可以保证 UserInfoT 的类型一定是在 T1 中存在的;9、NonNullable 从类型中排除 null 和 undefined 来构造一个新的 Type定义type NonNullable<T> = T extends null | undefined ? never : T;使用案例// 从 UserInfoK 中 排除掉 null | undefined type UserInfoK = NonNullable<"name" | "hob" | undefined>; // 等价于 type UserInfoKA = "name" | "hob";10、Parameters 从 [函数 Type] 的形参构造一个数组 Type定义type Parameters<T extends (...args: any) => any> = T extends (...args: infer P) => any ? P : never;infer标识一个待推导类型,上面定义的意思是:如果 T 为函数类型,那就返回函数的形参。ps: infer和变量似的,先定义一个 infer P 然后 Ts 就会自动推导函数的形参或者返回值、或者数组元素等,然后开发者在合适的位置使用定义好的infer P即可。一个简单的infer案例。加入有这样一个需求:需要将数组类型的 Type 变为联合类型。其他类型的则不变。这样我们就可以写一个这样的 Typetype ArrayToUnion<T> = T extends Array<infer Item> ? Item : T; const a:ArrayToUnion<[string, number]> = "111"; // a: string | number const b:ArrayToUnion<string | number> = "111"; // a: string | number从这个案列的a变量可以看出作用,a变量的类型定义为ArrayToUnion<[string, number]>,这里传入的是个数组[string, number]被ArrayToUnion处理为了string | number。使用案例// 定义一个函数 function getUserInfo(id:string, group:string){} // 获取到函数需要的形参 Type[] type GetUserInfoArg = Parameters<typeof getUserInfo>; const arg:GetUserInfoArg = [ "001", "002" ]; getUserInfo(...arg);ps: 上面代码中的typeof是 ts 提供的操作符不是 js 中的那个typeof,只能用到 ts 的类型定义中, 所以使用typeof getUserInfo才能指向函数Type11、ConstructorParameters 从定义的[构造函数]的形参构造数组 Type定义type ConstructorParameters<T extends abstract new (...args: any) => any> = T extends abstract new (...args: infer P) => any ? P : never;实现原理完全和 Parameters 一样,只不过这个方法接受的事一个类。使用案例class User{ constructor(id:string, group:string){} } type NewUserArg = ConstructorParameters<typeof User>; const arg:NewUserArg = [ "001", "002"]; new User(...arg);12、ReturnType 用函数 Type 的返回值定义一个新的 Type定义type ReturnType<T extends (...args: any) => any> = T extends (...args: any) => infer R ? R : any;使用 infer 实现。比 Parameters 更简单,可以去看上面的 Parameters 就能明白这段代码意思。使用案例// 定义一个函数 Type type GetUserInfo = ()=>string; const rt:ReturnType<GetUserInfo> = 'xxx'; 13、InstanceType 从一个构造函数的实例定义一个新的 Type定义type InstanceType<T extends abstract new (...args: any) => any> = T extends abstract new (...args: any) => infer R ? R : any;使用 infer 实现。和ReturnType实现原理完全一样。使用案例// 定义一个函数 Type type GetUserInfo = ()=>string; const rt:ReturnType<GetUserInfo> = 'xxx'; 14、ThisParameterType 提取函数 Type 的 this 参数生成一个新的 Type定义type ThisParameterType<T> = T extends (this: infer U, ...args: any[]) => any ? U : unknown;从上面定义看出该 Type 对函数的第一个形参 this 做了infer推导。然后返回了推导出来的this。 不清楚infer的话,往上翻,去仔细看看Parameters一节的说明。使用案例// 定义一个函数,并且定义函数 this 类型。 function getUserInfo(this:{ name:string }){} const getUserInfoArgThis: ThisParameterType<typeof getUserInfo> = { name:"王" };15、OmitThisParameter 忽略函数 Type 的 this 参数,生成一个新的函数 Type定义type OmitThisParameter<T> = unknown extends ThisParameterType<T> ? T : T extends (...args: infer A) => infer R ? (...args: A) => R : T;这个Type看着略微复杂。咋们拆一下看就会简单很多。首先说明一下这个Type的这些判断都是干嘛的。上面定义意思是:如果传入的T没有this参数就直接返回T,如果有this参数就继续进行判断,第二层判断为:如果T不是函数那也会直接返回T,最后是重新定义了一个函数然后返回。其中使用infer定义了我们所需要的形参和返回值。这里在座的各位可能会在(...args: infer A) => infer R ? (...args: A) => R : T这里产生疑惑。上面的写法会直接把this参数过滤掉,为了证实这点,我们可以实现一下:type NoThis<T> = T extends (...args: infer A) => infer R ? A : T const a:NoThis<typeof getUserInfo>; // a: [id: string]上面代码中我们直接返回了推导的A,得到了形参A的类型。这里面是不会包含this的。使用案例// 定义一个函数 function getUserInfo(this:{ name:string }, id:string){} // 去除 getUserInfo 函数 this 参,然后创建出来了一个新类型 const aaa: OmitThisParameter<typeof getUserInfo> = (id:string)=>{} 16、ThisType 给对象标记 this 接口这个类型在 lib.d.ts 中定义的就是一个{}空标签,所以用的时候往往比较困惑。特别是没注意看到官网上写的必须开启--noImplicitThis时才可以用的时候。就算你看到了,但是你在他们案例中如果不注意的话还是搞不懂,因为官方案例中设置了这个编译规则 // @noImplicitThis: false。noImplicitThis 规则开启后在函数中的this在不定义的情况下不能使用,相当于严格模式,默认情况下noImplicitThis的值为false,除非手动开启,否则ThisType毫无作用。使用案例// 注意这行注释,必须开启才能看出效果 // @noImplicitThis: true type ObjectDescriptor<D, M> = { data?: D; methods?: M & ThisType<D & M>; // 这个对象中的 this 要指向 D & M, 注意这里和 methods?: D & M 表示表示是不一样的,ThisType 只改变对象的 this }; function makeObject<D, M>(desc: ObjectDescriptor<D, M>): D & M { let data: object = desc.data || {}; let methods: object = desc.methods || {}; return { ...data, ...methods } as D & M; } let obj = makeObject({ data: { x: 0, y: 0 }, methods: { moveBy(dx: number, dy: number) { this.x += dx; this.y += dy; }, }, }); obj.x = 10; obj.y = 20; obj.moveBy(5, 5);17、Uppercase 将字符串中的每个字符转换为大写这是对字符串的操作,所有对字符串的操作在 lib.d.ts 中都找不到具体的定义,文档上说是为了提升性能。type MyText = "Hello, world" type A = Uppercase<MyText>; // type A = "HELLO, WORLD"18、Lowercase 将字符串中的每个字符转换为小写type MyText = "Hello, world" type A = Lowercase<MyText>; // type A = "hello, world"19、Capitalize 将字符串中的第一个字符转换为大写type MyText = "hello, world" type A = Capitalize<MyText>; // type A = "Hello, world"20、Uncapitalize 将字符串中的第一个字符转换为小写type MyText = "Hello, world" type A = Uncapitalize<MyText>; // type A = "hello, world"
2024年03月27日
4 阅读
0 评论
0 点赞
2023-12-08
PVE8优化
一、更改源关闭订阅提示将/etc/apt/sources.list.d/pve-enterprise.list 文件删除: rm -rf /etc/apt/sources.list.d/pve-enterprise.list 或者:/etc/apt/sources.list.d/pve-enterprise.list内容替换为 deb https://mirrors.tuna.tsinghua.edu.cn/proxmox/debian bookworm pve-no-subscription Proxmox软件源更换 echo "deb https://mirrors.ustc.edu.cn/proxmox/debian/pve bookworm pve-no-subscription" > /etc/apt/sources.list.d/pve-no-subscription.list Debian系统源更换 sed -i.bak "s#ftp.debian.org/debian#mirrors.aliyun.com/debian#g" /etc/apt/sources.list #阿里Debian源 sed -i "s#security.debian.org#mirrors.aliyun.com/debian-security#g" /etc/apt/sources.list #阿里Debian源 apt update && apt-get install -y apt-transport-https ca-certificates --fix-missing LXC仓库源更换 sed -i.bak "s#http://download.proxmox.com/images#https://mirrors.ustc.edu.cn/proxmox/images#g" /usr/share/perl5/PVE/APLInfo.pm wget -O /var/lib/pve-manager/apl-info/mirrors.ustc.edu.cn https://mirrors.ustc.edu.cn/proxmox/images/aplinfo-pve-7.dat systemctl restart pvedaemon CEPH源更换 echo "deb https://mirrors.ustc.edu.cn/proxmox/debian/ceph-quincy bookworm no-subscription" > /etc/apt/sources.list.d/ceph.list #中科大源 sed -i.bak "s#http://download.proxmox.com/debian#https://mirrors.ustc.edu.cn/proxmox/debian#g" /usr/share/perl5/PVE/CLI/pveceph.pm #中科大源 删除订阅弹窗 sed -Ezi.bak "s/(Ext.Msg.show\(\{\s+title: gettext\('No valid sub)/void\(\{ \/\/\1/g" /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js && systemctl restart pveproxy.service二、删除 local-lvm 合并到 locallvremove pve/data lvextend -l +100%FREE -r pve/root然后在 web 界面中前往 数据中心 > 存储, 移除 local-lvm ,再编辑 local,内容里选中所有的项目
2023年12月08日
12 阅读
0 评论
3 点赞
2023-09-01
ssh 代理转发
在外部网络上的机器上安装 SSH 客户端(例如 OpenSSH)。在内网服务器上安装 SSH 服务器。在外部网络上的机器上运行以下 SSH 命令,创建一个隧道将外部端口转发到内网服务器的端口。假设内网服务器的 IP 是 internal-ip,内网服务器上的需要代理的端口是 internal-port,外部网络上的机器的 IP 是 external-ip,需要将外部端口 external-port 代理到内网服务器上:ssh -N -L external-ip:external-port:internal-ip:internal-port user@internal-ip 其中,user 是内网服务器上的用户名,internal-ip 是内网服务器的 IP 地址,internal-port 是内网服务器上需要代理的端口,external-ip 是外部网络上的机器的 IP 地址,external-port 是外部网络上的机器上用于访问代理的端口。
2023年09月01日
3 阅读
0 评论
1 点赞
2023-08-28
MySQL创建数据库与创建用户以及授权
1、创建数据库命令: create schema [数据库名称] default character set utf8 collate utf8_general_ci;说明:采用create schema和create database创建数据库的效果一样。2、创建用户命令: create user '[用户名称]'@'%' identified by '[用户密码]';说明:密码8位以上,包括:大写字母、小写字母、数字、特殊字符%:匹配所有主机,该地方还可以设置成‘localhost’,代表只能本地访问,例如root账户默认为‘localhost‘ ;username : 你将创建的用户名,host : 指定该用户在哪个主机上可以登陆,如果是本地用户可用localhost, 如果想让该用户可以从任意远程主机登陆,可以使用通配符%.password : 该用户的登陆密码,密码可以为空,如果为空则该用户可以不需要密码登陆服务器.例子: CREATE USER 'dog'@'localhost' IDENTIFIED BY '123456';CREATE USER 'pig'@'192.168.1.101_' IDENDIFIED BY '123456';CREATE USER 'pig'@'%' IDENTIFIED BY '123456';CREATE USER 'pig'@'%' IDENTIFIED BY '';CREATE USER 'pig'@'%';3、用户授权数据库命令: grant select,insert,update,delete,create on [数据库名称].* to [用户名称];命令:GRANT privileges ON databasename.tablename TO 'username'@'host'说明:*代表整个数据库privileges : 用户的操作权限,如SELECT , INSERT , UPDATE 等(详细列表见该文最后面).如果要授予所的权限则使用ALL.;databasename -:数据库名,tablename:表名,如果要授予该用户对所有数据库和表的相应操作权限则可用表示, 如.*.例子: GRANT SELECT, INSERT ON test.user TO 'pig'@'%';GRANT ALL ON . TO 'pig'@'%';注意:用以上命令授权的用户不能给其它用户授权,如果想让该用户可以授权,用以下命令:GRANT privileges ON databasename.tablename TO 'username'@'host' WITH GRANT OPTION;4、启用修改flush privileges ;5、取消用户所有数据库(表)的所有权限revoke all on . from tester;6、删除用户delete from mysql.user where user='tester';7、删除数据库drop database [schema名称|数据库名称];--我在mysql root中建立了一个数据库,在数据库中建立了一个用户,--并授权用户对数据库中几张表的访问权限。--之后登陆用户,为什么无法访问表8、查询用户创建是否正确select user,host from mysql.user;--查看a@localhost是否存在如果没有则删除之前的用户,重新新建用户,并将%替换为localhost如:CREATE USER 'eims_report'@'localhost';
2023年08月28日
7 阅读
0 评论
2 点赞
2023-08-03
服务器reid配置
服务器开机后,根据屏幕提示,按Ctrl+R 进入阵列卡配置界面用键盘的上下左右键,选择到“Controller 0“,然后按键盘上的F2键,选择Create New VD, 回车在RAID Level项上按回车, 选择RAID级别选中要做RAID x的硬盘(按空格键和上下键,就可以选中硬盘了),硬盘选择好后,按TAB键,VD Size(默认即可),VD Name (随便写,不写也行),然后选择OK,VD已创建新服务器,需要初始化。选择Virtual Disk 0按F2键,选择InitializationàFast Init.(备注:快速初始化是给新服务器使用,如果是旧服务器,怀疑硬盘有故障,可以选择Start Init,但是需要几个小时才能完成初始化)提示将删除数据:可以看到初始化的进度,大概几分钟,初始化完成,就可以开始安装系统了.(备注:需要查看阵列状态,在Virtual Disk 0上按F2键, 选择Properties可以看到VD1的具体配置信息,还可以更改条带大小,读写策略等参考
2023年08月03日
2 阅读
0 评论
0 点赞
2023-06-08
jenkins根据分支、文件夹打包
Generic Webhook Trigger配置变量Post content parameters -> Name of variable = changed_filesExpression = $.commits-1[*]JSONPathPost content parameters -> Name of variable = branchExpression = $.refJSONPathToken (配置token "地址/generic-webhook-trigger/invoke?token=token")Optional filterExpression = master(.*"(BawangChaji-UI/)1+?"){1,}Text = $branch$changed_files" ↩
2023年06月08日
5 阅读
0 评论
0 点赞
1
2
...
15