作者: gemcjz

  • 创建原版Minecraft服务器

    Minecraft现在变得越来越火了,但是大多数人还在自己单机。想要进入服务器又苦于找不到好的亦或是厌烦各种可恶的规矩。那还在等什么?自己建一个吧!

    以下将以Linux为例

    1、使用ssh登陆购买linux服务器

    选择合适的工具

    • MAC OS 打开终端
    • Windows 大家可以百度下有什么可以有的ssh工具
    • Linux 你当然是知道的

    输入以下命令登陆linux服务器

    
    ssh [user]@[ip_address] -p [port]
    
    

    2. 下载你中意的服务器版本

    官方minecraft服务器版本下载地址:minecraft_server

    3、 编写启动脚本

    具体步骤如下:

    创建一个文件夹放置服务器文

    mkdir minecratr_server
    mv minecraft_server*.jar ./minecratr_server/minecraft_server.jar
    

    使用文本编辑器创建脚本文件

    cd minecratr_server
    vim minecraft_server.sh
    

    添加以下内容

    #!/bin/bash
    java -Xmx1024M -Xms512M -jar minecraft_server.jar
    

    设置执行权限

    chmod +x minecraft_server.sh
    

    4. 第一次启动服务器

    启动服务器

    ./minecraft_server.sh

    等待服务器退出

    
    [21:13:34] [Server thread/INFO]: Starting minecraft server version 1.11.2
    [21:13:34] [Server thread/INFO]: Loading properties
    [21:13:34] [Server thread/WARN]: server.properties does not exist
    [21:13:34] [Server thread/INFO]: Generating new properties file
    [21:13:34] [Server thread/WARN]: Failed to load eula.txt
    [21:13:34] [Server thread/INFO]: You need to agree to the EULA in order to run the server. Go to eula.txt for more info.
    [21:13:34] [Server thread/INFO]: Stopping server
    
    

    同意EULA

    vim eula.txt

    将eula=false改为eula=true
    再次启动服务器

    ./minecraft_server.sh

    等待加载完成后,关闭服务器。

    
    [21:14:53] [Server thread/INFO]: Starting minecraft server version 1.11.2
    [21:14:53] [Server thread/INFO]: Loading properties
    [21:14:53] [Server thread/INFO]: Default game type: SURVIVAL
    [21:14:53] [Server thread/INFO]: Generating keypair
    [21:14:53] [Server thread/INFO]: Starting Minecraft server on *:25565
    [21:14:53] [Server thread/INFO]: Using epoll channel type
    [21:14:53] [Server thread/WARN]: Failed to load user banlist:
    java.io.FileNotFoundException: banned-players.json (没有那个文件或目录)
    at java.io.FileInputStream.open0(Native Method) ~[?:1.8.0_111]
    at java.io.FileInputStream.open(FileInputStream.java:195) ~[?:1.8.0_111]
    at java.io.FileInputStream.<init>(FileInputStream.java:138) ~[?:1.8.0_111]
    at com.google.common.io.Files.newReader(Files.java:86) ~[minecraft_server.jar:?]
    at mx.g(SourceFile:136) ~[minecraft_server.jar:?]
    at lg.z(SourceFile:99) [minecraft_server.jar:?]
    at lg.<init>(SourceFile:25) [minecraft_server.jar:?]
    at lh.j(SourceFile:186) [minecraft_server.jar:?]
    at net.minecraft.server.MinecraftServer.run(SourceFile:436) [minecraft_server.jar:?]
    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_111]
    [21:14:53] [Server thread/WARN]: Failed to load ip banlist:
    java.io.FileNotFoundException: banned-ips.json (没有那个文件或目录)
    at java.io.FileInputStream.open0(Native Method) ~[?:1.8.0_111]
    at java.io.FileInputStream.open(FileInputStream.java:195) ~[?:1.8.0_111]
    at java.io.FileInputStream.<init>(FileInputStream.java:138) ~[?:1.8.0_111]
    at com.google.common.io.Files.newReader(Files.java:86) ~[minecraft_server.jar:?]
    at mx.g(SourceFile:136) ~[minecraft_server.jar:?]
    at lg.y(SourceFile:91) [minecraft_server.jar:?]
    at lg.<init>(SourceFile:27) [minecraft_server.jar:?]
    at lh.j(SourceFile:186) [minecraft_server.jar:?]
    at net.minecraft.server.MinecraftServer.run(SourceFile:436) [minecraft_server.jar:?]
    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_111]
    [21:14:53] [Server thread/WARN]: Failed to load operators list:
    java.io.FileNotFoundException: ops.json (没有那个文件或目录)
    at java.io.FileInputStream.open0(Native Method) ~[?:1.8.0_111]
    at java.io.FileInputStream.open(FileInputStream.java:195) ~[?:1.8.0_111]
    at java.io.FileInputStream.<init>(FileInputStream.java:138) ~[?:1.8.0_111]
    at com.google.common.io.Files.newReader(Files.java:86) ~[minecraft_server.jar:?]
    at mx.g(SourceFile:136) ~[minecraft_server.jar:?]
    at lg.A(SourceFile:107) [minecraft_server.jar:?]
    at lg.<init>(SourceFile:29) [minecraft_server.jar:?]
    at lh.j(SourceFile:186) [minecraft_server.jar:?]
    at net.minecraft.server.MinecraftServer.run(SourceFile:436) [minecraft_server.jar:?]
    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_111]
    [21:14:53] [Server thread/WARN]: Failed to load white-list:
    java.io.FileNotFoundException: whitelist.json (没有那个文件或目录)
    at java.io.FileInputStream.open0(Native Method) ~[?:1.8.0_111]
    at java.io.FileInputStream.open(FileInputStream.java:195) ~[?:1.8.0_111]
    at java.io.FileInputStream.<init>(FileInputStream.java:138) ~[?:1.8.0_111]
    at com.google.common.io.Files.newReader(Files.java:86) ~[minecraft_server.jar:?]
    at mx.g(SourceFile:136) ~[minecraft_server.jar:?]
    at lg.C(SourceFile:123) [minecraft_server.jar:?]
    at lg.<init>(SourceFile:30) [minecraft_server.jar:?]
    at lh.j(SourceFile:186) [minecraft_server.jar:?]
    at net.minecraft.server.MinecraftServer.run(SourceFile:436) [minecraft_server.jar:?]
    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_111]
    [21:14:53] [Server thread/INFO]: Preparing level "world"
    [21:14:54] [Server thread/INFO]: Preparing start region for level 0
    [21:14:55] [Server thread/INFO]: Preparing spawn area: 5%
    [21:14:56] [Server thread/INFO]: Preparing spawn area: 10%
    [21:14:57] [Server thread/INFO]: Preparing spawn area: 14%
    [21:14:58] [Server thread/INFO]: Preparing spawn area: 20%
    [21:14:59] [Server thread/INFO]: Preparing spawn area: 26%
    [21:15:00] [Server thread/INFO]: Preparing spawn area: 33%
    [21:15:01] [Server thread/INFO]: Preparing spawn area: 41%
    [21:15:02] [Server thread/INFO]: Preparing spawn area: 49%
    [21:15:03] [Server thread/INFO]: Preparing spawn area: 57%
    [21:15:04] [Server thread/INFO]: Preparing spawn area: 68%
    [21:15:05] [Server thread/INFO]: Preparing spawn area: 76%
    [21:15:06] [Server thread/INFO]: Preparing spawn area: 86%
    [21:15:07] [Server thread/INFO]: Preparing spawn area: 96%
    [21:15:08] [Server thread/INFO]: Done (14.531s)! For help, type "help" or "?"
    
    

    更改服务器配置文件

    vim server.properties

    server.properties配置方法:server.properties
    正式启动服务器

    screen ./minecraft_server.sh

    到此服务器建立完毕,开始享用吧!
    参考:如何建立一个自己的Minecraft服务器 【原版】

  • nginx日志格式配置

    nginx日志对于统计排错来说非常有利的,nginx 日志相关指令主要有两条,一条是log_format,用来设置日志格式,另外一条是access_log,用来指定日志文件的存放路径、格式和缓存大小,通俗的理解就是先用log_format来定义自己想用的日志格式,然后在用access_log定义虚拟主机时或全局日志时在把定义的log_format 跟在后面。

    log_format 格式

    log_format name( 格式名字) 格式样式(即想要得到什么样的日志内容)

    默认的示例:

    
    log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"';
    
    

    注释:

    $remote_addr 与$http_x_forwarded_for 用以记录客户端的ip地址;
    $remote_user :用来记录客户端用户名称;
    $time_local : 用来记录访问时间与时区;
    $request : 用来记录请求的url与http协议;
    $status : 用来记录请求状态;成功是200,
    $body_bytes_s ent :记录发送给客户端文件主体内容大小;
    $http_referer :用来记录从那个页面链接访问过来的;
    $http_user_agent :记录客户端浏览器的相关信息;
    

    还有更多的参数,可以根据自己的需求定义

    用access_log指令日志文件存放路径

    用了log_format 指令设置了日志格式之后,需要用access_log指令指定日志文件的存放路径;

    access_log path(存放路径) format (自定义日志名称)

    示例:

    access_log logs/access.log main;

    我们用log_format 定义了一个mylogformat的日志 我们可以写成这样

    access_log logs/access.log mylogformat ;

    如果不想启用日志 :

    access_log off ;

    注意:

    access.log文件是可以按日期进行分割的,方便查看及处理。

  • FreeBSD定期创建快照

    1、安装sysutils/freebsd-snapshot

    
    portmaster sysutils/freebsd-snapshot
    
    

    2、配置cron

    
    sudo crontab -e
    
    

    添加

    
    # /etc/crontab
    0 * * * * root /usr/local/sbin/periodic-snapshot hourly
    0 0 * * * root /usr/local/sbin/periodic-snapshot daily
    0 0 * * 0 root /usr/local/sbin/periodic-snapshot weekly
    
    

    编辑/etc/periodic.conf

    sudo vim /etc/periodic.conf
    

    添加

    snapshot_enable="YES"
    snapshot_schedule="/home:2:10:0"
    

    上述snapshot_schedule变量值必须符合以下语法:

    <schedule>
    ::= <entry>*
    <entry>
    ::= <fs> (", <fs>)* : <spec>
    <fs>
    ::= /^.*$/
    <spec>
    ::= <gen_weekly> : <gen_daily> : <gen_hourly> <gen_weekly> 
    ::= <generation>
    <gen_daily>
    ::= <generation> <gen_hourly> 
    ::= <generation> ("@ <hour> (", <hour>)*)? <generation> 
    ::= /^[0-9]+$/
    <hour>
    ::= /^(0?[0-9]|1[0-9]|2[0-3])$/
    
  • 使用fail2ban加固服务器

    Fail2Ban 是一个应用程序,它会在太多的失败登录尝试后禁止 IP 地址登录到你的服务器。由于合法登录通常不会超过三次尝试(如果使用 SSH 密钥,那不会超过一个),因此如果服务器充满了登录失败的请求那就表示有恶意访问。

    Fail2Ban 可以监视各种协议,包括 SSH、HTTP 和 SMTP。默认情况下,Fail2Ban 仅监视 SSH,并且因为 SSH 守护程序通常配置为持续运行并监听来自任何远程 IP 地址的连接,所以对于任何服务器都是一种安全威慑。

    安装Fail2Ban

    CentOS 7

    1、确保你的系统已经安装所有的更新:

    yum update

    2、启用 EPEL 更新源:

    
    wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
    rpm -ivh epel-release-latest-7.noarch.rpm
    
    

    3、安装Fail2Ban

    yum install fail2ban

    4、启动Fail2Ban

    systemctl start fail2ban
    systemctl enable fail2ban
    

    Debian

    1、确保你的系统已经安装所有的更新:

    apt-get update
    apt-get upgrade -y
    

    2、安装Fail2Ban

    apt-get install fail2ban

    FreeBSD

    1、确保你的系统ports更新到最新:

    portsnap fetch
    portsnap update
    

    2、安装Fail2Ban

    portmaster security/py-fail2ban

     

     

  • FreeBSD 11发布

    FreeBSD项目正式发布了11分支的第一个稳定版本。

    主要新特性包括:

    • OpenSSH默认禁用DSA密钥生成,移除 Protocol 1支持;
    • OpenSSH更新到7.2p2;
    • 无线支持IEEE 802.11n;
    • 支持AArch64 (arm64) 架构;
    • 从NetBSD项目移植了libblacklist(3)库和应用;
    • 其它包括性能改进和支持更多无线芯片组等等。

    转载自Solidot

  • portmaster使用介绍

    portmaster是一个用来升级ports的工具,它并不依赖于其他的数据库去追踪你已经安装的软件,而仅仅利用现有的ports架构,比如是/var/db/pkg

    portmaster的特点是通过port的依赖追踪而保持你的port随时更新到最新,这能够允许你去安全的更新某一特定的port而不必不得不更新基于这个port的其他软件,当然,在极少的情况下,你有重新编译那些依赖于你更新port的软件的需求,因此你可以用-r选项来完成。

    portmaster默认更新那些你在命令中指定的port,portmaster会去查询是否存在软件的最新版本,然后通过make config命令遍历指定的port和它所依赖port的编译选项,假如你从来没有安装过port或者更改了编译选项,将会有编译选项窗口来提示选择编译选项,当然,如果你想要默认提示所有的选项,可以使用—force-dialog选项

    当portmaster在遍历port的依赖关系的时候,假如你没有使用—packages*选项,portmaster会在后台默认启动一个make checksum进程去检查和验证已经下载和软件包,如果你在此时按了ctrl+c,会默认终止这个检查

    下面介绍一些常用的选项:

    
    --force-config //为所有的ports执行make config,会覆盖-G选项
    -G //阻止make config,也就是使用默认选项
    -B //不为已经安装的ports做备份
    -b //为已经安装的ports做备份
    --update-if-newer //当软件已经是最新了,就不再重新安装,只在命令行后跟软件包才执行
    -P //使用package来安装,假如没有合适的package,也可以用ports替换
    -PP //只使用package安装,假如没有合适的,就放弃安装或者升级
    -a //检查所有的ports,假如有必要就执行升级
    -l //根据ports的分类列出所以已经安装的port
    --index //只使用INDEX-[7-9]去检查port是否已经是最新了
    --no-confirm //在将要执行升级或者安装之前,不询问用户,直接执行
    --package-build //使用package来安装编译过程的一些依赖
    --delete-build-only //当一个port安装完之后,删除只在编译过程中使用依赖ports
    

    举个例子:假如我想更新或者新安装nginx,然后使用package安装编译过去依赖的包,并且在编译完成之后删除它们

    portmaster --packages-build delete-build nginx
    

    假如我要更新所有的包

    
    
  • Android 网络调试 tcpip 开启方法

    1.连接USB数据线,打开usb调试,使用windows的“运行”命令行方式:(此方法需配置adb环境变量,也可直接进入adb工具目录执行\android-sdk-windows\platform-tools\)

    adb tcpip 5555 #(端口号)
    adb usb #使用回usb调试
    adb connect 192.168.1.199 #(Android设备IP地址)
    

    2.无需数据线,且可解决部分机器在方法1时出现的“unable to connect to 192.168.1.199:5555”错误

    在android设备上安装 “终端模拟器”等类似shell命令工具,使用下面命令(需root权限):

    TCP/IP方式:

    setprop service.adb.tcp.port 5555
    stop adbd
    start adbd
    

    usb方式:

    setprop service.adb.tcp.port -1
    stop adbd
    start adbd
    
  • initramfs 文件解压/压缩

    1, 重命名gz 压缩文件

    mv initramfs.img  initramfs.img.gz

    2, 解压文件

    gunzip initramfs.img.gz

    3, 查看文件类型

    file initramfs.img

    4, 创建目录

    mkdir temp
    cd temp
    

    5, 解压目录

    cpio -i -F ../initramfs.img

    6, 压缩文件

    find . | cpio -ov -H newc | gzip >  ../initramfs.img
  • 提高路由器wifi无线速率(OpenWrt固件)

    我的路由器是网件Netgear WND4300,刷的是OpenWrt第三方固件。刷完后开启无线网络,发现iphone5s在5g下无线传输速率只有65Mbps,远低于理论值。后发现需在路由器里做如下配置可解决:
    1,进入路由器管理界面,编辑无线配置,无线安全中把加密设成“WPA2-PSK”,算法“AES”。
    2,HT mode设为40MHz,勾选“强制40MHz频宽”
    3,“无线电功率”也可调整,比如100mW
    4,SSH登录路由器,编辑文件/etc/config/wireless,注意下面的高亮部分的修改:

    
    config wifi-device 'radio0'
        option type 'mac80211'
        option channel '11'
        option hwmode '11ng'
        option path 'pci0000:00/0000:00:11.0'
        option txpower '20'
        option country 'US'
        option htmode 'HT40'
        option noscan '1'
    
    config wifi-device 'radio1'
        option type 'mac80211'
        option hwmode '11na'
        option path 'pci0000:00/0000:00:12.0'
        option country 'US'
        option channel '161'
        option txpower '18'
        option htmode 'HT40+'
        option noscan '1'
    
    config wifi-iface
        option device 'radio1'
        option network 'lan'
        option mode 'ap'
        option ssid 'OpenWrt_5'
        option key '12345678'
        option encryption 'psk2+ccmp'
    
    config wifi-iface
        option device 'radio0'
        option mode 'ap'
        option ssid 'OpenWrt_2'
        option network 'lan'
        option encryption 'psk2+ccmp'
        option key '12345678'
    
    
  • 为最佳性能调优 Nginx

    通常来说,一个优化良好的 Nginx Linux 服务器可以达到 500,000 – 600,000 次/秒 的请求处理性能,然而我的 Nginx 服务器可以稳定地达到 904,000 次/秒 的处理性能,并且我以此高负载测试超过 12 小时,服务器工作稳定。

    这里需要特别说明的是,本文中所有列出来的配置都是在我的测试环境验证的,而你需要根据你服务器的情况进行配置:

    从 EPEL 源安装 Nginx:

    yum -y install nginx

    备份配置文件,然后根据你的需要进行配置:

    cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.orig
    vim /etc/nginx/nginx.conf
    
    # This number should be, at maximum, the number of CPU cores on your system.
    # (since nginx doesn't benefit from more than one worker per CPU.)
    # 这里的数值不能超过 CPU 的总核数,因为在单个核上部署超过 1 个 Nginx 服务进程并不起到提高性能的作用。
    worker_processes 24;
     
    # Number of file descriptors used for Nginx. This is set in the OS with 'ulimit -n 200000'
    # or using /etc/security/limits.conf
    # Nginx 最大可用文件描述符数量,同时需要配置操作系统的 "ulimit -n 200000",或者在 /etc/security/limits.conf 中配置。 
    worker_rlimit_nofile 200000;
     
    # only log critical errors
    # 只记录 critical 级别的错误日志
    error_log /var/log/nginx/error.log crit
     
    # Determines how many clients will be served by each worker process.
    # (Max clients = worker_connections * worker_processes)
    # "Max clients" is also limited by the number of socket connections available on the system (~64k)
    # 配置单个 Nginx 单个进程可服务的客户端数量,(最大值客户端数 = 单进程连接数 * 进程数 )
    # 最大客户端数同时也受操作系统 socket 连接数的影响(最大 64K )
    worker_connections 4000;
     
    # essential for linux, optmized to serve many clients with each thread
    # Linux 关键配置,允许单个线程处理多个客户端请求。
    use epoll;
     
    # Accept as many connections as possible, after nginx gets notification about a new connection.
    # May flood worker_connections, if that option is set too low.
    # 允许尽可能地处理更多的连接数,如果 worker_connections 配置太低,会产生大量的无效连接请求。
    multi_accept on;
     
    # Caches information about open FDs, freqently accessed files.
    # Changing this setting, in my environment, brought performance up from 560k req/sec, to 904k req/sec.
    # I recommend using some varient of these options, though not the specific values listed below.
    # 缓存高频操作文件的FDs(文件描述符/文件句柄)
    # 在我的设备环境中,通过修改以下配置,性能从 560k 请求/秒 提升到 904k 请求/秒。
    # 我建议你对以下配置尝试不同的组合,而不是直接使用这几个数据。
    open_file_cache max=200000 inactive=20s;
    open_file_cache_valid 30s;
    open_file_cache_min_uses 2;
    open_file_cache_errors on;
     
    # Buffer log writes to speed up IO, or disable them altogether
    # 将日志写入高速 IO 存储设备,或者直接关闭日志。
    # access_log /var/log/nginx/access.log main buffer=16k;
    access_log off;
     
    # Sendfile copies data between one FD and other from within the kernel.
    # More efficient than read() + write(), since the requires transferring data to and from the user space.
    # 开启 sendfile 选项,使用内核的 FD 文件传输功能,这个比在用户态用 read() + write() 的方式更加高效。
    sendfile on;
     
    # Tcp_nopush causes nginx to attempt to send its HTTP response head in one packet,
    # instead of using partial frames. This is useful for prepending headers before calling sendfile,
    # or for throughput optimization.
    # 打开 tcp_nopush 选项,Nginux 允许将 HTTP 应答首部与数据内容在同一个报文中发出。
    # 这个选项使服务器在 sendfile 时可以提前准备 HTTP 首部,能够达到优化吞吐的效果。
    tcp_nopush on;
     
    # don't buffer data-sends (disable Nagle algorithm). Good for sending frequent small bursts of data in real time.
    # 不要缓存 data-sends (关闭 Nagle 算法),这个能够提高高频发送小数据报文的实时性。
    tcp_nodelay on;
     
    # Timeout for keep-alive connections. Server will close connections after this time.
    # 配置连接 keep-alive 超时时间,服务器将在超时之后关闭相应的连接。
    keepalive_timeout 30;
     
    # Number of requests a client can make over the keep-alive connection. This is set high for testing.
    # 单个客户端在 keep-alive 连接上可以发送的请求数量,在测试环境中,需要配置个比较大的值。
    keepalive_requests 100000;
     
    # allow the server to close the connection after a client stops responding. Frees up socket-associated memory.
    # 允许服务器在客户端停止发送应答之后关闭连接,以便释放连接相应的 socket 内存开销。
    reset_timedout_connection on;
     
    # send the client a "request timed out" if the body is not loaded by this time. Default 60.
    # 配置客户端数据请求超时时间,默认是 60 秒。
    client_body_timeout 10;
     
    # If the client stops reading data, free up the stale client connection after this much time. Default 60.
    # 客户端数据读超时配置,客户端停止读取数据,超时时间后断开相应连接,默认是 60 秒。
    send_timeout 2;
     
    # Compression. Reduces the amount of data that needs to be transferred over the network
    # 压缩参数配置,减少在网络上所传输的数据量。
    gzip on;
    gzip_min_length 10240;
    gzip_proxied expired no-cache no-store private auth;
    gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;
    gzip_disable "MSIE [1-6].";
    

    启动 Nginx 并配置开机自动启动。

    service nginx start
    chkconfig nginx on