Linux: Build a simple NFS server

Source: Internet
Author: User
Tags php and mysql

First, we need to prepare three virtual machines. Here we will use the clone method to prepare them. Open the "VM" option of the virtual machine.

Find the "clone" option in it, click Next, and save it to the prepared directory,

Name them www1, www2, and NFS respectively, and then open these three VMS,

At this point, the preparation is complete. Before you begin, check whether the compiling environment is installed, that is, whether the following software package groups are installed: "Legacy Software Development legacy network server X software development document tools document librarys" after these software packages are installed, check whether firewall is disabled, run the setup command, and check whether the firewall is disabled, the above are sure there is no problem, so we will first set the host names of the three hosts,

Edit/etc/hosts and add a line in it, as shown below

192.168.0.146 nfs.a.org NFS this is the first host's 192.168.0.145 www1.a.org www1 second host 192.168.0.147 www2.a.org www2 third host

 

Edit/etc/sysconfig/network and modify it as follows:

Hostname = nfs.a.org hostname of the first Server = www1.a.org hostname of the second server = www2.a.org

 

Then, run the following command on each host:

Hostname nfs.a.org first hostname www1.a.org second hostname www2.a.org third host

 

If you use SSH to log on, You need to log on again. In this case, your host name has changed, as shown in the following figure:

[root@nfs~]#[root@www1 ~]#[root@www2~]#

 

Now it indicates that you have successfully changed the name, and you can start later.

Step 1: first establish the underlying NFS server, create a MySQL database on the NFS server, create a webpage storage directory htdocs, and then share the webpage storage directory with the other two hosts.

Create a MySQL database first. Before creating a MySQL database, make the following preparations:

First, create the required user and user group. The command is as follows:

groupadd -g 3306 mysqluseradd -u 3306 -M -s /sbin/nologin -g mysql mysql

 

Run the command: Id MySQL to verify

Then you need to create/www/mydata and/www/htdocs

Run the following command:

mkdir -pv /www/{mydata,htdocs}

 

Then we need to prepare two logical volumes, one for storing/data and the other for storing/htdocs.

# fdisk /dev/sdaThe number of cylinders for this disk isset to 15665.There is nothing wrong with that, but thisis larger than 1024,and could in certain setups cause problemswith:software that runs at boot time (e.g.,old versions of LILO)booting and partitioning software fromother OSs(e.g., DOS FDISK, OS/2 FDISK)Command (m for help): nFirst cylinder (8926-15665, default 8926):Using default value 8926Last cylinder or +size or +sizeM or +sizeK(8926-15665, default 15665): +10GCommand (m for help): tPartition number (1-6): 6Hex code (type L to list codes): 8eChanged system type of partition 6 to 8e(Linux LVM)

 

Create logical volume

# partprobe /dev/sda# pvcreate /dea/sda{6,7}#vgcreate myvg /dev/sda{6,7}# lvcreate -L 10G -n mydata myvg# lvcreate -L 5G -n htdocs myvg

 

Format two partitions

# mke2fs -j –L MYDATA /dev/myvg/mydata# mke2fs -j –L HTDOCS /dev/myvg/htdocs

 

Then mount,

mount /dev/myvg/mydata /www/mydatamount /dev/myvg/htdocs /www/htdocs

 

Modify/etc/fstab to enable mounting upon startup

LABEL=MYDATA /www/mydata/data ext3 defaults 0 0LABEL=NFS /www/nfs ext3 defaults 0 0

 

Then create the directory data under/www/mydata

mkdir /www/mydata/data

 

Modify the master and Group of the mydata directory

cd /wwwchown -R mysql:mysql mydata/data

 

Now the preparation is complete,

Start compiling and installing the MySQL source package:

# Tar xf mysql-5.5.15-linux2.6-i686.tar.gz-C/usr/local/# cd/usr/local/# ln-SV mysql-5.5.15-linux2.6-i686 MySQL # setenforce 0 // disable SELinux to prevent interference # cd MySQL # scripts/mysql_install_db -- User = MySQL -- datadir =/www/mydata/data # cp support-files/MySQL. server/etc/init. d/mysqld # chkconfig -- add mysqld # chown root: mysql-R. # chown MYSQL: MySQL/www.mydata-R # cp support-files/my-large.cnf/etc/My. CNF # Vim/etc/My. cnfthread_concurrency = 2 datadir =/www/mydata/Data

 

Start the MySQL service and configure the password for the root user.

# export PAHT=$PATH:/usr/local/mysql/binsource $PATH# service mysqld start# mysqlmysql> GRANT ALL PRIVILEGES ON *.* TOroot@'%.%.%.%' IDENTIFIED BY 'redhat';mysql> FLUSH PRIVILEGES;mysql> quit

 

Create an Apache user

# Groupadd APACHE-G 48 # useradd APACHE-m-u 48-G 48-S/bin/bash // note that you need to know/bin/bash

 

Configure to enable NFS service

#

Service Portmap statusportmap (PID 2177) is running... // It should be running. If not, service Portmap restart # Vim/etc/exports/www/htdocs 192.168.0.0/24 (RW, async) # Vim/etc/sysconfig/nfs // modify the NFS service port to prevent it from occupying other service ports: mountd_port = 10010statd_port = 10011rquotad_port = 10012statd_outgoing_port = 10013 # service NFS start # showmount-A // check next, make sure the service is normal. If it cannot be displayed, you may have forgotten to modify/etc/hostall mount points on nfs.a.org: 192.168.0.48:/xiha.

 

Step 2: configure the www1 and www2 servers, and install httpd and PHP. The two servers have the same configuration. Take www1 as an example.

Install httpd, PhP5, and PHP-mysql using yum

yum install httpd php5 php-mysql –y

 

Mount the NFS Shared File System

mkdir /wwwmount –t nfs 172.16.1.100:/www/htdocs /web

 

Modify the httpd configuration file so that the home page is stored in the/web directory.

vim /etc/httpd/conf/httpd.confDocumentRoot "/www"AddType application/x-httpd-php .phpAddType application/x-httpd-php-source .phpDirectoryIndex index.html index.html.varindex.php

 

Enable the HTTPd service and test whether PHP and MySQL work normally.

service httpd start

 

Step 3: Install the WordPress webpage

Decompress the Web package on the NFS server

Unzip wordpress.zip

Enter 192.168.0.145 to go to the webpage installation page.

Enter root in mysq database username

Password: RedHat

Database location: 192.168.0.146

Create a Web page management account and password admin Admin

Continue to the next step. installation is complete.

Post the xiha topic on 192.168.0.144, and enter 192.168.0.145 in the browser. If the webpage is displayed normally and there is a xiha topic, it indicates that it is successful.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.