Openbsd 3.8上安装配置 APACHE + MYSQL + PHP + mod_limitipco
本文旨在用OPENBSD自己提供的软件安装包来搭建服务器环境,当然你也可以下载原代码包编译安装,但这样就费时费力了。实际上OPENBSD给我们提供了大量的编译好的二进制安装包,利用这些二进制安装包我们可以快速部署我们需要的服务器环境,不仅省时还可以保障OPENBSD的安全性,还可以自动解决各个安装包之间的包依赖问题(用pkg_add来安装远程服务器上的软件包,包依赖问题会自动处理不需要认为干预,这个有点像通过PORT安装)。下面的文档在一个E文的文档基础上经过整理补充后形成的,那个E文档找不到了。
设立网络安装服务器的地址:
# export PKG_PATH=ftp://ftp.openbsd.org/pub/OpenBSD/3.8/packages/i386/
1. 配置APACHE服务器:
因为APACHE是系统默认安装的,这里就省去了安装过程,下面配置APACHE这样就可以开机运行HTTP了因为在/ETC/RC脚本中已经有了HTTPD服务的启动设置
# vi /etc/rc.conf
改:
httpd_flags=NO
为:
httpd_flags=""
对apache做一初步设置
# vi /var/www/conf/httpd.conf
ExtendedStatus On
ServerAdmin llzqq@126.com
ServerName llzqq.3322.org
ServerTokens Prod
ServerSignature Off
Options Indexes FollowSymLinks 改为 Options FollowSymLinks
2. 安装mysql-server-4.0.24p1:
# pkg_add -v mysql-server-4.0.24p1.tgz
# cp /usr/local/share/mysql/my-medium.cnf /etc/my.cnf
如果不想让其他机器连接MYSQL,可以通过下面的操作实现:
# vi /etc/my.cnf
bind-address = 127.0.0.1
启动MYSQL-SERVER服务器:
# /usr/local/bin/mysqld_safe &
设置ROOT的MYSQL密码:
# /usr/local/bin/mysqladmin -u root password mypass
对于chroot下的 mysql:
#mkdir /var/www/var
#chmod -R 1777(或者777) /var/www/var
#vi /etc/my.conf
mysql启动后会产生/var/www/var/run目录,还需要chmod -R 777 /var/www/var/run
自行建立/var/www/var/run
[client]
socket = /var/www/var/run/mysql/mysql.sock
[mysqld]
socket = /var/www/var/run/mysql/mysql.sock
open-files-limit = 8192
open-files = 1000
了方便启动和关闭MYSQL服务建立了下面的脚本:
# vi /etc/rc.d/mysqld.sh
========================================================
#!/bin/sh
# made by llzqq
# mail:openbsd@163.com
# mysql startup scripts
case "$1" in
start)
if [ -x /usr/local/bin/mysqld_safe ]; then
/usr/local/bin/mysqld_safe &
fi
;;
stop)
pkill mysqld &
rm -f /var/run/mysql/mysql.sock &
;;
*)
echo "$0 start | stop"
;;
esac
exit 0
========================================================
# chmod 555 /etc/rc.d/mysqld.sh
设置开机启动MYSQL
# vi /etc/rc.local
if [ -f /etc/my.cnf ]; then
/etc/rc.d/mysqld.sh start
fi
3. 安装配置PHP-4.4.1
# pkg_add -v php4-core-4.4.1p0.tgz
运行下面的命令使其生效
# cp /usr/local/share/examples/php4/php.ini-recommended /var/www/conf/php.ini
# /usr/local/sbin/phpxs -s
由于OPENBSD上的APACHE采用了CHROOT机制,要保证PHP正常工作就要建下面的目录PHP工作目录:
# mkdir /var/www/tmp
# chmod 1777 /var/www/tmp
下面选择安装几个PHP组件:
# pkg_add -v php4-gd-4.4.1p0-no_x11.tgz
# /usr/local/sbin/phpxs -a gd
# pkg_add -v php4-mysql-4.4.1p0.tgz
# /usr/local/sbin/phpxs -a mysql
# pkg_add -v php4-ncurses-4.4.1p0.tgz
# /usr/local/sbin/phpxs -a ncurses
# pkg_add -v php4-imap-4.4.1p0.tgz
# /usr/local/sbin/phpxs -a imap
# pkg_add -v php4-curl-4.4.1p0.tgz
# /usr/local/sbin/phpxs -a curl
# pkg_add -v php4-dbx-4.4.1p0.tgz
# /usr/local/sbin/phpxs -a dbx
# pkg_add -v php4-ldap-4.4.1p0.tgz
# /usr/local/sbin/phpxs -a ldap
# pkg_add -v php4-pdf-4.4.1p0.tgz
# /usr/local/sbin/phpxs -a pdf
# pkg_add -v php4-snmp-4.4.1p0.tgz
# /usr/local/sbin/phpxs -a snmp
设置apache支持PHP:
# vi /var/www/conf/httpd.conf
DirectoryIndex index.html index.php
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
# vi /var/www/conf/php.ini
doc_root= "/htdocs"
register_globals = On
建立测试php页面
# vi /var/www/htdocs/test.php
<?php phpinfo(); ?>
测试一下:
# pkill httpd
# /usr/sbin/httpd
在浏览器中输入http://IP/test.php实验一下
4. 安装mod_limitipconn模块来限制单IP的并发连接数
# wget http://dominia.org/djao/limit/mod_limitipconn-0.04.tar.gz
# tar xzf mod_limitipconn-0.04.tar.gz
# cd mod_limitipconn-0.04
# vi Makefile
APXS = /usr/sbin/apxs
# make
# make install
让APACHE支持这个模块:
# vi /var/www/conf/httpd.conf
<IfModule mod_limitipconn.c>
<Location />
MaxConnPerIP 5
</Location>
</IfModule>
到次整个安装过程结束。
附件部分:
我们为让APACHE支持SSL传输配置APACHE:
# vi /var/www/conf/httpd.conf
添加下面两行:
SSLCertificateFile /etc/ssl/server.crt
SSLCertificateKeyFile /etc/ssl/private/server.key
为了使APACHE启动时启用SSL,设置一下APACHE启动选项:
# vi /etc/rc.conf.local
改:
httpd_flags="" # or it could have httpd_flags=NO
为:
httpd_flags="-DSSL # or it could have httpd_flags=NO
手动启动和关闭APACHE这样做就可以了:
# apachectl startssl
# apachectl stop
下面是设置APACHE+SSL的过程:
1. 创建服务器KEY文件 (1024 bit) :
# /usr/sbin/openssl genrsa -out /etc/ssl/private/server.key 1024
2. 创建服务器CSR文件(certificate signing request)
# /usr/sbin/openssl req -new -key /etc/ssl/private/server.key -out /etc/ssl/private/server.csr
这里自己填写一些注册信息
3. 生成签名证书(365天有效证书):
# /usr/sbin/openssl x509 -req -days 365 -in /etc/ssl/private/server.csr -signkey /etc/ssl/private/server.key -out /etc/ssl/server.crt
4. 虚拟主机部分:
NameVirtualHost 192.168.10.1:*
<VirtualHost 192.168.10.1:443>
ServerAdmin llzqq@126.com
DocumentRoot /var/www/llzqq
ServerName llzqq.home.com
ErrorLog logs/llzqq.home.com-error_log
CustomLog logs/llzqq.home.com-access_log common
SSLEngine on
SSLCipherSuite ALL:!ADH:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP
SSLCertificateFile /etc/ssl/virtualsite.com.crt
SSLCertificateKeyFile /etc/ssl/private/server.key
</VirtualHost>
<VirtualHost 192.168.10.1:80>
ServerAdmin llzgg@126.com
DocumentRoot /var/www/llzgg
ServerName llzgg.home.com
ErrorLog logs/llzgg.home.com-error_log
CustomLog logs/llzgg.home.com-access_log common
</VirtualHost>
其他部分待续(现在没PC装OPENBSD了有些资料不好整理了)
下一篇:NetBSD 4.0 正式版官方下载地址