作者: 8bto

  • Apache mod_deflate(gzip)

    在Apache中,可以啟用mod_deflate來壓縮網頁,傳送給client後再由client端解壓縮,可以大大節省頻寬的使用

    開啟方法:

    #先到apache的httpd.conf中把mod_deflate.so註解拿掉(如果預設有引入的話就代表已經有使用deflate壓縮囉)

    LoadModule deflate_module libexec/apache22/mod_deflate.so

    #Ubuntu可以使用指令開啟

    a2enmod deflate

    接著可以在Apache設定檔(httpd.conf)中自訂一些設定

    <IfModule mod_deflate.c>

    #壓縮等級1~9,等級越高壓縮效能越好

    DeflateCompressionLevel 9

    #設定要壓縮的類型

    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/javascript application/x-httpd-php

    #自訂Log格式及存放位置

    DeflateFilterNote ratio

    LogFormat ‘”%r” %b (%{ratio}n) “%{User-agent}i”‘ deflate

    CustomLog /var/log/deflate_log deflate

    </IfModule>

    其他更細部的操作,例如BrowserMatch等等,可以直接參考Apache mod_deflate的說明

    設定完成後重新啟動Apache即可,可以透過這個網站測試

  • FreeBSD防火墙Firewall(ipfw)

    先將kernel複製出來

    mkdir /usr/local/etc/FreeBSD

    cd /usr/src/sys/i386/conf

    cp GENERIC /usr/local/etc/FreeBSD/MYKERNEL

    ln -s /usr/local/etc/FreeBSD/MYKERNEL

    vi /usr/local/etc/FreeBSD/MYKERNEL

    加入

    options IPFIREWALL #firewall

    options IPFIREWALL_VERBOSE #enable logging to syslogd(8)

    options IPFIREWALL_FORWARD #packet destination changes

    options IPFIREWALL_DEFAULT_TO_ACCEPT #allow everything by default

    cd /usr/src;make kernel

    完成後開始設定

    vi /etc/rc.conf

    加入

    #firewall

    firewall_enable=”YES”

    firewall_logging=”YES”

    firewall_script=”/etc/rc.firewall”

    vi /etc/rc.firewall

    將內容全部刪除改為

    #!/bin/sh

    fwcmd=”/sbin/ipfw”

    Trust_IP1=”127.0.0.1″ #這裡要換成server本身的IP

    Trust_IP2=”120.119.1.0/24″ #可通過的網段

    UnTrust_IP1=”192.83.191.0/24″

    Allowed_TCP_In_1=”22,25,53,80,443″

    #you want to open port

    Traceroute=”33433-33499″

    Allowed_UDP_Out=”20,21,53,113″

    Allowed_UDP_In=”20,21,53,113″

    Allowed_UDP_ftp_Out=”65000-65500″

    Allowed_UDP_ftp_In=”65000-65500″

    Allowed_TCP_ftp_Out=”65000-65500″

    Allowed_TCP_ftp_In=”65000-65500″

    #ipfw [add/del/fwd] [serial] [allow/deny] [protocol] [from] [ports] to [destation] [ports]

    $fwcmd -f flush

    #flush ipfw tables

    $fwcmd add 1 allow ipv6 from any to any

    $fwcmd add 00010 allow tcp from me to any setup keep-state

    $fwcmd add 00021 check-state

    $fwcmd add 00030 allow ip from ${Trust_IP1} to any

    $fwcmd add 00031 allow ip from ${Trust_IP2} to any

    $fwcmd add 00060 allow icmp from any to any

    $fwcmd add 00061 allow udp from any to any $Traceroute

    $fwcmd add 00120 deny ip from ${UnTrust_IP1} to me

    $fwcmd add 00121 deny tcp from ${UnTrust_IP1} to me 25

    $fwcmd add 56000 allow tcp from any to any ${Allowed_TCP_In_1}

    $fwcmd add 56003 allow udp from any ${Allowed_UDP_In} to any

    $fwcmd add 56004 allow udp from any to any ${Allowed_UDP_ftp_Out}

    $fwcmd add 56005 allow tcp from any to any ${Allowed_TCP_ftp_Out}

    $fwcmd add 65534 deny log ip from any to any

    #deny all ip

    $fwcmd zero

    #clean counter

    sh /etc/rc.firewall &

    reboot

  • FreeBSD安裝sshguard-ipfw

    請先完成ipfw設置

    cd /usr/ports/security/sshguard-ipfw;make install clean

    在/etc/syslog.conf 中

    #auth.info;authpriv.info |exec /usr/local/sbin/sshguard

    註解去掉

    也可以自由設定鎖定時間

    例如:

    auth.info;authpriv.info |exec /usr/local/sbin/sshguard -a 5 -p 7200 -s 3600

    (a:失敗多少次 p:被擋多久(秒) s:多少秒忘記攻擊)

    最後/etc/rc.d/syslogd restart

    接著你可以tail -f /var/log/auth.log,然後用putty連線,密碼請故意打錯四次,就會出現:

    Jan 26 13:31:05 earth sshguard[40059]: Blocking 210.71.11.116:4 for >420secs: 4 failures over 2 seconds.

    解除鎖定:

    使用另一個IP登入

    ipfw show

    ipfw delete xxxxx

  • FreeBSD安装pure-ftpd

    cd /usr/ports/ftp/pure-ftpd

    make install clean(選UTF-8)

    cd /usr/local/etc

    cp pure-ftpd.conf.sample pure-ftpd.conf

    vi /etc/rc.conf

    加入

    pureftpd_enable=”YES”

    ftp傳輸檔案時是有特定的port,

    如果防火牆有擋port,可以自行設定ftp檔案傳輸的port

    vi /usr/local/etc/pure-ftpd.conf

    將PassivePortRange這行改成

    PassivePortRange 65000 65500

    啟用ftp

    /usr/local/etc/rc.d/pure-ftpd start

  • FreeBSD Samba安装及设定

    cd /usr/ports/net/samba34

    make install clean

    (選擇 LDAP、ADS、CUPS、WINBIND、ACL_SUPPORT、SYSLOG、UTMP)

    vi /etc/rc.conf

    samba_enable=”YES”

    vi /usr/local/etc/smb.conf

    #加入工作群組

    workgroup = WORKGROUP

    #主機名稱

    server string = %h Samba Server

    (%h為主機名稱變數)

    #設定使用者家目錄

    原為:

    [homes]

    comment = Homes Directories

    browseable = no

    writable = yes

    更改為:

    [homes]

    comment = Home directory for %u on %h

    browseable = no

    writable = yes

    path = /usr/home/%u/

    valid users = %S

    #設定共享資料夾

    [public]

    comment = %h Shared Public Directory

    path = /usr/home/samba/public

    force directory mode = 0777

    force create mode = 0777

    force group = nobody

    force user = nobody

    public = yes

    writeable = yes

    read only = no

    #測試Samba conf中語法有無錯誤

    /usr/local/bin/testparm | more

    mkdir /usr/home/samba

    mkdir /usr/home/samba/public

    chmod 777 /usr/home/samba/public

    #新增Samba帳戶

    使用者必須同時設定兩種帳號: FreeBSD 的使用者帳號、 Samba 的使用者帳號 才能正常登入 Samba 伺服器。

    smbpasswd -a 帳號

    /usr/local/etc/rc.d/samba restart

    #個別設定資料夾設定

    [aaa]

    comment = aaa

    path = /home/samba/my2075/aaa

    valid users = aaa, admin2075

    write list = aaa, admin2075

    browseable = No

    [bbb]

    comment = bbb

    path = /home/samba/my2075/bbb

    valid users = bbb, admin2075

    write list = bbb, admin2075

    browseable = No

    [ccc]

    comment = ccc

    path = /home/samba/my2075/ccc

    valid users = ccc, admin2075

    write list = ccc, admin2075

    browseable = No

    #samba變數

    %S: 取代目前的「資源名稱」,所謂的「資源名稱」就是在 [ ] 裡面的內容。ex: valid users = %S

    %U: 代表目前登入的使用者的使用者名稱。

    %m: 代表 Client 端的 NetBIOS 名稱。

    %g: 代表登入的使用者的群組名稱。

    %M: 代表 Client 端的 Internet 主機名稱,就是 HOSTNAME。

    %L: 代表 SAMBA 主機的 NetBIOS 名稱。

    %h: 代表目前這部 SAMBA 主機的 HOSTNAME。

    %H: 代表使用者的家目錄。

    %I: 代表 Client 端的 IP。

    %T: 代表目前的日期與時間。

    #Samba 使用下列的通訊埠:

    Port 135/TCP – used by smbd

    Port 137/UDP – used by nmbd

    Port 138/UDP – used by nmbd

    Port 139/TCP – used by smbd

    Port 445/TCP – used by smbd

    #Windows網路芳鄰切換使用者

    進cmd模式

    net use * /delete

  • FreeBSD MySQL忘记密码

    今天使用時出現

    ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (61)

    其實是忘記密碼啦XDD

    #背景執行mysql安全模式

    mysqld_safe -u root –skip-grant-tables &

    #登入mysql(不用密碼)

    mysql -u root -p

    >use mysql

    >UPDATE user SET password=password(‘這裡輸入你的密碼’) where user=’root’;

    >FLUSH PRIVILEGES;

    >exit

    /usr/local/etc/rc.d/mysql-server restart

  • 一行HTML5语法将浏览器变成编辑器

    data:text/html, <html contenteditable>

  • FreeBSD安裝phpmyadmin

    cd /usr/ports/databases/phpmyadmin

    make install clean

    cp -r /usr/local/www/phpMyAdmin /usr/local/www/apache22/data/phpmyadmin

    cd /usr/local/www/apache22/data/phpmyadmin

    cp config.sample.inc.php config.inc.php

    chmod 644 config.inc.php

  • 在Debian里面用quota配置磁盘限额

    实现磁盘配额限制步骤:

    1. 内核里面打开了配额的支持,绝大部分发行版都打开的

    2. 以配额方式加载文件系统

    3.安装配额软件:

    4.配置配额

    原/etc/fstab的一项:

    /dev/hda1 /home ext2 defaults 1 1

    做如下修改:

    /dev/hda1 /home ext2 defaults,usrquota 1 1

    如何是对组限制就将usrquota改为grpquota

    重新加载文件系统:

    mount -o remount,usrquota /home

    加载内核模块,并让其开机的时候也会自动加载

    modprobe quota_v2

    echo ‘quota_v2’ >> /etc/modules

    我们要在启用配额的分区创建文件并且限制root才能读写

    touch /home/aquota.user

    touch /home/aquota.group

    chmod 600 /home/aquota.user /home/aquota.group

    现在来安装quota软件:

    apt-get install quota quotatool

    如果不想重起机器来打开磁盘配额

    quotacheck -vagum

    现在到最后一步了,假设我们要对系统里的某个用户skx进行限制配额:

    quotatool -u skx -bq 200M -l ‘250 Mb’ /home

    系统管理员可以用如下命令看到 磁盘配额

    repquota /home

    如果想把一个用户的限制取消只用把他的限制配额设为0

    对了,如果是20G,那就要写20000M,quotatool好像不认 20G的。

    收工~~

    其实现在一般情况下也用不到这个磁盘限额。

  • Linux服务器一键安装包

    CentminMod

    http://centminmod.com/

    Nginx Auto Installer – PHP – MySQL

    http://serversreview.net/nginx-auto-installer-php-mysql

    TuxLite

    http://tuxlite.com/

    https://github.com/Mins/TuxLite

    Minimal & Minstall & Server

    https://github.com/maxexcloo/

    TigersWay

    https://github.com/TigersWay/VPS

    Debian-Server

    https://github.com/mikegioia/Debian-Server

    LNMP-xcache-PHPMyAdmin

    https://github.com/AhmadShamli/LNMP-xcache-PHPMyAdmin

    Nginx-Setup-Script

    https://github.com/mikemansell/Nginx-Setup-Script

    LNMPA

    https://github.com/XWay/LNMPA

    NGinxAutoInstall.sh

    https://github.com/nicolargo/debianpostinstall

    VladGh.com-LEMP

    https://github.com/vladgh/VladGh.com-LEMP/tree/next

    https://github.com/scott23/VladGh.com-LEMP/tree/update

    lowendscript

    https://github.com/jkilgore/lowendscript

    https://github.com/sotiri/lowendscript

    https://github.com/ilevkov/lowendscript

    小朱的两个

    http://www.centos.bz/lnmp/

    http://www.centos.bz/lamp/

    QLNMP

    http://qlnmp.forum.openfans.org/

    http://code.google.com/p/qlnmp/

    Linux + Apache + Nginx + MySQL + PHP Auto Install Script

    https://github.com/wangyan/lanmp

    LEMP

    http://bbs.linuxtone.org/thread-1582-1-1.html

    http://docs.linuxtone.org/autoinstall/

    AceLNMP

    http://code.google.com/p/acelnmp/

    lnmp-project

    http://code.google.com/p/lnmp-project/downloads/list

    Centos,Debian

    http://code.google.com/p/lnmp-auto-install/