网站建设资讯

NEWS

网站建设资讯

WEB+NFS+DNS的搭建-创新互联

本次试验用了两个web,一个php和mysql web1,2 (172.16.31.30,31.31)nfs 172.16.31.34

创新互联致力于网站建设、成都做网站,成都网站设计,集团网站建设等服务标准化,推过标准化降低中小企业的建站的成本,并持续提升建站的定制化服务水平进行质量交付,让企业网站从市场竞争中脱颖而出。 选择创新互联,就选择了安全、稳定、美观的网站建设服务!

php 172.16.31.32  mysql 172.16.31.32

WEB+NFS+DNS的搭建

构建如图所示

1,搭建web

首先# mount -t nfs 172.16.31.34:/mydata/mydata   挂载nfs

此次编译和上篇LAMP中web所用的版本是一个版本,编译步骤相同

1)下载apr-1.5.0.tar.bz2 apr-util-1.5.3.tar.bz2 httpd-2.4.9.tar.bz2 这三个包,依次解压,

   # tar xf apr-1.5.0.tar.bz2

   # cd apr-1.5.0

   # ./configure --prefix=/usr/local/apr

   # make && make install

2) 编译安装apr-util

# tar xf apr-util-1.5.3.tar.bz2

# cd apr-util-1.5.3

# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

# make && make install

3)编译安装httpd-2.4.9

# tar xf httpd-2.4.9.tar.bz2

# cd httpd-2.4.9

# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=event

# make && make install

两台都是做如此操作,然后修改PATH环境变量

echo "export PATH=/usr/local/apach/bin:$PATH">> /etc/profile.d/httpd.sh

让PATH在当前shell生效并且启动服务

source /etc/profile.d/httpd.sh

apachectl start

# vim /etc/httpd/httpd.con

LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so  需启用的两个模块

LoadModule proxy_module modules/mod_proxy.so

ServerName www.caoshujia.com:80

ProxyRequests off        关闭正向代理

ProxyPassMatch ^/(.*\.php)$ fcgi://172.16.2.11:9000/mydata/$1    只要是php文件都使用fcgi协议代理到php服务器。

DocumentRoot "/mydata/"                        修改站点根目录为nfs

                     修改对站点根目录的控制标签

DirectoryIndex index.html index.php            添加默认请求文件

AddType application/x-httpd-php .php       在标签中加入,以支持php格式的文件。

AddType application/x-httpd-php-source .phps

# httpd -t

# apache restart

2 php编译安装

1)事先需要安装几个包组,如果安装,无需安装

# yum -y groupinstall "Desktop Platform Development"

# yum -y install bzip2-devel

# yum -y install libmcrypt-devel

2)编译安装

# tar xf php-5.4.26.tar.bz2

# cd php-5.4.26

#./configure --prefix=/usr/local/php --with-mysql --with-mysqli --with-openssl --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --enable-sockets --enable-fpm --with-bz2 --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-mcrypt

# make && make install

3)为php提供配置文件:

# cp php.ini-production /etc/php.ini

4)配置php-fpm

为php-fpm提供SysV init脚本,并将其添加至服务列表:

# cp sapi/fpm/init.d.php-fpm  /etc/rc.d/init.d/php-fpm

# chmod +x /etc/rc.d/init.d/php-fpm

# chkconfig --add php-fpm

# chkconfig php-fpm on

为php-fpm提供配置文件:

# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

编辑php-fpm的配置文件:

# vim /usr/local/php/etc/php-fpm.conf

配置fpm的相关选项为你所需要的值,并启用pid文件(如下最后一行):

pm.max_children = 50

pm.start_servers = 5

pm.min_spare_servers = 2

pm.max_spare_servers = 8

pid = /usr/local/php/var/run/php-fpm.pid

指定php的PID文件所在位置。这条一定要写在[global]下面第一行,不然不会生效。

接下来就可以启动php-fpm了:

# service php-fpm start

