原标题:Linux 虚拟主机安装
Linux 虚拟主机安装
* 注意,修改 Unix/Linux 任何配置文件,最后需要保留一个 Unix 换行 *
==================== 配置 APT 源 ====================
vi /etc/apt/sources.list
deb http://mirrors.163.com/debian squeeze main non-free contrib
deb http://mirrors.163.com/debian squeeze-proposed-updates main contrib non-free
deb http://mirrors.163.com/debian-security squeeze/updates main contrib non-free
deb-src http://mirrors.163.com/debian squeeze main non-free contrib
deb-src http://mirrors.163.com/debian squeeze-proposed-updates main contrib non-free
deb-src http://mirrors.163.com/debian-security squeeze/updates main contrib non-free
deb http://http.us.debian.org/debian squeeze main contrib non-free
deb http://security.debian.org squeeze/updates main contrib non-free
最后需要保留一个 Unix 换行
==================== 更新 APT 源 ====================
apt-get update
如果提示需要继续更新,则继续执行此命令
==================== 安装 SSH ====================
apt-get install ssh
==================== 配置 SSH ====================
vi /etc/ssh/sshd_config
UseDNS no
如果没有则增加这个参数到最后一行
GSSAPIAuthentication no
重启 SSH 使其生效
/etc/init.d/ssh restart
==================== 配置主机名 ====================
vi /etc/hostname
修改主机名为 localhost
==================== 配置DNS ====================
vi /etc/resolv.conf
nameserver 61.139.2.69
nameserver 202.98.96.68
nameserver 218.6.200.139
nameserver 8.8.8.8
nameserver 61.139.2.69
nameserver 202.98.96.68
nameserver 218.6.200.139
nameserver 8.8.8.8
nameserver 8.8.4.4
==================== 配置 Fsck ====================
vi /etc/default/rcS
FSCKFIX=yes
==================== 配置带有颜色区分的 ls 命令 ====================
vi /root/.bashrc
把下面这几行的注释去掉
# You may uncomment the following lines if you want `ls' to be colorized:
export LS_OPTIONS='--color=auto'
eval `dircolors`
alias ls='ls $LS_OPTIONS'
alias ll='ls $LS_OPTIONS -l'
alias l='ls $LS_OPTIONS -lA'
==================== 安装软件包 ====================
apt-get -y install gcc g++ make screen rsync perl dnsutils psmisc rdate ifstat sysstat tcpdump sun-java6-jre
==================== 网络配置 ====================
vi /etc/network/interfaces
auto lo
auto eth0
iface lo inet loopback
iface eth0 inet static
address 192.168.1.241
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.2
post-up iptables-restore < /etc/iptables.up.rules
==================== IPTables ====================
#!/bin/bash
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -p tcp --sport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --sport 443 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
iptables -A INPUT -p tcp --dport 5535:5555 -j ACCEPT
iptables -A INPUT -s 210.209.69.223 -d 210.209.69.223 -j ACCEPT
iptables -A INPUT -s 125.65.113.73 -p tcp --dport 3306 -j ACCEPT
iptables -A INPUT -s 125.65.113.40 -p tcp --dport 3306 -j ACCEPT
iptables -A INPUT -s 8.8.8.8/32 -p udp --sport 53 -j ACCEPT
iptables -A INPUT -s 8.8.4.4/32 -p udp --sport 53 -j ACCEPT
iptables -A INPUT -p icmp -s 125.65.112.36/32 -j ACCEPT
iptables -A INPUT -s 125.65.113.36/32 -p udp --dport 161 -j ACCEPT
iptables -A INPUT -s 125.65.113.60/32 -p tcp --dport 873 -j ACCEPT
iptables -A INPUT -s 221.122.112.159/32 -p tcp --dport 56000 -j ACCEPT
iptables -A INPUT -s 221.122.112.160/32 -p tcp --dport 56000 -j ACCEPT
iptables -A INPUT -s 182.148.112.78 -j ACCEPT
iptables -A INPUT -s 125.65.112.58 -j ACCEPT
iptables -A INPUT -s ntp.api.bz -p udp --sport 123 -j ACCEPT
iptables -A INPUT -s 0.asia.pool.ntp.org -p udp --sport 123 -j ACCEPT
iptables -A INPUT -j DROP
iptables -A OUTPUT -o lo -j ACCEPT
iptables -A OUTPUT -d 8.8.8.8/32 -p udp --dport 53 -j ACCEPT
iptables -A OUTPUT -d 8.8.4.4/32 -p udp --dport 53 -j ACCEPT
iptables -A OUTPUT -d 125.65.113.36/32 -p udp --sport 161 -j ACCEPT
iptables -A OUTPUT -d ntp.api.bz -p udp --dport 123 -j ACCEPT
iptables -A OUTPUT -d 0.asia.pool.ntp.org -p udp --dport 123 -j ACCEPT
iptables -A OUTPUT -p udp -j DROP
==================== 安装 Apache ====================
apt-get -y install apache2-mpm-worker apache2-suexec libapache2-mod-fcgid libfcgi-perl
apt-get -y install apache2-suexec
apt-get -y install libapache2-mod-fcgid libfcgi-perl
==================== 配置 Apache ====================
/etc/apache2/apache2.conf
ServerName 127.0.0.1
LogFormat "%t %a %{X-Forwarded-For}i %A %H %m %p %{Host}i %U %{Referer}i" newlog
CustomLog /var/log/apache2/access.log newlog
# 服务器允许配置的进程数上限
ServerLimit 16
# 服务器启动时建立的子进程数
StartServers 2
# 允许同时伺服的最大接入请求数量
MaxClients 1024
# 最小空闲线程数
MinSpareThreads 25
# 最大空闲线程数
MaxSpareThreads 75
# 每个子进程建立的线程数
ThreadsPerChild 64
# 每个子进程在其生存期内允许伺服的最大请求数量
MaxRequestsPerChild 0
vi /etc/apache2/conf.d/security
ServerTokens Prod
启用 Suexec 模块
ln -s /etc/apache2/mods-available/suexec.load /etc/apache2/mods-enabled/suexec.load
启用 Rewrite 模块
ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load
修改 FastCGI 配置
vi /etc/apache2/mods-available/fcgid.conf
AddHandler fcgid-script .php
IPCConnectTimeout 3
IPCCommTimeout 60
IdleTimeout 60
IdleScanInterval 30
BusyTimeout 60
BusyScanInterval 30
ErrorScanInterval 3
ZombieScanInterval 3
ProcessLifeTime 300
MaxRequestsPerProcess 500
==================== 默认主机配置 ====================
vi /etc/apache2/sites-available/default
ServerName 127.0.0.1
DocumentRoot /var/www/
Options FollowSymLinks
AllowOverride None
Order Deny,Allow
Deny from all
重启 Apache
/etc/init.d/apache2 restart
==================== 安装 PHP ====================
apt-get -y install php5-cgi php5-gd php5-mcrypt php5-sqlite php5-xsl php5-curl php5-mysql php5-odbc php5-sybase
apt-get -y install php5-cgi
apt-get -y install php5-gd
apt-get -y install php5-mcrypt
apt-get -y install php5-sqlite
apt-get -y install php5-xsl
apt-get -y install php5-curl
apt-get -y install php5-mysql
apt-get -y install php5-odbc
apt-get -y install php5-sybase
==================== 安装 MySQL ====================
apt-get -y install mysql-server
vi /etc/mysql/my.cnf
bind-address = 0.0.0.0
[client]
# 设置默认的字符集
default-character-set=utf8
[mysqld]
lower_case_table_names=1 # 表名不区分大小写
default-character-set=utf8 # 设置默认的字符集
skip-name-resolve # 禁止反向解析
innodb_file_per_table # 使用多表空间
key_buffer = 512M
max_connections = 10000
tmp_table_size = 256M
table_cache = 512
重启 MySQL
/etc/init.d/mysql restart
==================== 安装 vsFTPd ====================
apt-get install vsftpd
修改 /etc/vsftpd.conf
anonymous_enable=NO
local_enable=YES
chroot_local_user=YES
write_enable=YES
local_umask=022
修改 /etc/pam.d/vsftpd
#auth required pam_shells.so
删除 FTP 匿名帐号
deluser ftp
删除 FTP 匿名帐号主目录
rm -rf /home/ftp
重启 vsFTPd
/etc/init.d/vsftpd restart
==================== 磁盘配额 ====================
apt-get install quota
修改 /etc/fstab 加入 usrquota
重启服务器
reboot
quotacheck -mcf /
或
quotacheck -c /home
启用配额
quotaon /
关闭配额
quotaoff /
================== 新建虚拟主机过程 =============
创建目录
mkdir -p /var/www/config/web12345
mkdir -p /var/www/wwwroot/web12345/wwwroot/cgi-bin
生成网站配置文件
/var/www/config/web12345/php5
#!/bin/sh
export PHPRC=/var/www/config/web12345
export PHP_FCGI_CHILDREN=1
export PHP_FCGI_MAX_REQUESTS=5000
exec /usr/bin/php5-cgi -d open_basedir = /var/www/wwwroot/web12345/wwwroot/:/tmp/
添加用户
useradd -s /bin/false -g www-data -d /var/www/wwwroot/web -m web
设置用户密码
chpasswd web web
复制网站模版
cp -r templates/0/web/* /var/www/wwwroot/web12345/wwwroot
设置磁盘所有者
chown -R web12345:www-data /var/www/wwwroot/web12345
设置磁盘配额
setquota web12345 1024000 1024000 0 0 /
或
setquota web12345 1024000 1024000 0 0 /home
建立新文件
/etc/apache2/sites-available/web12345
ServerName 12show.vhost018.cn
ServerAlias www.160link.com
DocumentRoot /var/www/wwwroot/12show/wwwroot
ScriptAlias /php5-cgi "/usr/bin/php5-cgi"
ScriptAlias /cgi-bin/ "/var/www/wwwroot/12show/wwwroot/cgi-bin/"
DirectoryIndex index.php default.cgi index.htm index.html default.htm default.html
Action php-script "/php5-cgi"
AddHandler php-script .php
Options FollowSymLinks
AllowOverride All
启用网站命令
ln -s /etc/apache2/sites-available/web12345 /etc/apache2/sites-enabled/web12345
/etc/init.d/apache2 restart
禁用网站命令
unlink /etc/apache2/sites-enabled/web78042
/etc/init.d/apache2 restart返回搜狐,查看更多
责任编辑: