Erlang安装

使用的系统是CENTOS7.X

  • 安装命令如下:
cd /opt
yum install epel-release -y
wget https://packages.erlang-solutions.com/erlang-solutions-1.0-1.noarch.rpm
rpm -Uvh erlang-solutions-1.0-1.noarch.rpm
yum install erlang -y
[ -f /opt/erlang-solutions-1.0-1.noarch.rpm ] && rm /opt/erlang-solutions-1.0-1.noarch.rpm -rf
erl  ##输入这个命令,如果有版本等信息就表示安装成功

参考地址: https://tecadmin.net/install-erlang-on-centos/

删除备份脚本

这个脚本的主要功能就是读取配置文件,然后根据需求保留备份的个数(备份的文件是以时间格式命名的),删除最老的备份,以下是脚本内容:

#!/bin/bash
KEEP_NUM=2
for i in `cat /opt/sh/delete_backup.conf`
do
    CURRENT_NUM=`ls -l ${i} | grep -v total | wc -l`
    for((j=${CURRENT_NUM};j>${KEEP_NUM};j--))
    do
        FILE_NAME=`ls ${i} | sort -n | head -n 1`
        echo "删除的目录是: ${i}/${FILE_NAME}"
        cd ${i} && [ -d ${FILE_NAME} ] && rm ${FILE_NAME} -rf && sleep 1
    done
done

delete_backup.conf的内容是删除的目录

/opt/sh/testdir/a
/opt/sh/testdir/b

nodejs学习系列(一)

这儿的开发环境是windows。需要先安装好node 安装好vscode 安装好 “git bash”。下面是一个简单的示例

  • 打开git bash 创建目录,并启动vscode 打开创建好的项目
cd d:
mkdir code
cd code
mkdir study-api
code.cmd study-api
  • 以下命令是在vscode终端中运行的
npm init ## 初始化项目,填入相应的信息即可
npm install -g cnpm --registry=https://registry.npm.taobao.org  ## 安装阿里的cnpm来加速安装
cnpm.cmd install koa --save  ## 安装koa, --save的参数是表示写入到package.json中
cnpm.cmd install nodemon --save-dev  ## 安装自动重启的工具
  • 完成后的“package.json”的文件内容如下:
{
  "name": "study-api",
  "version": "1.0.0",
  "description": "学习 RESTful API",
  "main": "index.js",
  "scripts": {
    "start": "nodemon index.js"
  },
  "author": "author_name",
  "license": "ISC",
  "dependencies": {
    "koa": "^2.7.0"
  },
  "devDependencies": {
    "nodemon": "^1.19.1"
  }
}
  • 编写一个”index.js”文件,文件如下:
const Koa = require('koa');
const app = new Koa;

app.use((ctx) =>{
    ctx.body = 'hello 我的媳妇';
})

app.listen(3000);
  • 启动项目
npm start

centos7初始化脚本

#!/bin/bash
#update soft
yum -y update
yum install wget rsync bzip2 lsof telnet htop screen tree vim gcc make net-tools lrzsz psmisc hwloc gsmartcontrol chrony -y

#时间设置 
timedatectl set-local-rtc 1
timedatectl set-timezone Asia/Shanghai
systemctl start chronyd.service
systemctl enable chronyd.service

#设置最大打开文件描述符数
echo "ulimit -SHn 102400" >> /etc/rc.local
cat >> /etc/security/limits.conf <<EOF
*           soft   nofile       65535
*           hard   nofile       65535
EOF

#禁用selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
setenforce 0

#停止不必要的服务
systemctl disable --now rpcbind
systemctl disable --now rpcbind.socket
systemctl disable --now postfix.service
systemctl disable --now firewalld.service
systemctl disable --now firewalld
systemctl disable --now dnsmasq
systemctl disable --now NetworkManager

#set ssh
sed -i 's/^GSSAPIAuthentication yes$/GSSAPIAuthentication no/' /etc/ssh/sshd_config
sed -i 's/#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config
systemctl  restart sshd.service

#内核参数优化
cat >> /etc/sysctl.conf <<EOF
vm.overcommit_memory = 1
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_abort_on_overflow = 0
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.netdev_max_backlog = 262144
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_max_syn_backlog = 262144
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.ipv4.tcp_syncookies = 1
EOF
/sbin/sysctl -p

# profile 修改
echo "export HISTTIMEFORMAT=\"%F %T \"" >> /etc/profile
echo "" >> /etc/profile
echo "## 自定义别名" >> /etc/profile
echo "alias c=clear" >> /etc/profile
echo "alias vi=vim" >> /etc/profile
echo "alias dsh='du -hsx * | sort -rh | head -n 10'" >> /etc/profile
sed -i 's/HISTSIZE=1000/HISTSIZE=10000/g' /etc/profile
source /etc/profile

NAS安装迅雷进行离线下载

nas使用迅雷总的给我的使用感觉不好,如果种子不好的话,速度提不上来。个人感觉实际意义不是很大

  1. 在套件中心安装 docker 组件
  2. 打开刚刚安装好的 docker 组件,在注册表中搜索”yinheli/docker-thunder-xware”,并安装
  3. 创建一个文件夹”/docker/download/xunlei”。
  4. 在“映像”列表里选择刚刚下载好的镜像点击“启动”,并把第三步创建的文件夹挂载到”/TDdownload”下面
  5. 在端口设置这儿添加一个端口映射,我容器的端口和映射的端口都是9000
  6. 启动容器之后,点击刚刚启动那个容器的”详情”,然后再选择”日志”,在日志中找到”THE ACTIVE CODE IS”后面的激活码
  7. 登录 “http://yuancheng.xunlei.com ” ,并登录你自己的账号和密码,输入你的激活码并点击”绑定”
  8. 然后就可以愉快的使用了,使用的时候是在“http://yuancheng.xunlei.com”这个网址中添加种子等信息