LNMP架构的源码编译以及论坛部署
一、编译安装Nginx 服务
1、编译安装Nginx 服务的操作步骤
systemctl stop firewalld systemctl disable firewalld setenforce 0
1.1 安装依赖包
yum -y install pcre-devel zlib-devel gcc gcc-c++ make
1.2 创建运行用户
useradd -M -s /sbin/nologin nginx
1.3 编译安装
cd /opt tar zxvf nginx-1.12.0.tar.gz -C /opt/ cd nginx-1.12.0/ ./configure \ --prefix=/usr/local/nginx \ --user=nginx \ --group=nginx \ --with-http_stub_status_module make && make install
1.4 优化路径
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
1.5 添加 Nginx 系统服务
vim /lib/systemd/system/nginx.service [Unit] Description=nginx After=network.target [Service] Type=forking PIDFile=/usr/local/nginx/logs/nginx.pid ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target chmod 754 /lib/systemd/system/nginx.service systemctl start nginx.service systemctl enable nginx.service
2、实例操作:编译安装Nginx 服务
2.1 关闭防火墙,并把安装包放到/opt目录下,并安装依赖包
[root@192 ~]# systemctl stop firewalld [root@192 ~]# setenforce 0 setenforce: SELinux is disabled [root@192 ~]# systemctl disable firewalld [root@192 ~]# cd /opt [root@192 opt]# rz -E rz waiting to receive. [root@192 opt]# ls nginx-1.12.2.tar.gz rh [root@192 opt]# yum -y install pcre-devel zlib-devel gcc gcc-c++ make
2.2 创建运行用户,配置相关模块并编译安装
[root@192 opt]# useradd -M -s /sbin/nologin nginx [root@192 opt]# tar zxf nginx-1.12.2.tar.gz [root@192 opt]# ls nginx-1.12.2 nginx-1.12.2.tar.gz rh [root@192 opt]# cd nginx-1.12.2/ [root@192 nginx-1.12.2]# ls auto CHANGES CHANGES.ru conf configure contrib html LICENSE man README src [root@192 nginx-1.12.2]# ./configure \ > --prefix=/usr/local/nginx \ > --user=nginx \ > --group=nginx \ > --with-http_stub_status_module
2.3 优化路径
[root@192 nginx-1.12.2]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ [root@192 nginx-1.12.2]# ll /usr/local/nginx/sbin/nginx -rwxr-xr-x 1 root root 3693272 8月 11 18:31 /usr/local/nginx/sbin/nginx [root@192 nginx-1.12.2]# ll /usr/local/sbin/nginx lrwxrwxrwx 1 root root 27 8月 11 18:33 /usr/local/sbin/nginx -> /usr/local/nginx/sbin/nginx
2.4 添加nginx服务
[root@192 system]# vim /lib/systemd/system/nginx.service [Unit] Description=nginx After=network.target [Service] Type=forking PIDFile=/usr/local/nginx/logs/nginx.pid ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target
2.5 赋予权限并开启服务,访问测试
[root@192 system]# chmod 754 /lib/systemd/system/nginx.service [root@192 system]# ll /lib/systemd/system/nginx.service -rwxr-xr-- 1 root root 274 8月 11 18:55 /lib/systemd/system/nginx.service [root@192 system]# netstat -natp | grep :80 [root@192 system]# systemctl start nginx.service [root@192 system]# netstat -natp | grep :80 tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 6953/nginx: master
二、编译安装MySQL服务
1、编译安装MySQL服务的操作步骤
1.1 安装Mysql环境依赖包
yum -y install \ ncurses \ ncurses-devel \ bison \ cmake
1.2 创建运行用户
useradd -M -s /sbin/nologin mysql
1.3 编译安装
cd /opt tar zxvf mysql-boost-5.7.20.tar.gz cd /opt/mysql-5.7.20/ cmake \ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \ -DSYSCONFDIR=/etc \ -DSYSTEMD_PID_DIR=/usr/local/mysql \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DWITH_EXTRA_CHARSETS=all \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_ARCHIVE_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \ -DMYSQL_DATADIR=/usr/local/mysql/data \ -DWITH_BOOST=boost \ -DWITH_SYSTEMD=1 make && make install
1.4 修改mysql 配置文件
vim /etc/my.cnf [client] port = 3306 socket=/usr/local/mysql/mysql.sock [mysqld] user = mysql basedir=/usr/local/mysql datadir=/usr/local/mysql/data port = 3306 character-set-server=utf8 pid-file = /usr/local/mysql/mysqld.pid socket=/usr/local/mysql/mysql.sock bind-address = 0.0.0.0 skip-name-resolve max_connections=2048 default-storage-engine=INNODB max_allowed_packet=16M server-id = 1 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
1.5 更改mysql安装目录和配置文件的属主属组
chown -R mysql:mysql /usr/local/mysql/ chown mysql:mysql /etc/my.cnf
1.6 设置路径环境变量
echo 'export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile source /etc/profile
1.7 初始化数据库
cd /usr/local/mysql/bin/ ./mysqld \ --initialize-insecure \ --user=mysql \ --basedir=/usr/local/mysql \ --datadir=/usr/local/mysql/data
1.8 添加mysqld系统服务
cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/ systemctl daemon-reload systemctl start mysqld.service systemctl enable mysqld
1.9 修改mysql 的登录密码
mysqladmin -u root -p password "abc123"
1.10 授权远程登录
mysql -u root -p grant all privileges on *.* to 'root'@'%' identified by 'abc123'; #授予root用户可以在所有终端远程登录,使用的密码是abc123,并对所有数据库和所有表有操作权限 show databases; #查看当前已有的数据库
2、实例操作:编译安装MySQL服务
2.1 放入软件包并安装Mysql环境依赖包
[root@192 system]# cd /opt/ [root@192 opt]# ls nginx-1.12.2 nginx-1.12.2.tar.gz rh [root@192 opt]# rz -E rz waiting to receive. [root@192 opt]# ls mysql-boost-5.7.20.tar.gz nginx-1.12.2.tar.gz nginx-1.12.2 rh [root@192 opt]# yum -y install gcc gcc-c++ ncurses ncurses-devel bison cmake
2.2 创建运行用户并配置相关模块,最后编译安装
[root@192 opt]# useradd -M -s /sbin/nologin mysql [root@192 opt]# ls mysql-boost-5.7.20.tar.gz nginx-1.12.2 nginx-1.12.2.tar.gz rh [root@192 opt]# tar zxf mysql-boost-5.7.20.tar.gz [root@192 opt]# ls mysql-5.7.20 mysql-boost-5.7.20.tar.gz nginx-1.12.2 nginx-1.12.2.tar.gz rh [root@192 opt]# cd mysql-5.7.20/ [root@192 mysql-5.7.20]# ls boost cmd-line-utils Docs libbinlogevents libservices packaging scripts support-files win BUILD config.h.cmake Doxyfile-perfschema libbinlogstandalone man plugin sql testclients zlib client configure.cmake extra libevent mysql-test rapid sql-common unittest cmake COPYING include libmysql mysys README storage VERSION CMakeLists.txt dbug INSTALL libmysqld mysys_ssl regex strings vio [root@192 mysql-5.7.20]# cmake \ > -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ > -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \ > -DSYSCONFDIR=/etc \ > -DSYSTEMD_PID_DIR=/usr/local/mysql \ > -DDEFAULT_CHARSET=utf8 \ > -DDEFAULT_COLLATION=utf8_general_ci \ > -DWITH_EXTRA_CHARSETS=all \ > -DWITH_INNOBASE_STORAGE_ENGINE=1 \ > -DWITH_ARCHIVE_STORAGE_ENGINE=1 \ > -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ > -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \ > -DMYSQL_DATADIR=/usr/local/mysql/data \ > -DWITH_BOOST=boost \ > -DWITH_SYSTEMD=1
[root@192 mysql-5.7.20]# make -j2 && make install
2.3 修改mysql 配置文件
[root@192 mysql-5.7.20]# vim /etc/my.cnf [client] port = 3306 socket=/usr/local/mysql/mysql.sock [mysqld] user = mysql basedir=/usr/local/mysql datadir=/usr/local/mysql/data port = 3306 character-set-server=utf8 pid-file = /usr/local/mysql/mysqld.pid socket=/usr/local/mysql/mysql.sock bind-address = 0.0.0.0 skip-name-resolve max_connections=2048 default-storage-engine=INNODB max_allowed_packet=16M server-id = 1 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
2.4 更改mysql安装目录和配置文件的属主属组
[root@192 mysql-5.7.20]# chown -R mysql:mysql /usr/local/mysql [root@192 mysql-5.7.20]# chown mysql:mysql /etc/my.cnf [root@192 mysql-5.7.20]# ll /etc/my.cnf -rw-r--r-- 1 mysql mysql 554 8月 11 20:03 /etc/my.cnf [root@192 mysql-5.7.20]# ll /usr/local/mysql/ 总用量 64 drwxr-xr-x 2 mysql mysql 4096 8月 11 19:59 bin -rw-r--r-- 1 mysql mysql 17987 9月 13 2017 COPYING -rw-r--r-- 1 mysql mysql 17987 9月 13 2017 COPYING-test drwxr-xr-x 2 mysql mysql 55 8月 11 19:59 docs drwxr-xr-x 3 mysql mysql 4096 8月 11 19:59 include drwxr-xr-x 4 mysql mysql 191 8月 11 19:59 lib drwxr-xr-x 4 mysql mysql 30 8月 11 19:59 man drwxr-xr-x 10 mysql mysql 4096 8月 11 19:59 mysql-test -rw-r--r-- 1 mysql mysql 2478 9月 13 2017 README -rw-r--r-- 1 mysql mysql 2478 9月 13 2017 README-test drwxr-xr-x 28 mysql mysql 4096 8月 11 19:59 share drwxr-xr-x 2 mysql mysql 90 8月 11 19:59 support-files drwxr-xr-x 3 mysql mysql 17 8月 11 19:59 usr
2.5 设置路径环境变量
[root@192 mysql-5.7.20]# echo 'export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile [root@192 mysql-5.7.20]# source /etc/profile
2.6 初始化数据库
[root@192 mysql-5.7.20]# cd /usr/local/mysql/bin/ [root@192 bin]# ./mysqld \ > --initialize-insecure \ > --user=mysql \ > --basedir=/usr/local/mysql \ > --datadir=/usr/local/mysql/data
2.7 添加mysqld系统服务
[root@192 system]# cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/ [root@192 system]# ll /usr/lib/systemd/system/mysqld.service -rw-r--r-- 1 root root 1639 8月 11 20:30 /usr/lib/systemd/system/mysqld.service [root@192 system]# systemctl daemon-reload [root@192 system]# systemctl start mysqld.service [root@192 system]# systemctl enable mysqld.service Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /usr/lib/systemd/system/mysqld.service. [root@192 system]# netstat -natp | grep mysqld tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 27761/mysqld
2.8 修改mysql 的登录密码并授权远程登录
[root@192 system]# mysqladmin -u root -p password "abc123" Enter password: mysqladmin: [Warning] Using a password on the command line interface can be insecure. Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety. [root@192 system]# mysql -u root -pabc123 mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.20 Source distribution Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> grant all privileges on *.* to 'root'@'%' identified by 'abc123'; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec) mysql> quit Bye
三、编译安装PHP解析环境
1、编译安装PHP解析环境的操作步骤
1.1 安装环境依赖包
yum -y install gd \ libjpeg libjpeg-devel \ libpng libpng-devel \ freetype freetype-devel \ libxml2 libxml2-devel \ zlib zlib-devel \ curl curl-devel \ openssl openssl-devel
1.2 编译安装
cd /opt tar jxvf php-7.1.10.tar.bz2 cd php-7.1.10 ./configure \ --prefix=/usr/local/php \ --with-mysql-sock=/usr/local/mysql/mysql.sock \ --with-mysqli \ --with-zlib \ --with-curl \ --with-gd \ --with-jpeg-dir \ --with-png-dir \ --with-freetype-dir \ --with-openssl \ --enable-fpm \ --enable-mbstring \ --enable-xml \ --enable-session \ --enable-ftp \ --enable-pdo \ --enable-tokenizer \ --enable-zip make && make install
1.3 路径优化
ln -s /usr/local/php/bin/* /usr/local/bin/ ln -s /usr/local/php/sbin/* /usr/local/sbin/
1.4 调整PHP配置文件
php有三个配置文件:
- php.ini 主配置文件
- php-fpm.conf 进程服务配置文件
- www.conf 扩展配置文件
调整主配置文件:
cp /opt/php-7.1.10/php.ini-development /usr/local/php/lib/php.ini vim /usr/local/php/lib/php.ini --1170行--修改 mysqli.default_socket = /usr/local/mysql/mysql.sock --939行--取消注释,修改 date.timezone = Asia/Shanghai php -m #验证安装的模块
调整进程服务配置文件:
cd /usr/local/php/etc/ cp php-fpm.conf.default php-fpm.conf vim php-fpm.conf --17行--去掉";"注释 pid = run/php-fpm.pid
调整扩展配置文件:
cd /usr/local/php/etc/php-fpm.d/ cp www.conf.default www.conf
1.5 启动php-fpm
/usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini netstat -anpt | grep 9000
PHP-FPM(FastCGI Process Manager:FastCGI 进程管理器)是一个 PHPFastCGI 管理器, 由于Nginx服务器不能处理动态页面,需要由 Nginx 把动态请求交给 php-fpm 进程进行解析
1.6 配置 Nginx 支持 PHP 解析
vim /usr/local/nginx/conf/nginx.conf --65行--取消注释,修改 location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name; #将 /scripts 修改为nginx的工作目录 include fastcgi_params; } systemctl restart nginx.service
1.7 验证PHP 测试页
vim /usr/local/nginx/html/index.php <?php phpinfo(); ?>
浏览器访问 http://192.168.229.90/index.php
1.8 验证数据库工作是否正常
mysql -u root -p CREATE DATABASE bbs; GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY 'admin123'; GRANT all ON bbs.* TO 'bbsuser'@'localhost' IDENTIFIED BY 'admin123'; flush privileges; vim /usr/local/nginx/html/index.php #替换原来的测试页内容 <?php $link=mysqli_connect('192.168.80.10','bbsuser','admin123'); if($link) echo "<h1>Success!!</h1>"; else echo "Fail!!"; ?>
浏览器访问
http://192.168.229.90/index.php
2、实例操作:编译安装PHP解析环境
2.1 放入安装包并安装环境依赖包
[root@192 system]# cd /opt [root@192 opt]# rz -E rz waiting to receive. [root@192 opt]# rz -E rz waiting to receive. [root@192 opt]# ls Discuz_X3.4_SC_UTF8.zip mysql-5.7.20 mysql-boost-5.7.20.tar.gz nginx-1.12.2 nginx-1.12.2.tar.gz php-7.1.10.tar.bz2 rh [root@192 opt]# yum -y install gd \ > libjpeg libjpeg-devel \ > libpng libpng-devel \ > freetype freetype-devel \ > libxml2 libxml2-devel \ > zlib zlib-devel \ > curl curl-devel \ > openssl openssl-devel
2.2 配置相关模块并编译安装
[root@192 opt]# ls Discuz_X3.4_SC_UTF8.zip mysql-5.7.20 mysql-boost-5.7.20.tar.gz nginx-1.12.2 nginx-1.12.2.tar.gz php-7.1.10.tar.bz2 rh [root@192 opt]# tar jxf php-7.1.10.tar.bz2 [root@192 opt]# ls Discuz_X3.4_SC_UTF8.zip mysql-5.7.20 mysql-boost-5.7.20.tar.gz nginx-1.12.2 nginx-1.12.2.tar.gz php-7.1.10 php-7.1.10.tar.bz2 rh [root@192 opt]# cd php-7.1.10/ [root@192 php-7.1.10]# ./configure \ > --prefix=/usr/local/php \ > --with-mysql-sock=/usr/local/mysql/mysql.sock \ > --with-mysqli \ > --with-zlib \ > --with-curl \ > --with-gd \ > --with-jpeg-dir \ > --with-png-dir \ > --with-freetype-dir \ > --with-openssl \ > --enable-fpm \ > --enable-mbstring \ > --enable-xml \ > --enable-session \ > --enable-ftp \ > --enable-pdo \ > --enable-tokenizer \ > --enable-zip
[root@192 php-7.1.10]# make -j2 && make install
2.3 路径优化
[root@192 php-7.1.10]# ln -s /usr/local/php/bin/* /usr/local/bin/ [root@192 php-7.1.10]# ll /usr/local/php/bin/ 总用量 112576 -rwxr-xr-x 1 root root 837 8月 11 21:01 pear -rwxr-xr-x 1 root root 858 8月 11 21:01 peardev -rwxr-xr-x 1 root root 774 8月 11 21:01 pecl lrwxrwxrwx 1 root root 9 8月 11 21:01 phar -> phar.phar -rwxr-xr-x 1 root root 14833 8月 11 21:01 phar.phar -rwxr-xr-x 1 root root 38157072 8月 11 21:01 php -rwxr-xr-x 1 root root 38001768 8月 11 21:01 php-cgi -rwxr-xr-x 1 root root 2682 8月 11 21:01 php-config -rwxr-xr-x 1 root root 39075352 8月 11 21:01 phpdbg -rwxr-xr-x 1 root root 4563 8月 11 21:01 phpize [root@192 php-7.1.10]# ll /usr/local/bin/ 总用量 0 lrwxrwxrwx 1 root root 23 8月 11 21:03 pear -> /usr/local/php/bin/pear lrwxrwxrwx 1 root root 26 8月 11 21:03 peardev -> /usr/local/php/bin/peardev lrwxrwxrwx 1 root root 23 8月 11 21:03 pecl -> /usr/local/php/bin/pecl lrwxrwxrwx 1 root root 23 8月 11 21:03 phar -> /usr/local/php/bin/phar lrwxrwxrwx 1 root root 28 8月 11 21:03 phar.phar -> /usr/local/php/bin/phar.phar lrwxrwxrwx 1 root root 22 8月 11 21:03 php -> /usr/local/php/bin/php lrwxrwxrwx 1 root root 26 8月 11 21:03 php-cgi -> /usr/local/php/bin/php-cgi lrwxrwxrwx 1 root root 29 8月 11 21:03 php-config -> /usr/local/php/bin/php-config lrwxrwxrwx 1 root root 25 8月 11 21:03 phpdbg -> /usr/local/php/bin/phpdbg lrwxrwxrwx 1 root root 25 8月 11 21:03 phpize -> /usr/local/php/bin/phpize
2.4 调整PHP三个配置文件
2.4.1 调整主配置文件:
[root@192 php-7.1.10]# cp /opt/php-7.1.10/php.ini-development /usr/local/php/lib/php.ini [root@192 php-7.1.10]# ll /usr/local/php/lib/php.ini -rw-r--r-- 1 root root 71064 8月 11 21:07 /usr/local/php/lib/php.ini [root@192 php-7.1.10]# vim /usr/local/php/lib/php.ini
2.4.2 调整进程服务配置文件:
[root@192 php-7.1.10]# cd /usr/local/php/etc/ [root@192 etc]# ls pear.conf php-fpm.conf.default php-fpm.d [root@192 etc]# cp php-fpm.conf.default php-fpm.conf [root@192 etc]# ls pear.conf php-fpm.conf php-fpm.conf.default php-fpm.d [root@192 etc]# vim php-fpm.conf
2.4.3 调整扩展配置文件:
[root@192 etc]# cd /usr/local/php/etc/php-fpm.d/ [root@192 php-fpm.d]# ls www.conf.default [root@192 php-fpm.d]# cp www.conf.default www.conf [root@192 php-fpm.d]# ls www.conf www.conf.default
2.4 启动php-fpm
[root@192 php-fpm.d]# /usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini [root@192 php-fpm.d]# netstat -natp | grep :9000 tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 33687/php-fpm: mast [root@192 php-fpm.d]# cd /opt/php-7.1.10/sapi/fpm/ [root@192 fpm]# ls config.m4 init.d.php-fpm Makefile.frag php-fpm.8.in php-fpm.service status.html.in www.conf.in CREDITS init.d.php-fpm.in php-fpm php-fpm.conf php-fpm.service.in tests fpm LICENSE php-fpm.8 php-fpm.conf.in status.html www.conf [root@192 fpm]# cp php-fpm.service /usr/lib/systemd/system/ [root@192 fpm]# ll /usr/lib/systemd/system/php-fpm.service -rw-r--r-- 1 root root 512 8月 11 21:28 /usr/lib/systemd/system/php-fpm.service [root@192 fpm]# systemctl restart php-fpm.service
2.5 配置 Nginx 支持 PHP 解析并重启服务
2.6 并修改index.php的网页内容
[root@192 fpm]# vim /usr/local/nginx/html/index.php <?php phpinfo(); ?>
2.7 浏览器访问测试
2.8 验证数据库工作是否正常
2.8.1 创建数据库并进行授权
[root@192 fpm]# mysql -u root -pabc123 mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 Server version: 5.7.20 Source distribution Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> CREATE DATABASE bbs; Query OK, 1 row affected (0.02 sec) mysql> GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY 'abc123'; Query OK, 0 rows affected, 1 warning (0.02 sec) mysql> GRANT all ON bbs.* TO 'bbsuser'@'localhost' IDENTIFIED BY 'abc123'; Query OK, 0 rows affected, 2 warnings (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.01 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | bbs | | mysql | | performance_schema | | sys | +--------------------+ 5 rows in set (0.00 sec) mysql> quit Bye
2.8.2 替换原来的测试页内容
[root@192 fpm]# vim /usr/local/nginx/html/index.php <?php $link=mysqli_connect('192.168.229.90','bbsuser','abc123'); if($link) echo " <h1>成功连接!</h1>"; else echo "<h1>连接失败!</h1>"; ?>
2.8.3 在浏览器进行访问测试
四、部署 Discuz!社区论坛
1、部署 Discuz!社区论坛 的操作步骤
因为在验证数据库连接的时候已经创建了数据库bbs,这里省略
1.1 解压论坛压缩包
cd /opt unzip Discuz_X3.4_SC_UTF8.zip -d /opt/dis cd /opt/dis/dir_SC_UTF8/ cp -r upload/ /usr/local/nginx/html/bbs/
1.2 更改论坛目录的属主
cd /usr/local/nginx/html/bbs/ chown -R nobody ./config/ chown -R nobody ./data/ chown -R nobody ./uc_client/ chown -R nobody ./uc_server/ 或者 chmod -R 777 ./config/ chmod -R 777 ./data/ chmod -R 777 ./uc_client/ chmod -R 777 ./uc_server/
论坛页面访问
http://192.168.229.90/bbs/install/index.php
-------------------------------------------------------------------------------------------------------------------------------------------------------------
数据库服务器:localhost ###本地架设就用localhost,如何不是在在本机上就要填写IP地址和端口号
数据库名字:bbs
数据库用户名:bbsuser
数据库密码:abc123
管理员账号:admin
管理员密码:abc123
------------------------------------------------------------------------------------------------------------------------------------------------------------------
论坛后台管理员页面
http://192.168.229.90/bbs/admin.php
2、实例操作:部署 Discuz!社区论坛
2.1 解压论坛压缩包
[root@192 opt]# unzip Discuz_X3.4_SC_UTF8.zip -d /opt/dis/ [root@192 opt]# cd /opt/dis/ [root@192 dis]# ls dir_SC_UTF8 说明.htm [root@192 dis]# cd dir_SC_UTF8/ [root@192 dir_SC_UTF8]# ls readme upload utility [root@192 dir_SC_UTF8]# cp -r upload/ /usr/local/nginx/html/bbs/
2.2 更改论坛目录的属主
[root@192 bbs]# chown -R nobody ./config/ [root@192 bbs]# ls admin.php archiver crossdomain.xml forum.php index.php member.php portal.php source uc_client api config data group.php install misc.php robots.txt static uc_server api.php connect.php favicon.ico home.php m plugin.php search.php template [root@192 bbs]# chown -R nobody ./config/ [root@192 bbs]# chown -R nobody ./data/ [root@192 bbs]# chown -R nobody ./uc_client/ [root@192 bbs]# chown -R nobody ./uc_server/ [root@192 bbs]# ll 总用量 68 -rw-r--r-- 1 root root 2748 8月 12 09:08 admin.php drwxr-xr-x 10 root root 149 8月 12 09:08 api -rw-r--r-- 1 root root 727 8月 12 09:08 api.php drwxr-xr-x 2 root root 23 8月 12 09:08 archiver drwxr-xr-x 2 nobody root 90 8月 12 09:20 config -rw-r--r-- 1 root root 1017 8月 12 09:08 connect.php -rw-r--r-- 1 root root 106 8月 12 09:08 crossdomain.xml drwxr-xr-x 12 nobody root 202 8月 12 09:08 data -rw-r--r-- 1 root root 5558 8月 12 09:08 favicon.ico -rw-r--r-- 1 root root 2245 8月 12 09:08 forum.php -rw-r--r-- 1 root root 821 8月 12 09:08 group.php -rw-r--r-- 1 root root 1280 8月 12 09:08 home.php -rw-r--r-- 1 root root 5885 8月 12 09:08 index.php drwxr-xr-x 5 root root 64 8月 12 09:08 install drwxr-xr-x 2 root root 23 8月 12 09:08 m -rw-r--r-- 1 root root 1025 8月 12 09:08 member.php -rw-r--r-- 1 root root 2435 8月 12 09:08 misc.php -rw-r--r-- 1 root root 1788 8月 12 09:08 plugin.php -rw-r--r-- 1 root root 977 8月 12 09:08 portal.php -rw-r--r-- 1 root root 582 8月 12 09:08 robots.txt -rw-r--r-- 1 root root 1155 8月 12 09:08 search.php drwxr-xr-x 10 root root 168 8月 12 09:08 source drwxr-xr-x 7 root root 86 8月 12 09:08 static drwxr-xr-x 3 root root 38 8月 12 09:08 template drwxr-xr-x 7 nobody root 106 8月 12 09:08 uc_client drwxr-xr-x 14 nobody root 256 8月 12 09:08 uc_server
如何查看论坛目录的属主
2.3 论坛页面访问
http://192.168.229.90/bbs/install/index.php
排错:Discuz!安装成功,但是访问进去
思路:
1、检查数据库是否有问题,之前已经验证了连接没有问题
2、页面中出现nginx服务拒绝此页面显示,故检查nginx的配置文件
五、fpm 参数优化
vim /usr/local/php/etc/php-fpm.conf pid = run/php-fpm.pid vim /usr/local/php/etc/php-fpm.d/www.conf --96行-- pm = dynamic #fpm进程启动方式,动态的 --107行-- pm.max_children=20 #fpm进程启动的最大进程数 --112行-- pm.start_servers = 5 #动态方式下启动时默认开启的进程数,在最小和最大之间 --117行-- pm.min_spare_servers = 2 #动态方式下最小空闲进程数 --122行-- pm.max_spare_servers = 8 #动态方式下最大空闲进程数 kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid` #重启php-fpm,为了在不断开服务的情况下进行重载配置文件 netstat -anpt | grep 9000 ps -elf | grep php-fpm