yaogengzhu / daily-share

个人博客记录、内容在issues
30 stars 4 forks source link

Linux相关(新入Linux机器、记录相关知识点) (2023-05-06) #186

Open yaogengzhu opened 1 year ago

yaogengzhu commented 1 year ago

最近新购入一台服务器,记录一些小技巧

yaogengzhu commented 1 year ago

安装 git

yum install git 

安装node

yum install nodejs 
yaogengzhu commented 1 year ago

安装nvm

可参考该文章

wget https://github.com/nvm-sh/nvm/archive/refs/tags/v0.39.1.tar.gz
tar -zcvf 压缩文件名.tar.gz  -C /home    #  -C 解压到指定目录

编辑bashrc 文件

vim ~/.bashrc
export NVM_DIR="/home/nvm-0.39.1"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
source ~/.bashrc # 刷新配置

nvm install v16.17.1 # 安装指定node 版本
yaogengzhu commented 1 year ago

配置ssh

可参考另外一个issues https://github.com/yaogengzhu/daily-share/issues/182

简单粗暴的方式

ssh-keygen # 回车... 直接执行,则默认生成一个ssh key, 复制xxx.pub 到指定的系统中即可
yaogengzhu commented 1 year ago

使用 nginx

docker pull nginx:latest

创建nginx 配置

mkdir -p /home/nginx/conf

mkdir -p /home/nginx/log

mkdir -p /home/nginx/html

Docker 跑 nginx 服务

docker run -d -p80:80 nginx

拷贝容器中的配置文件到宿主机中 (可将nginx 替换成容器id)

docker cp nginx:/etc/nginx/nginx.conf /home/nginx/conf/nginx.cof

docker cp nginx:/etc/nginx/conf.d /home/nginx/conf/conf.d

docker cp nginx:/usr/share/nginx/html /home/nginx/

停止nginx, 对文件目录重新做映射

做https 需要开放443 端口

netstat -ntulp  # 查看端口监听情况
netstat -lntp | grep 443  # 查看443 端口
docker run -d -p80:80 \
-p 443:443 \
-v /home/nginx/conf/nginx.cof:/etc/nginx/nginx.conf \
-v /home/nginx/conf/conf.d:/etc/nginx/conf.d \
-v /home/nginx/conf/cert/:/etc/nginx/cert/ \
-v /home/nginx/log:/var/log/nginx \
-v /home/nginx/html:/usr/share/nginx/html \
nginx
server {
    listen 80 default_server;
    server_name _;
    return 301 https://$host$request_uri;
}

server {
    # SSL configuration
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name www.yaogeng.top;

    ssl_certificate      /etc/nginx/cert/yaogeng.top.pem;  # pem文件的路径
    ssl_certificate_key  /etc/nginx/cert/yaogeng.top.key; # key文件的路径

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }
}

server {
    listen 80; #侦听80端口
    listen 443 ssl; #侦听443端口,用于SSL
    server_name api.yaogeng.top;  # 自己的域名
    # 注意证书文件位置,是从/etc/nginx/下开始算起的
    ssl_certificate     /etc/nginx/cert/api.yaogeng.top.pem;  # pem文件的路径
    ssl_certificate_key /etc/nginx/cert/api.yaogeng.top.key; # key文件的路径
    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
    ssl_prefer_server_ciphers on;

    client_max_body_size 1024m;

    location / {
        proxy_set_header HOST $host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://xxxxxx:3000;
    }
}

server {
    listen 80; #侦听80端口
    listen 443 ssl; #侦听443端口,用于SSL
    server_name jenkins.yaogeng.top;  # 自己的域名
    # 注意证书文件位置,是从/etc/nginx/下开始算起的
    ssl_certificate     /etc/nginx/cert/jenkins.yaogeng.top.pem;  # pem文件的路径
    ssl_certificate_key /etc/nginx/cert/jenkins.yaogeng.top.key; # key文件的路径
    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
    ssl_prefer_server_ciphers on;

    client_max_body_size 1024m;

    location / {
        proxy_set_header HOST $host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://xxxxx:8080;
    }
}