您的位置:首页 > 运维架构 > Linux

VPS LINUX系统上安装配置LNMP 以及挂载硬盘 ,并把数据库和网站弄到挂载硬盘上!

2012-07-26 13:54 901 查看
首先需要安装 lnmp 环境:

网址:http://lnmp.org (参考网址) 按照步骤一步一步的来没有问题!

挂载硬盘 

先通过fdisk -l查看目前磁盘分区状况

[root@MyVPS ~]# fdisk -l
Disk /dev/xvda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
  Device Boot Start End Blocks Id System
  /dev/xvda1 * 1 13 104391 83 Linux
  /dev/xvda2 14 1044 8281507+ 8e Linux LVM

Disk /dev/xvdb: 23.6 GB, 23622320128 bytes
255 heads, 63 sectors/track, 2871 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System

我们可以看到/dev/xvdb容量有23.6G,而且没有分区,接下来我们对它进行分区和挂载

# fdisk /dev/xvdb

[root@MyVPS ~]# fdisk /dev/xvdb
The number of cylinders for this disk is set to 2871.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

输入n新建分区
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p

/dev/xvdb中第1个分区
Partition number (1-4): 1
First cylinder (1-2871, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-2871, default 2871):
Using default value 2871

输入W保存退出
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

通过上述步骤我们已将/dev/xvdb分区完成,下面我们对分区格式化并进行挂载

将新分区xvdb1(此名称因系统而异)格式化为ext3格式

# mkfs -t ext3 /dev/xvdb1

[root@MyVPS ~]# mkfs -t ext3 /dev/xvdb1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
2883584 inodes, 5765319 blocks
288265 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
176 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 24 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

将新分区xvdb1挂载,我们示例挂载到/home1目录。新建目录/home1,然后挂载:

# mkdir /home1
# mount /dev/xvdb1 /home1

完成后我们通过df -hal可以看到,新分区已经挂载到目录/home1上了

[root@MyVPS ~]# df -hal
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
5.7G 1.4G 4.1G 25% /
proc 0 0 0 - /proc
sysfs 0 0 0 - /sys
devpts 0 0 0 - /dev/pts
/dev/xvda1 99M 28M 67M 30% /boot
tmpfs 256M 0 256M 0% /dev/shm
none 0 0 0 - /proc/sys/fs/binfmt_misc
sunrpc 0 0 0 - /var/lib/nfs/rpc_pipefs
/dev/xvdb1 22G 173M 21G 1% /home1

然后编辑/etc/fstab使分区在开机时自动挂载到home1

# echo "/dev/xvdb1 /home1 ext3 defaults 1 2" >> /etc/fstab

通过上述步骤已经完成硬盘未分区部分分区和挂载,并实现开机时自动挂载。在后台重装系统时,只要选择只格系统盘就可实现重装而不丢失新分区数据。

重装系统后,不用重新分区,直接按上面挂载分区步骤进行挂载即可读取该分区数据。

到现在位置硬盘挂载已经没问题了!

接下来就是把网站和数据库弄到挂载硬盘上了!

2种方法:如果一开始你输入的域名就是你用的域名的话:那么修改/usr/local/nginx/conf/nginx.conf 里面的路径即可! 要重启nginx 服务!

如果用:[b][b]/root/vhost.sh 这个命令只需要 在填写的时候把路径写上去即可![/b][/b]

把数据库放在挂载硬盘上,这个我可费劲了!

我首先修改的mysql 配置文件路径:/etc/my.cnf 但是修改完路径后重启后,在启动mysql 的时候会报错误!发现/tmp/mysql.sock 不见了 郁闷!

试了很久,还是找不到,在百度上查了好久,最后决定重新装一下环境!

环境装好后,首先把这个文件在本地备份一下,然后修改my.cnf 依旧报错!刚才发牢骚了,下面解决方法:

停止mysql,/etc/init.d/mysql stop移动/usr/local/mysql/var/ 到新目录,修改/etc/my.cnf ,查找[mysqld] ,在下面加入datadir = /data/mysql/ (这个路径是你想放在的路径) ,给新目录加权限(不知加上权限弄得777),重启/etc/init.d/mysql start 注意,修改前先备份数据!!!!...

OK了!

这样挂载硬盘上面就有你的网站和数据库了 再也不怕做系统数据丢失了!

写了这么多,在此小广告一下,我的vps 在http://www.ffvps.com上买的 总体还行!卖的是质量。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