检测监听端口

# netstat -tnlp | grep php-fpm

tcp     0    0 127.0.0.1:9000        0.0.0.0:*          LISTEN    689/php-fpm

[root@localhost php-5.4.26]# service php start

[root@localhost php-5.4.26]# mkdir /mydata

[root@localhost php-5.4.26]# mount -t nfs 172.16.31.34:/mydata/mydata 挂载nfs,用来存储php页面。

[root@localhost php-5.4.26]# chown -R nobody /mydata   修改webdata目录的所有者为nobody,                             因为nobody是php进程运行的用户。

3,mysql配置

1首先下载mysql-5.5.33包组(mariadb-5.5.36-linux-x86_64.tar.gz),然后解压mariadb-5.5.36-linux-x86_64.tar.gz到/usr/local

[root@localhost ~]# tar xfmariadb-5.5.36-linux-x86_64.tar.gz -C /usr/local

2准备数据存放的文件系统

 a新建一个sda3

      [root@localhost~]# fdisk /dev/sda

      Command (m for help): n

Commandaction

  e  extended

  p  primary partition (1-4)

p

Partitionnumber (1-4): 3

Firstcylinder (7859-13054, default 7859):

Usingdefault value 7859

Lastcylinder, +cylinders or +size{K,M,G} (7859-13054, default 13054): +20G

Command(m for help): t

Partitionnumber (1-4): 3

Hex code(type L to list codes): 8e   (文件系统为LVM)

Changedsystem type of partition 3 to 8e (Linux LVM)

Command (m for help): w

b读入磁盘中

  [root@localhost ~]# kpartx -af /dev/sda

device-mapper: reload ioctl on sda1failed: Invalid argument

create/reload failed on sda1

device-mapper: reload ioctl on sda2failed: Invalid argument

create/reload failed on sda2

device-mapper: reload ioctl on sda3failed: Invalid argument

create/reload failed on sda3

  [root@localhost ~]# partx -a /dev/sda

BLKPG: Device or resource busy

error adding partition 1

BLKPG: Device or resource busy

error adding partition 2

BLKPG: Device or resource busy

error adding partition 3        (表示已经读入到磁盘中)

c新建逻辑卷,并将其挂载至特定目录,此处目录设置为/mydata

   [root@localhost ~]# pvcreate /dev/sda3

 Physical volume "/dev/sda3" successfully created

[root@localhost ~]# vgcreate myvg/dev/sda3

 Volume group "myvg" successfully created

[root@localhost ~]# lvcreate -L 10G -nmydata myvg

 Logical volume "mydata" created

[root@localhost ~]# mke2fs -t ext4 -LMYDATA -b 4096 -m 3 /dev/myvg/mydata

    并且能开机挂载,编辑fastab文件

    /dev/mapper/vg0-root   /                      ext4   defaults       1 1

UUID=90ebd4cf-95c1-4338-b0dd-19b2b1cb943d/boot                  ext4   defaults       1 2

/dev/mapper/vg0-usr    /usr                   ext4   defaults       1 2

/dev/mapper/vg0-var    /var                   ext4   defaults       1 2

/dev/mapper/vg0-swap   swap                   swap   defaults       0 0

tmpfs                  /dev/shm               tmpfs  defaults       0 0

devpts                 /dev/pts               devpts gid=5,mode=620 0 0

sysfs                  /sys                   sysfs  defaults       0 0

proc                   /proc                  proc   defaults       0 0

LABEL=MYDATA           /mydata                ext4   defaults       0 0

(开机挂载)

d  新建用户以安全方式运行进程,并创建链接

   [root@localhost ~]# groupadd -r mysql

[root@localhost ~]# useradd-g mysql -r mysql

[root@localhost ~]# idmysql

uid=496(mysql)gid=493(mysql) groups=493(mysql)

[root@localhost ~]#chown -R mysql.mysql /mydata/data/

