轻松玩转macos
这篇文章就讲如何高效的使用macos
,其中包含一些可以提高生产力的工具和mac上面鲜为人知的强大功能。
Macos
自带的快捷键
免密登录centos
# 1. 生成id_rsa key
ssh-keygen -t rsa
# 2. 将密钥推送到远程服务器
ssh-copy-id -i ~/.ssh/id_rsa root@47.105.123.222
# 3. 登录
ssh root@47.105.123.222
ssh root@47.105.123.222 uname
设置了本机的免密登录,如果想要上传文件。就可以使用:
scp -r build/web/* root@47.105.123.222:/root/web/tmp
Tips
ssh 的原理:https://zhuanlan.zhihu.com/p/241341815
ssh 的原理:https://github.com/guobinhit/cg-blog/blob/master/articles/others/detail-ssh.md
使用 ssh 连接github : https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account
centos上安装openjdk
由于阿里云上面的 jdk 源最新才11
,想要安装最新的 jdk21
,可以采用直接下载 tar 文件的方式。
- 下载 jdk 源文件
wget https://download.java.net/java/GA/jdk21.0.1/415e3f918a1f4062a0074a2794853d0d/12/GPL/openjdk-21.0.1_linux-x64_bin.tar.gz
- 解压文件并把文件放到指定位置
cd /opt/
tar -zxvf ../root/openjdk-21.0.1_linux-x64_bin.tar.gz
mv jdk-21.0.1/ jdk
- 配置JAVA_HOME
# 在.bashrc 文件中,添加如下内容
export JAVA_HOME=/opt/jdk
export PATH=$JAVA_HOME/bin:$PATH
在centos 上面安装 docker
- Set up the repository
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
- Install Docker Engine
sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
- Start Docker
sudo systemctl start docker
https://docs.docker.com/engine/install/centos/#install-using-the-repository
- Install docker-compose
curl -SL https://github.com/docker/compose/releases/download/v2.23.3/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
nginx 出现403的问题
当我把博客的内容发送到/root/web/xxx
当中,尝试访问出现403的问题。
查看nginx 的配置文件
/etc/nginx/nginx.conf
发现user nginx;
,将其修改为user root;
即可。参考:https://cloud.tencent.com/developer/article/1949092
aliyun centos访问 github 缓慢
在/etc/hosts
文件中添加以下内容
140.82.114.4 github.com
199.232.5.194 github.global.ssl.fastly.net
host
文件维护 IP 和域名之间的关系。当用户在浏览器输入域名(比如github.com)并访问时,系统会先在host
中找寻对应的IP地址(140.82.114.4)。如果找到系统就会立即打开网页,否则会拿这个域名去DNS 服务得到解析后的IP地址。
host文件的好处:
加快域名解析
: 配置在 host 文件中的域名,不用经过 DNS 解析构建 IP 与域名关系
:要是局域网里面的服务器众多,各种 IP 难以记住。有个名字就简单名了些屏蔽垃圾网站
:在 host 中把垃圾网站映射到错误的 IP 中,让垃圾网站就被禁止访问
curl的basic auth
# username and password
curl https://reqbin.com/echo -u "login:password"
# Authorization header,'bG9naW46cGFzc3dvcmQ='是"login:password"字符串的base64编码
curl https://reqbin.com/echo -H "Authorization: Basic bG9naW46cGFzc3dvcmQ="
使网站 https
http 的网站会显示Not Secure
的角标,这是由于现代主流浏览器已经识别到你使用的传输不怎么安全http。
- 申请免费的 SSL 证书
由于我的域名和服务器都是用的aliyun,而阿里又存在免费的SSL的证书可以申请。所以就选择了aliyun。参考链接:https://developer.aliyun.com/article/1212043
- 部署和配置 nginx
参考链接: https://help.aliyun.com/zh/ssl-certificate/deploy-a-certificate-to-an-alibaba-cloud-service
Tips
整个流程参考:https://juejin.cn/post/6987940779733811208
http重定向到https: https://segmentfault.com/a/1190000022532940
最后贴出我的nginx关于https的配置
server {
listen 80;
listen [::]:80;
server_name _;
root /root/web/huhx_blog/;
index index.html index.htm;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
return 301 https://huhx.cn$request_uri;
}
# Settings for a TLS enabled server.
server {
listen 443 ssl;
listen [::]:443 ssl http2;
server_name huhx.cn;
root /root/web/huhx_blog/;
ssl_certificate "/etc/nginx/conf.d/cert/huhx.cn.pem";
ssl_certificate_key "/etc/nginx/conf.d/cert/huhx.cn.key";
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
include /etc/nginx/default.d/*.conf;
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}