Home > VPS, 服务器管理 > Linode VPS (LAMP+VPN)配置笔记

Linode VPS (LAMP+VPN)配置笔记

June 28th, 2010

昨天一时兴起,买了个 Linode 的 512 型 VPS 折腾了一下。玩了一天了,才学会顺利搭建LAMP环境 、安装VPN服务器 。过程中也犯了不少错误。在这里记录一下安装、配置过程和遇到了一些简单的错误处理。

由于Linode 是基于 Xen 虚拟化的 VPS 。 这相当于在菜场买了一台裸机、因此要想能用,得经历装系统、装软件、配置等一系列的过程。

一、基础运行环境

1、选择数据中心

2、安装 Linux 内核操作系统,我选择了玩CentOS 5.5

3、启动系统

4、ssh、sftp登陆管理、安装系统安全补丁

5、系统设置 ( 主机别名、时间等)

二、CentOS 5 下 AMP  ( Apache + MySql + PHP ) 网站服务器工作环境搭建

1、安装/配置 Apache Web Server

安装 Apache :
yum update
yum install httpd

备份 Apache 配置文件 :
cp /etc/httpd/conf/httpd.conf ~/httpd.conf.backup

配置虚拟主机 :
vi  /etc/httpd/conf.d/vhost.conf

NameVirtualHost VPS IP :80

<VirtualHost domain.com:80>
ServerAdmin domain@domain.com
ServerName domain.com
ServerAlias www.domain.com
DocumentRoot /srv/www/domain.com/public_html/
ErrorLog /srv/www/domain.com/logs/error.log
CustomLog /srv/www/domain.com/logs/access.log combined
</VirtualHost>

创建文件夹 :
mkdir -p /srv/www/domain.com/public_html
mkdir -p /srv/www/domain.com/logs

启动 /重启Apache:

/etc/init.d/httpd start
/etc/init.d/httpd reload

配置设置为开机启动 :
/sbin/chkconfig –levels 235 httpd on

2、安装/配置 MySQL

安装 MySQL

yum install mysql-server

配置设置为开机启动 :
/sbin/chkconfig –levels 235 mysqld on

启动/重启 MySQL

/etc/init.d/mysqld start
/etc/init.d/mysqld reload

配置MySQL / 建立数据库

mysql_secure_installation (注意修改密码、删除示例)
mysql -u root -p (登入)
create database lollipop; (创建)
grant all on lollipop.* to ‘foreman’ identified by ’5t1ck’; (赋与权限 / 用户名、密码创建)
quit (退出)

3、安装/配置 PHP

安装PHP

yum install php php-pear

配置PHP

vi /etc/php.ini

error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR
display_errors = Off
log_errors = On
error_log = /var/log/php.log
max_execution_time = 300
memory_limit = 64M
register_globals = Off

安装 PHP5-Mysql 包

yum install php-mysql

4、至止,已经可以通过 IP 访问了 , 只需修改域名 A/CNAME 记录,即可实现网站在 VPS 上面的托管

以上代码抄自 1、Linode基础 2、Linode CentOS 5 LAMP 配置

Tips :

Apache 设置中控制直接 IP 访问显示所需内容的方法 : 设置一个servername是本机IP地址的虚拟主机

<VirtualHost 220.110.4.5:80>
ServerName 220.110.4.5
DocumentRoot /var/www/html/
</VirtualHost>

三、WordPress 安装 (不解释)

cd 虚拟主机目录

wget http://wordpress.org/latest.zip

unzip latest.zip

alias cp=cp

cp -rf wordpress/* .

rm -rf wordpress/ latest.zip

惯例配置 wp-config.php ( 已经 wordpress 3.0 了,需要添加多网站支持 ,参见 WordPress 正式版更新到3.0 )

以上代码抄自 ssh 升级 wordpress

四、CentOS 5 下 PPTP VPN 服务器安装配置 (32 位版本的安装命令行、不解释)

yum install -y ppp iptables

wget http://acelnmp.googlecode.com/files/pptpd-1.3.4-1.rhel5.1.i386.rpm

rpm -ivh pptpd-1.3.4-1.rhel5.1.i386.rpm

vi /etc/pptpd.conf
localip 192.168.0.1 (去注释)
remoteip 192.168.0.234-238,192.168.0.245 (去注释)

vi /etc/ppp/chap-secrets
username pptpd password *

vi /etc/ppp/options.pptpd
ms-dns 8.8.8.8
ms-dns 8.8.4.4

vi /etc/sysctl.conf
net.ipv4.ip_forward=1 (一般默认为0,修改为1)

sysctl -p

/etc/init.d/pptpd restart

/sbin/iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o eth0 -j MASQUERADE

chkconfig pptpd on chkconfig iptables on

以上为CentOS 5 32位系统 PPTP VPN 服务器安装代码无解释版本。

以上代码抄自 CentOS 5 VPS配置pptpd为VPN服务器

Tips 1 :

部分特定的网站可能会无法正常访问。比如我无法访问 fc2.com alexa.com 等。通常出现这个问题是 MTU 问题。

解决方案 : 修改ppp接口的MTU

vi /etc/ppp/ip-up

在倒数第二行加入如下内容: /sbin/ifconfig $1 mtu 1400

service pptpd restart

以上问题解决方法来自 centos 5.4 pptp vpn详细安装配置教程

Tips 2 : xen 服务器重启后、VPN可能登陆,但是无法收到数据包

解决方案 : 重新 设置 iptable 、重启pptpd

/sbin/iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o eth0 -j MASQUERADE

/etc/init.d/pptpd restart

五、CentOS 5 下 FTP (vsftpd)安装、配置

1、安装
yum -y install vsftpd

2、启动
service vsftpd start

3、随开机启动
chkconfig –level 35 vsftpd on

4、查看 VPS 正在监听的端口
netstat -tl

5、禁止匿名用户
vi /etc/vsftpd/vsftpd.conf
anonymous_enable=NO

6、设定 ftp 目录
chgrp -R ftp   /home/wwwroot
chmod -R 777  /home/wwwroot

7、增加 ftp 用户
adduser –d /home/wordpress –g ftp –s /sbin/nologin usersx
passwd usersx

8、重启 ftp
service vsftpd restart

9、用户管理
userdel 选项 用户名 #删除用户
常用的选项是-r,它的作用是把用户的主目录一起删除。
passwd 选项 用户名 #修改口令
passwd -l 用户名 锁定口令,即禁用账号。
passwd -u 用户名 口令解锁。
passwd -d 用户名 使账号无口令。
passwd -f 用户名 强迫用户下次登录时修改口令。
如果默认用户名,则修改当前用户的口令。
如果是超级用户,可以用下列形式指定任何用户的口令:
passwd 用户名
passwd -d 用户名 此命令将用户的口令删除,这样用户下一次登录时,系统就不再询问口令

以上代码和说明均抄自 centOS 5.4 vsftpd安装配置

admin VPS, 服务器管理 , , ,

  1. July 22nd, 2010 at 12:15 | #1

    chown

    chgrp

    chmod

  2. August 2nd, 2010 at 01:24 | #2

    查看网络端口状态 netstat -tnlp

  3. August 19th, 2010 at 17:37 | #3

    I think your blog post was secretly a awesome kick off to a potential series of articles about this topic. So many users act like they comprehend what they are talking about when it comes to this stuff and generally, very few people actually get it. You seem to really dominate it however, so I think you need to start writing more. Thanks a lot!

  1. No trackbacks yet.