十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
众所周知,LAMP平台时目前应用最为广泛的网站服务器架构,其中的“A”对应着web服务软件的Apache HTTP Server ,随着Nginx在工作环境中的使用越来越多,LNMP(或LEMP)架构也受到越来越多的Linux运维工程师的青睐。
创新互联专注于大英企业网站建设,成都响应式网站建设公司,成都做商城网站。大英网站建设公司,为大英等地区提供建站服务。全流程专业公司,专业设计,全程项目跟踪,创新互联专业和态度为您提供的服务
就像构建LAMP平台一样,构建LNMP平台也需要Linux服务器、MySQL数据库、PHP解析环境,区别主义在于Nginx与PHP的协作配置上。
准备工作
Centos 7操作系统一台;
Windows 客户端一台;
案例所需镜像及软件包请访问:https://pan.baidu.com/s/10wFG1YQaY2FTJKgMp1x0kw
提取码:rl3i
部署前准备
①挂载Linux光盘,拷贝nginx依赖程序到/usr/src/目录
[root@centos02 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@centos02 ~]# cp /mnt/nginx-1.6.0.tar.gz /usr/src/
②切换LAMP光盘,将mnt目录下所有数据拷贝到/usr/src/目录[root@centos02 ~]# umount /mnt/
[root@centos02 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@centos02 ~]# cp /mnt/* /usr/src/
③切换到操作系统光盘[root@centos02 ~]# umount /mnt/
[root@centos02 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
Nginx具体配置及概述请访问博客:Centos 7部署Nginx网站服务
[root@centos02 ~]# rm -rf /etc/yum.repos.d/CentOS-*
[root@centos02 ~]# yum -y install pcre-devel zlib-devel
[root@centos02 ~]# useradd -M -s /sbin/nologin nginx
[root@centos02 ~]# tar zxvf /usr/src/nginx-1.6.0.tar.gz -C /usr/src/
[root@centos02 ~]# cd /usr/src/nginx-1.6.0/
[root@centos02 nginx-1.6.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module
[root@centos02 nginx-1.6.0]# make && make install
[root@centos02 ~]# ln -s /usr/local/nginx/sbin/* /usr/local/sbin/
[root@centos02 ~]# cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak
[root@centos02 ~]# vim /usr/local/nginx/conf/nginx.conf
3 user nginx;
4 worker_processes 1;
6 error_log logs/error.log;
12 pid logs/nginx.pid;
16 use epoll;
17 worker_connections 1024;
29 #access_log logs/access.log main;
31 sendfile on;
35 keepalive_timeout 65;
39 server {
40 listen 80;
41 server_name localhost;
44 charset utf-8;
48 location / {
49 root html;
50 index index.html index.htm;
51 }
84 }
[root@centos02 ~]# nginx
[root@centos02 ~]# netstat -anptu | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 4663/nginx: master
[root@centos02 ~]# vim /etc/init.d/nginx
#!/bin/bash
#chkconfig: 35 90 30
#description:nginx server
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case "$1" in
start)
$PROG
;;
stop)
kill -s QUIT $(cat $PIDF)
;;
restart)
$0 stop
$0 start
;;
reload)
kill 0s HUP $(cat $PIDF)
;;
*)
echo "Usage:$0 (start|stop|restart|reload)"
exit 1
esac
exit 0
[root@centos02 ~]# chmod +x /etc/init.d/nginx
[root@centos02 ~]# chkconfig --add nginx
[root@centos02 ~]# chkconfig --level 35 nginx on
[root@centos02 ~]# /etc/init.d/nginx stop
[root@centos02 ~]# /etc/init.d/nginx start
[root@centos02 ~]# /etc/init.d/nginx restart
至此,可以配置客户端配置与服务器同网卡、同网段的IP地址及网关,访问Nginx网站
[root@centos02 ~]# yum -y install bind bind-chroot bind-utils
[root@centos02 ~]# echo "" > /etc/named.conf
[root@centos02 ~]# vim /etc/named.conf
options {
listen-on port 53 { 192.168.100.20; };
directory "/var/named";
}
zone "benet.com" IN {
type master;
file "benet.com.zone";
}
zone "accp.com" IN {
type master;
file "accp.com.zone";
}
[root@centos02 ~]# named-checkconf -z /etc/named.conf
[root@centos02 ~]# vim /var/named/benet.com.zone
$TTL 86400
@ SOA benet.com. root.benet.com(
2019112801
1H
15M
1W
1D
)
@ NS centos02.benet.com.
centos02 A 192.168.100.20
www A 192.168.100.20
[root@centos02 ~]# chmod +x /var/named/benet.com.zone
[root@centos02 ~]# chown named:named /var/named/benet.com.zone
[root@centos02 ~]# named-checkzone benet.com /var/named/benet.com.zone
zone benet.com/IN: loaded serial 2019112801
OK
[root@centos02 ~]# cp /var/named/benet.com.zone /var/named/accp.com.zone
[root@centos02 ~]# vim /var/named/accp.com.zone
$TTL 86400
@ SOA accp.com. root.accp.com(
2019112801
1H
15M
1W
1D
)
@ NS centos02.accp.com.
centos02 A 192.168.100.20
www A 192.168.100.20
[root@centos02 ~]# named-checkzone accp.com /var/named/accp.com.zone
[root@centos02 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens32
DNS1=192.168.100.20
[root@centos02 ~]# systemctl restart network
[root@centos02 ~]# systemctl start named
[root@centos02 ~]# systemctl enable named
[root@centos02 ~]# nslookup www.benet.com
Server: 192.168.100.20
Address: 192.168.100.20#53
Name: www.benet.com
Address: 192.168.100.20
[root@centos02 ~]# nslookup www.accp.com
Server: 192.168.100.20
Address: 192.168.100.20#53
Name: www.accp.com
Address: 192.168.100.20
[root@centos02 ~]# mkdir -p /var/www/benetcom
[root@centos02 ~]# mkdir -p /var/www/accpcom
[root@centos02 ~]# echo "www.benet.com" > /var/www/benetcom/index.html
[root@centos02 ~]# echo "www.accp.com" > /var/www/accpcom/index.html
[root@centos02 ~]# vim /usr/local/nginx/conf/nginx.conf
server {
listen www.benet.com:80;
server_name www.benet.com;
charset utf-8;
access_log logs/www.benet.com.access.log;
error_log logs/www.benet.com.error.log;
location / {
root /var/www/benetcom/;
index index.html;
}
}
server {
listen www.accp.com:80;
server_name www.accp.com;
charset utf-8;
access_log logs/www.accp.com.access.log;
error_log logs/www.accp.com.error.log;
location / {
root /var/www/accpcom/;
index index.html;
}
}
[root@centos02 ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@centos02 ~]# systemctl restart named
[root@centos02 ~]# /etc/init.d/nginx restart
至此客户端添加DNS地址,访问域名即可
MySQL数据库具体配置及概述请访问博文:Centos安装MySQL数据库
[root@centos02 ~]# groupadd mysql
[root@centos02 ~]# useradd -M -s /sbin/nologin -g mysql mysql
[root@centos02 ~]# yum -y install ncurses-devel
[root@centos02 ~]# tar zxvf /usr/src/cmake-2.8.6.tar.gz -C
/usr/src/
[root@centos02 ~]# cd /usr/src/cmake-2.8.6/
[root@centos02 cmake-2.8.6]# ./configure && gmake && gmake install
[root@centos02 ~]# tar zxvf /usr/src/mysql-5.5.22.tar.gz -C
/usr/src/
[root@centos02 mysql-5.5.22]# cmake -
DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
-DWITH_EXTRA_CHARSETS=all -DSYSCONFDIR=/etc
[root@centos02 mysql-5.5.22]# make && make install
[root@centos02 mysql-5.5.22]# cp support-files/my-medium.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y
[root@centos02 mysql-5.5.22]# cp support-files/mysql.server
/etc/init.d/mysqld
[root@centos02 ~]# chmod +x /etc/init.d/mysqld
[root@centos02 ~]# chkconfig --add mysqld
[root@centos02 ~]# chkconfig --level 35 mysqld on
[root@centos02 ~]# vim /etc/profile
PATH=$PATH:/usr/local/mysql/bin/
[root@centos02 ~]# source /etc/profile
[root@centos02 ~]# /usr/local/mysql/scripts/mysql_install_db
--user=mysql --basedir=/usr/local/mysql
--datadir=/usr/local/mysql/data
[root@centos02 ~]# systemctl start mysqld
[root@centos02 ~]# systemctl enable mysqld
[root@centos02 ~]# mysqladmin -u root password
New password:
Confirm new password:
[root@centos02 ~]# mysql -uroot -ppwd@123
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
[root@centos02 ~]# yum -y install gd libxml2-devel libjpeg-devel libpng-devel
[root@centos02 ~]# tar zxvf /usr/src/php-5.3.28.tar.gz -C /usr/src/
[root@centos02 ~]# cd /usr/src/php-5.3.28/
[root@centos02 php-5.3.28]# ./configure --prefix=/usr/local/php
--with-config-file-path=/usr/local/php --with-mysql=/usr/local/mysql/
--with-mysqli=/usr/local/mysql/bin/mysql_config --with-gd
--with-zlib --with-jpeg-dir=/usr/lib --enable-mbstring
--enable-fpm
[root@centos02 php-5.3.28]# make && make install
[root@centos02 php-5.3.28]# ls -ld /usr/local/php/
drwxr-xr-x 10 root root 101 11月 28 20:04 /usr/local/php/
[root@centos02 php-5.3.28]# cp php.ini-production
/usr/local/php/php.ini
[root@centos02 ~]# ln -s /usr/local/php/sbin/* /usr/local/sbin/
[root@centos02 ~]# ln -s /usr/local/php/bin/* /usr/local/bin/
[root@centos02 ~]# tar zxvf /usr/src/zendguardloader-php-5.3-linux-glibc23-i386.tar.gz
-C /usr/src/
[root@centos02 ~]# mv /usr/src/ZendGuardLoader-php-5.3-linux-glibc23-i386
/php-5.3.x/ZendGuardLoader.so /usr/local/php/lib/php/
[root@centos02 ~]# vim /usr/local/php/php.ini
zend_extension=/usr/local/php/lib/php/ZendGuardLoader.so
zend_loader.enable=1
[root@centos02 ~]# cp /usr/local/php/etc/php-fpm.conf.default
/usr/local/php/etc/php-fpm.conf
[root@centos02 ~]# vim /usr/local/php/etc/php-fpm.conf
26 pid = run/php-fpm.pid
141 user = nginx
142 group = nginx
[root@centos02 ~]# /usr/local/sbin/php-fpm
[root@centos02 ~]# netstat -anptu | grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 127332/php-fpm: mas
[root@centos02 ~]# vim /usr/local/nginx/conf/nginx.conf
location ~ \.php$ {
root /var/www/benetcom;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
[root@centos02 ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@centos02 ~]# vim /var/www/benetcom/index.php
[root@centos02 ~]# /etc/init.d/nginx restart
至此,客户端可以访问PHP测试页
[root@centos02 ~]# vim /usr/local/nginx/conf/nginx.conf
104 server {
105 listen www.accp.com:80;
106 server_name www.accp.com;
107 charset utf-8;
108 access_log logs/www.accp.com.access.log;
109 error_log logs/www.accp.com.error.log;
110 location / {
111 root /var/www/accpcom/;
112 index index.html index.php;
113 }
114 location ~ \.php$ {
115 root /var/www/accpcom;
116 fastcgi_pass 127.0.0.1:9000;
117 fastcgi_index index.php;
118 include fastcgi.conf;
119 }
[root@centos02 ~]# unzip Discuz_X3.2_SC_UTF8.zip
[root@centos02 ~]# ls
anaconda-ks.cfg Discuz_X3.2_SC_UTF8.zip readme utility
Discuz_X3.2_SC_UTF8 initial-setup-ks.cfg upload
[root@centos02 ~]# mv ./upload/* /var/www/accpcom/
[root@centos02 ~]# chmod -R +x /var/www/accpcom/
[root@centos02 ~]# chown -R nginx:nginx /var/www/accpcom/
[root@centos02 ~]# mysql -uroot -ppwd@123
mysql> create database bbs;
mysql> grant all on bbs.* to bbs@localhost identified by 'pwd@123';
[root@centos02 ~]# /etc/init.d/nginx restart
1)客户端浏览器输入www.accp.com/install访问,单击我同意开始安装
2)检查安装环境
3)选择全新安装,单击下一步
4)设置数据库的用户及密码
5)等待安装完成即可
6)删除accp.com网站的默认首页[root@centos02 ~]# rm -rf /var/www/accpcom/index.html
7)客户端访问
8)登录后台管理网站
至此论坛就已经部署完成。
—————— 本文至此结束,感谢阅读 ——————