分类: *BSD

学习BSD-UNIX系统

  • FreeBSD 10: Installing Apache 2.4, MySQL 5.5, and PHP5.5 — 找不到 libphp5.so

    今天装freebsd 10,然后装apache,再装php和php扩展.没有问题.

    然后重启apache,发现打不开php页面,提示下载.

    刚开始以为php5安装错误了,于是又重新安装一次,发现安装php5时里面没有apache选项了,整了半天也没有发现原因,以前用freebsd8配置apache+php+mysql从来没出现过这种问题,就再试一下php53目录,make config-recursive看看里面是有apache选项的,郁闷,于是又出墙google,终于找到答案了,ls /usr/local/libexec/apache22/ 没找到libphp5.so

    然后/usr/ports/www/mod_php5

    make install clean;rehash安装,可是又遇到问题了,提示“Error from bsd.apache.mk. apache22 is installed (or APACHE_PORT is defined) and port requires apache”,郁闷之极,只能再google,呵呵,又被我找到答案了,万能的google啊,谢谢!关于“Error from bsd.apache.mk. apache22 is installed (or APACHE_PORT is defined) and port requires apache”请参考这篇文章

  • FreeBSD 11 on Raspberry Pi

    Install FreeBSD 11 on a Raspberry Pi

     

    It seems a nice project to try out FreeBSD on a Raspberry Pi.

    There are ready made images available from FreeBSD.org, so this is not very hard to accomplish. Both for FreeBSD 10 as well as for FreeBSD 11. Feeling wild, I choose for FreeBSD 11 🙂

    The image can be downloaded from the FreeBSD ftp-servers.

    Bunzip your image and dd it to a SD-card

     

    I got the FreeBSD-11.0-CURRENT-arm-armv6-RPI-B-20140811-r269824.img.bz2 but perhaps when you read this there are allready newer images available.

    On a Debian GNU/Linux laptop I ran the command:

    bunzip2 FreeBSD-11.0-CURRENT-arm-armv6-RPI-B-20140811-r269824.img.bz2

    Followed by:

    dd if=FreeBSD-11.0-CURRENT-arm-armv6-RPI-B-20140811-r269824.img of=/dev/mmcblk0 bs=1M

    Be carefull when you issue this last command, when you got the of= part wrong, you might inreversable destroy things!

    Now you have a 1Gb big image on your SD card.

    Put the SD card in the Raspberry Pi and power up.

    The very first time you boot FreeBSD on your Raspberry Pi it seems to take ages before you get a prompt. This is because FreeBSD is expanding the partion to fill your whole SD card. In my case it was a 8 Gb SD card. I rebooted the thing and now it did not take that long to give you a prompt.

    When you have a prompt, press enter and log on as root, with an empty password (just hit Enter on the password prompt).

    Now you first need to add a user, make that part of the group “wheel” and give this user a password. This is needed in order to log on to your FreeBSD Raspberry Pi over ssh.

    Set fixed address

    Default your FreeBSD Raspberry Pi will get its network configuration over DHCP. This is great if you want that, but I like my servers to have fixed addresses.

    In /etc/rc.conf you can set the fixed address of the board and add a line with the default router:

    ifconfig_ue0=”inet 192.168.0.123 netmask 255.255.255.0″

    defaultrouter=”192.168.0.1″

    Do not forget to check /etc/resolv.conf to see if this has the right nameserver(s).

    Set timezone

    Become root.

    Make a symbolic link for your timezone to /etc:

    ln -s /usr/share/zoneinfo/Europe/Amsterdam /etc/localtime

    Update the time on your board;

    ntpdate -v -b in.pool.ntp.org

    And edit /etc/rc.conf, add the following line:

    ntpdate_enable=”YES”

    ntpd_enable=”YES”

    Configure sshd

     

    When your Raspberry Pi is connected to the internet, it is important to harden your sshd_config. The best is to disable password login, only allow public key authentication and only for restricted users. Something like “Match Group wheel” is a good start.

    No pkg install

     

    Unfortunately, installing pre-compiled binary packages with the new pkg will not work on your Raspberry Pi.

    Hardware stability is an issue

     

    I own several Raspberry Pies and not all of them are stable. Also the Raspberry Pi is notorious picky about the powersupply cable (USB cable) as well as the powersupply. Problems with the powersupply cable and the powersupply are hard to diagnose.

    If you run into problems, the USB cable and the powersupply are the first things to check. I have seen Raspberries that, when powered on, only show a single, red, LED burning, with all the other LEDs are off. This often is the result of a USB-cable or power supply not playing nice with the Rapsberry – even if the same combination have run wihout problems for weeks.

    On the other hand, there are also a couple Raspberries running in my network with high uptimes and never have shown any problem …

  • FreeBSD install shadowsocks-libev

    cd /usr/ports/net/shadowsocks-libev

    make install clean;rehash

    ee /etc/rc.conf 加入

    shadowsocks_libev_enable=”YES”
    shadowsocks_libev_flags=”-c /usr/local/etc/shadowsocks-libev/config.json”

    在/usr/local/etc/shadowsocks-libev/config.json中加入

    {
    “server”:”136.0.16.99″,
    “server_port”:1234,             //服务端端口
    “local_address”: “127.0.0.1”,
    “local_port”:4321,                 //客户端端口
    “password”:”password”,      //客户端连接密码
    “timeout”:300,
    “method”:”aes-256-cfb”     //加密方式
    }

    然后客户端,在本地,用config.json文件内容对shadowsocks-gui进行相应配置并运行客户端,

    shadowsocks-gui下载地址:http://sourceforge.net/projects/shadowsocksgui/files/dist/

    最后设置浏览器代理。Chrome 推荐使用 SwitchySharp 切换代理设置。把浏览器代理设为下列参数即可:

    协议: socks5

    地址: 127.0.0.1

    端口: 你填的 local_port

    service shadowsocks-libev restart

    ok应该可以科学上网了

  • FreeBSD安装Pure-FTPd及user manager for PureFTPd

    1、首先安装需要配置好apache2/mysql/php等服务!前面有过笔记。

    2、安装pure-ftpd

    cd /usr/ports/ftp/pure-ftpd/

    make with_language=simplified-chinese install clean;rehash

    安装时,会有选择项;勾选:

    MYSQL Support for users in mysql database

    PRIVSEP Enable privileges separation

    PERUSERLIMITS Per-user concurrency limits

    THROTTLING Bandwidth throttling

    BANNER Show pure-ftpd welcome upon session start

    UTF8 Support for charset conversion (expreimental)

    安装完成后 添加pureftpd_enable=”YES”到/etc/rc.conf文件中。

    3、创建MySQL数据库,登陆mysql

    INSERT INTO mysql.user (Host, User, Password, Select_priv, Insert_priv, Update_priv, Delete_priv, Create_priv, Drop_priv, Reload_priv, Shutdown_priv, Process_priv, File_priv, Grant_priv, References_priv, Index_priv, Alter_priv, ssl_cipher, x509_issuer, x509_subject)

    VALUES(‘localhost’,’ftp’,PASSWORD(‘tmppasswd’),’Y’,’Y’,’Y’,’Y’,’N’,’N’,’N’,’N’,’N’,’N’,’N’,’N’,’N’,’N’, Hex(“”), Hex(“”), Hex(“”));

     

    FLUSH PRIVILEGES;

    CREATE DATABASE ftpusers;

    USE ftpusers;

     

    drop table if exists ftpusers.admin;

    CREATE TABLE ftpusers.admin (

    Username varchar(35) NOT NULL default ”,

    Password char(32) binary NOT NULL default ”,

    PRIMARY KEY (Username)

    ) ;

    — Data for table ‘admin’

    INSERT INTO ftpusers.admin VALUES (‘Administrator’,MD5(‘tmppasswd’));

    — Table structure for table ‘users’

    drop table if exists ftpusers.users;

    CREATE TABLE ftpusers.users (

    `User` varchar(16) NOT NULL default ”,

    `Password` varchar(32) binary NOT NULL default ”,

    `Uid` int(11) NOT NULL default ’14’,

    `Gid` int(11) NOT NULL default ‘5’,

    `Dir` varchar(128) NOT NULL default ”,

    `QuotaFiles` int(10) NOT NULL default ‘500’,

    `QuotaSize` int(10) NOT NULL default ’30’,

    `ULBandwidth` int(10) NOT NULL default ’80’,

    `DLBandwidth` int(10) NOT NULL default ’80’,

    `Ipaddress` varchar(15) NOT NULL default ‘*’,

    `Comment` tinytext,

    `Status` enum(‘0′,’1’) NOT NULL default ‘1’,

    `ULRatio` smallint(5) NOT NULL default ‘1’,

    `DLRatio` smallint(5) NOT NULL default ‘1’,

    PRIMARY KEY (`User`),

    UNIQUE KEY `User` (`User`)

    ) ;

    — Data for table ‘users’

    INSERT INTO ftpusers.users VALUES (‘ftpuser_1’,MD5(‘tmppasswd’),65534, 31, ‘/usr’, 100, 50, 75, 75, ‘*’, ‘Ftp user (for example)’, ‘1’, 0, 0);

     

     

    配置pure-ftpd.conf

    cp /usr/local/etc/pure-ftpd.conf.sample pure-ftpd.conf

    编辑pure-ftpd.conf文件 ee pure-ftpd.conf

    MySQLConfigFile /usr/local/etc/pureftpd-mysql.conf

    CreateHomeDir yes

    DisplayDotFiles no

    保存退出

    配置pureftpd-mysql.conf

    cd /usr/local/etc/

    fetch http://machiel.generaal.net/files/pureftpd/v2.x/pureftpd-mysql.conf

    或者自己网站上镜像下载

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

     

    安装User manager for PureFTPd

    cd /usr/ports/www/usermanager/

    make install clean;rehash

     

    以上全部正确安装完毕后:进入ftp目录下载

    http://machiel.generaal.net/files/pureftpd/ftp_v2.1.tar.gz或自己网站镜像

    解压后http://ip/ftp/install.php安装即可。

    Step [1 – 7]

    This configuration script has carried out a few checks to see if everything is ready to start the configuration.

    Checking if config.php exists OK!

    Checking if config.php is writable OK!

    Checking if PHP Extension MYSQL is enabled OK!

    Checking if PHP Extension PCRE is enabled OK!

    Checking if PHP Extension POSIX is enabled OK!

    Checking if PHP Extension SESSION is enabled OK!

    Please choose your configuration type:.选择New installation,create a new database.

     

    Step [3 – 7]输入正确的root用户和root的密码。

    Settings MySQL database.直接按默认设置(要是你改过密码,就输入你的密码)

    Step [4 – 7]语言选择中文,选择Quota support,Ratio support(上传下载比可以选择或不选择)按Save按钮保存配置文件,然后点Setp5进行下一步。

    Step [5 – 7]这里你可以更改管理员Administator的密码,也可以创建一个自己的帐号代替Administrator

    Step [6 – 7]系统有一些提示,说需要编辑那2个配置文件,因为前面已经编辑过了。所以直接下一步。

    Step [7 – 7]恭喜你安装完成了。建议把install.php文件更改一下名称

     

  • freebsd enter full pathname of shell or return ro /bin/sh

    解决方法:

     

    开机后进入单机模式,选择4

     

    或者是输入#boot -s

     

    然后执行

     

    /sbin/fsck

     

    /sbin/mount -a

     

    重新启动ok

  • freebsd 统计连接数查看外部IP

    服务器上的一些统计数据:

     

    1)统计80端口连接数

     

    netstat -nat|grep -i “80”|wc -l

     

    1

     

    2)统计httpd协议连接数

     

    ps -ef|grep httpd|wc -l

     

    1

     

    3)、统计已连接上的,状态为“established’

     

    netstat -na|grep ESTABLISHED|wc -l

     

    2

     

    4)、查出哪个IP地址连接最多,将其封了.

     

     

    netstat -na|grep ESTABLISHED|awk ‘{print $5}’|awk -F: ‘{print $1}’|sort|uniq -c|sort -r +0n

    netstat -na|grep SYN|awk ‘{print $5}’|awk -F: ‘{print $1}’|sort|uniq -c|sort -r +0n

     

     

    netstat快速查看一下TCP连接情况

    netstat -n | awk ‘/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}’

    通过man netstat可以了解SYN_RCVD的意义。SYN_RCVD表示当前未完成的TCP SYN队列

     

    用命令:

     

    # netstat -an | grep SYN | wc -l

     

    $netstat -an | grep SYN_RECV | wc

    97 582 7857

    $netstat -an | grep 80 | wc

    916 5500 74164

  • FreeBSD中绑定多IP

    vi /etc/rc.conf

    以下是我在虚拟机中的一个绑定多IP示例:

     

    # Created: Sat Apr 10 17:06:56 2010

    # Enable network daemons for user convenience.

    # Please make all changes to this file, not to /etc/defaults/rc.conf.

    # This file now contains just the overrides from /etc/defaults/rc.conf.

    # — sysinstall generated deltas —

    ifconfig_em0=”inet 192.168.245.11 netmask 255.255.255.0″

    gateway_enable=”NO”

    defaultrouter=”192.168.245.2″

    hostname=”192.168.245.11″

    ifconfig_em0=”inet 192.168.245.14 netmask 255.255.255.0″

    ifconfig_em0_alias0=”inet 192.168.245.15 netmask 255.255.255.0″

    ifconfig_em0_alias1=”inet 192.168.245.16 netmask 255.255.255.0″

    ifconfig_em0_alias2=”inet 192.168.245.17 netmask 255.255.255.0″

    defaultrouter=”192.168.245.2″

    hostname=”192.168.245.11″

    sshd_enable=”yes”

     

    最后执行如下命令,让rc.conf立即生效

    # sh /etc/rc

  • /usr was not properly dismounted解决办法

    今天在FreeBSD用dmesg命令查看信息时,发现最后几行出现了错误 提示信息:

    /usr was not properly dismounted
    /tmp was not properly dismounted
    /var was not properly dismounted

    几经周折,终于解决了,解决方法如下:

    shutdown -h now /halt/reboot/

  • FreeBSD下查看各软件版本命令

    查看FreeBSD版本: uname -a

    root# uname -a

    FreeBSD power 8.1-RELEASE FreeBSD 8.1-RELEASE #0: Mon Jul 19 02:36:49 UTC 2010 root@mason.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC amd64

    查看apache版本: apachectl -v

    root#apachectl -v

    Server version: Apache/2.2.15 (FreeBSD)

    Server built: Nov 26 2010 16:07:59

    查看php版本:php -v

    root#php -v

     

    Copyright (c) 1997-2010 The PHP Group

    Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies

    with Zend Extension Manager v1.2.2, Copyright (c) 2003-2007, by Zend Technologies

    with Zend Optimizer v3.3.0, Copyright (c) 1998-2007, by Zend Technologies

    查看php模块:php -m

     

    查看mysql版本:mysql -V(大写V哦)

    root#mysql -V

    mysql Ver 14.14 Distrib 5.1.53, for portbld-freebsd8.1 (amd64) using 5.2