[root@localhost ~]# ll -a/mydata/data/

total 8

drwxr-xr-x 2 mysql mysql4096 Aug 11 20:15 .

先进入/usr/local目录下

[root@localhost local]# ln-sv mariadb-5.5.36-linux-x86_64 mysql

lrwxrwxrwx  1 root root  27 Aug 11 20:18mysql -> mariadb-5.5.36-linux-x86_64

e 为mysql提供主配置文件

cd/usr/local/mysql/

mkdir /etc/mysql创建一个目录,因为在/etc下有个my.cnf

cpsupport-files/my-large.cnf /etc/mysql/my.cnf

vim/etc/mysql/my.cnf

    port           = 3306

socket         =/tmp/mysql.sock

skip-external-locking

key_buffer_size = 256M

max_allowed_packet = 1M

table_open_cache = 256

sort_buffer_size = 1M

read_buffer_size = 1M

read_rnd_buffer_size = 4M

myisam_sort_buffer_size = 64M

thread_cache_size = 8

query_cache_size= 16M

# Try number of CPU's*2 for thread_concurrency

thread_concurrency = 8

datadir = /mydata/data   (指定mysql数据文件的存放位置)

开始初始化

[root@localhostmysql]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data/

(此处必须在 mysql目录下,要在scripts初始化,会报错)

f 为mysql提供sysv服务脚本

  [root@localhostmysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld

然后添加到服务列表中

  [root@localhost mysql]# chkconfig --addmysqld

  [root@localhost mysql]# chkconfig --list mysqld

mysqld          0:off1:off2:on3:on4:on5:on6:off

启动服务

root@localhost mysql]# service mysqld start

Starting MySQL...                                         [ OK ]

[root@localhost mysql]# ss -tnl

State     Recv-Q Send-Q                Local Address:Port                  Peer Address:Port

LISTEN    0     128                               *:52971                            *:*

LISTEN    0     128                              :::50732                           :::*

LISTEN    0     128                              :::111                             :::*

LISTEN    0     128                               *:111                              *:*

LISTEN    0     128                              :::22                              :::*

LISTEN    0     128                               *:22                               *:*

LISTEN    0     128                       127.0.0.1:631                              *:*

LISTEN    0     128                             ::1:631                             :::*

LISTEN    0     100                             ::1:25                              :::*

LISTEN    0     100                       127.0.0.1:25                               *:*

LISTEN    0     128                       127.0.0.1:6010                             *:*

LISTEN    0     128                             ::1:6010                             :::*

LISTEN    0     50                                *:3306                             *:*  (3306端口已启动)

设置权限

  [root@localhostmysql]#chmod +x /etc/rc.d/init.d/mysqld

g 编辑环境变量

[root@localhost~]# vim /etc/profile.d/mysql.sh

exportPATH=/usr/local/mysql/bin:$PATH

h导出头文件和库文件

  ln -sv /usr/local/mysql/include /usr/include/mysql

[root@localhost~]# vim /etc/ld.so.conf.d/mysql.conf(新建)

                  /usr/local/mysql/lib

  让系统重新载入

[root@localhost ~]#ldconfig -v | grep mysql

/usr/local/mysql/lib:

                 libmysqld.so.18 -> libmysqld.so.18

                 libmysqlclient.so.18 ->libmysqlclient_r.so.18.0.0

/usr/lib64/mysql:

                libmysqlclient.so.16 -> libmysqlclient.so.16.0.0

                libmysqlclient_r.so.16 -> libmysqlclient_r.so.16.0.0

[root@localhost ~]#mysql

MariaDB [(none)]> use mysql

MariaDB [mysql]> grant all on discuz.* to disadmin@172.16.31.32 identified by 'root';   为数据库用户disadmin授权在172.16.31.32主机上登陆,密码为 root

配置完成。

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网站名称:WEB+NFS+DNS的搭建-创新互联
网站网址:http://cdweb.net/article/dpdige.html