#!/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使用迅雷总的给我的使用感觉不好,如果种子不好的话,速度提不上来。个人感觉实际意义不是很大
- 在套件中心安装 docker 组件
- 打开刚刚安装好的 docker 组件,在注册表中搜索”yinheli/docker-thunder-xware”,并安装
- 创建一个文件夹”/docker/download/xunlei”。
- 在“映像”列表里选择刚刚下载好的镜像点击“启动”,并把第三步创建的文件夹挂载到”/TDdownload”下面
- 在端口设置这儿添加一个端口映射,我容器的端口和映射的端口都是9000
- 启动容器之后,点击刚刚启动那个容器的”详情”,然后再选择”日志”,在日志中找到”THE ACTIVE CODE IS”后面的激活码
- 登录 “http://yuancheng.xunlei.com ” ,并登录你自己的账号和密码,输入你的激活码并点击”绑定”
- 然后就可以愉快的使用了,使用的时候是在“http://yuancheng.xunlei.com”这个网址中添加种子等信息
结合redis和lua实现个性化域名登录
使用场景: 客户只要通过后台绑定了自己的域名,解析到我们服务器之后。就能通过绑定的域名类型访问到相应的对应资源。实现原理是:在绑定的时候程序会将绑定域名和类型写入到redis中,并永久保存,NGINX通过lua读取redis里面的数据,指定不同的root路径。
安装
- 安装luajit
yum -y install lua lua-devel ## 编译的时候会依赖这个
cd /opt && wget http://luajit.org/download/LuaJIT-2.0.5.tar.gz
tar zxvf LuaJIT-2.0.5.tar.gz && cd LuaJIT-2.0.5
make install PREFIX=/opt/luajit
export LUAJIT_LIB=/opt/luajit/lib ## 编译nginx需要的变量
export LUAJIT_INC=/opt/luajit/include/luajit-2.0 ## 编译nginx需要的变量
- 安装cjson库,用来解析json格式数据的
cd /opt && wget https://www.kyne.com.au/~mark/software/download/lua-cjson-2.1.0.tar.gz
tar zxvf lua-cjson-2.1.0.tar.gz && cd lua-cjson-2.1.0
##编辑Makefile修改以下几个参数
vim Makefile
PREFIX = /opt/luajit
LUA_INCLUDE_DIR = /opt/luajit/include/luajit-2.0
LUA_CMODULE_DIR = /opt/luajit/lib
LUA_MODULE_DIR = /opt/luajit/share/lua/5.1
LUA_BIN_DIR = /opt/luajit/bin
##编译并安装
make && make install
- 安装cmsgpack库,主要用来序列化和反序列化的
cd /opt && git clone https://github.com/antirez/lua-cmsgpack.git && cd /opt/lua-cmsgpack
mkdir build && cd build && cmake .. && make
- nginx编译需要的模块
cd /opt && git clone https://github.com/simplresty/ngx_devel_kit.git
cd /opt && git clone https://github.com/openresty/lua-nginx-module.git
cd /opt && git clone https://github.com/openresty/lua-resty-redis.git
- 解决一些模块和库文件依赖问题
cp /opt/lua-cmsgpack/build/cmsgpack.so /opt/luajit/lib/
cp /opt/lua-cmsgpack/build/cmsgpack.so /opt/luajit/lib/lua/5.1/
cp /opt/luajit/lib/cjson.so /opt/luajit/lib/lua/5.1/
echo "/usr/local/lib/" >> /etc/ld.so.conf.d/libc.conf
echo "/opt/luajit/lib" >> /etc/ld.so.conf.d/libc.conf
ldconfig
- 编译nginx,复制编译好的nginx二进制文件替换原来的nginx(原来的nginx二进制文件做备份)
tar zxvf nginx-1.14.0.tar.gz && cd nginx-1.14.0
./configure --add-module=/opt/lua-nginx-module --add-module=/opt/ngx_devel_kit --prefix=/opt/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_dav_module --with-http_flv_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_stub_status_module --with-http_sub_module --with-http_random_index_module --with-http_degradation_module --with-http_secure_link_module --with-http_gzip_static_module --with-http_perl_module --with-pcre --with-debug --with-file-aio --with-mail --with-mail_ssl_module --with-stream --with-ld-opt=-Wl,-E
make -j2
下面是一个示例代码
- 在nginx.conf中http下加入redis的支持: “lua_package_path “/opt/lua-resty-redis/lib/?.lua;;”;”
- lua.conf的配置文件如下:
server {
listen 80 default;
server_name _; ## 这儿做默认解析
access_log logs/lua.log;
error_log logs/lua.error.log;
index index.html;
location / {
add_header 'Access-Control-Allow-Origin' '*';
set $defaultroot /opt/web/default;
access_by_lua_file '/opt/nginx/conf/vhost/lua.lua';
root $defaultroot;
try_files $uri $uri/ /index.html;
}
- lua.lua的配置文件如下:
local redis = require "resty.redis"
local cjson = require "cjson"
local cmsgpack = require "cmsgpack"
local red = redis:new()
red:set_timeout(1000)
local ok, err = red:connect("127.0.0.1", 6379)
if not ok then
ngx.say("failed to connect: ", err)
return
end
red:select(1)
local redisData = red:get("domain.key")
local getdata = cjson.decode(redisData);
for i,w in ipairs(getdata) do
if ngx.var.host == w.domain
then
if w.type == "app1"
then
ngx.var.defaultroot = "/opt/web/app1"
elseif w.type == "app2"
then
ngx.var.defaultroot = "/opt/web/app2"
else
ngx.var.defaultroot = "/opt/web/default"
end
end
end
red:close()
- redis中取出来的json格式如下:
[
{
"domain":"domain1_name",
"id":"123456",
"type":"app1"
},
{
"domain":"domain2_name",
"id":"123457",
"type":"app2"
},
{
"domain":"domain3_name",
"id":"123458",
"type":"app3"
}
]
NAS中使用qbittorrent来离线下载种子文件
- 在套件中心安装 docker 组件
- 打开刚刚安装好的 docker 组件,在注册表中搜索”linuxserver/qbittorrent”,并安装
- 创建两个文件夹”/docker/download/qbittorrent/config” 和 “/docker/download/qbittorrent/downloads”,并赋予everyone的权限
- 在“映像”列表里选择刚刚下载好的镜像点击“启动”,并把第三步创建的两个文件夹挂载到”/config”和”/downloads”下面
- 在端口设置这儿将8080改为8999,本地端口也改为8999
- 在配置环境变量这儿填入以下三个变量:
WEBUI_PORT 8999
SavePath /downloads
TempPath /downloads
- 最后”http://172.16.50.2:8999/” 使用该地址访问qb,用户名是:admin 密码是:adminadmin
YAPI的安装
- YAPI是一个高效、易用、功能强大的API管理平台旨在为开发、产品、测试人员提供更优雅的接口管理服务,这是官网上面说的
- 安装Node,参考 Centos下安装node
- 安装mongodb, 参考 mongodb的安装和常用配置项的含义
- 安装 yapi “npm install -g yapi-cli –registry https://registry.npm.taobao.org”
- “yapi server” 启动yapi配置向导,包括yapi的安装位置,mongodb数据库等信息
- “npm install pm2 -g”安装pm2来管理yapi,可以方便的停止 启动等操作
- 启动yapi “pm2 start /your_install_path/vendors/server/app.js –name yapi”,默认的启动端口是3000;登录的默认用户名是:admin@admin.com ; 默认密码:ymfe.org