当前位置 : 主页 > 操作系统 > centos >

实验:源码编译构建LANP+bbs论坛+初始化优化fpm

来源:互联网 收集:自由互联 发布时间:2022-06-20
环境:```html/xmlip:192.168.206.5 LANP服务机win7客机一个 使用192.168.206.0/24 网段的DHCP服务需求:nginx、musql、 php的安装包centos7 完成防火墙关闭和本地yum仓库配置opt目录中存放压缩包文件LA

环境:```html/xmlip:192.168.206.5 LANP服务机win7客机一个 使用192.168.206.0/24 网段的DHCP服务需求:nginx、musql、 php的安装包centos7 完成防火墙关闭和本地yum仓库配置opt目录中存放压缩包文件LANP:建议4核心,8G内存以上

### 首先安装nginx (nginx-1.12.2.tar.gz 压缩包) 首先是安装nginx的相关依赖包 ```html/xml yum -y install pcre-devel zlib-devel gcc gcc-c++ make

1、首先安装nginx的依赖包.png然后创建nginx的相关程序用户(没有家目录和无法登陆)```html/xmluseradd -M -s /sbin/nologin nginx

![2、创建nginx的依赖用户.png](https://s2.51cto.com/images/20220110/1641799765656680.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) 我们去opt目录,使用winscp把nginx的压缩包传给服务器的opt,最后解压 ```html/xml tar zxvf nginx-1.12.2.tar.gz -C /opt/

3、解压nginx的包.png

进入nginx安装包内部,执行编译安装```html/xmlcd nginx-1.12.2/./configure \--prefix=/usr/local/nginx \--user=nginx \--group=nginx \--with-http_stub_status_module

![3.1进入安装包内.png](https://s2.51cto.com/images/20220110/1641799900351175.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) ![3.2执行软件配置.png](https://s2.51cto.com/images/20220110/1641799904292832.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) 完成后执行编译并安装 ```html/xml make && make install make #执行编译安装 选项:make -j 8 #执行后台8核心编译(数字取决你的设备配置)

3.3执行编译安装.png

完成编译安装后我们制作软连接(优化路径)```html/xmlln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/

![4、制作软连接(做优化路径).png](https://s2.51cto.com/images/20220110/1641800008361645.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) 接着我们呢来添加nginx的系统配置 ```html/xml 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

5.1 添加nginx的系统配置(内容).png

5 添加nginx的系统配置(内容).png

完成保存退出,赋权后,设置开启启动并启动nginx```html/xmlchmod 754 /lib/systemd/system/nginx.servicesystemctl start nginx.servicesystemctl enable nginx.service

![6、设置开机启动nginx.png](https://s2.51cto.com/images/20220110/1641800169931138.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) ### 下面安装Mysql (mysql-boost-5.7.20.tar.gz 压缩包) 首先是准备yum安装环境需求包 ```html/xml yum -y install \ ncurses \ ncurses-devel \ bison \ cmake

7、开始安装mysql的系统依赖包.png

下面创建mysql的程序用户```html/xmluseradd -M -s /sbin/nologin mysql

![8创建mysql的依赖用户.png](https://s2.51cto.com/images/20220110/1641800272114492.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) 下面用winscp传mysql的依赖集合包boost,然后去opt目录解压mysql的依赖集合包boost ```html/xml tar zxvf mysql-boost-5.7.20.tar.gz

9,下面解压mysql的依赖集合包boost.png进去mysql的解压目录里,执行软件的配置安装```html/xmlcd /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

![10、进入软件目录,我们配置软件.png](https://s2.51cto.com/images/20220110/1641800458590365.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) 完成后我使用8核心编译安装 ![11、执行8核心编译并安装.png](https://s2.51cto.com/images/20220110/1641800499600819.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) 修改mysql 配置文件 ```html/xml 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

12、修改mysql配置文件.png12、修改mysql配置文件 2.png

更改mysql安装目录和配置文件的属主属组```html/xmlchown -R mysql:mysql /usr/local/mysql/chown mysql:mysql /etc/my.cnf

![13、更改mysql的属主和属组.png](https://s2.51cto.com/images/20220110/1641800762501956.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) 设置路径环境变量,并使用source立即生效 ```html/xml echo "export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib">> /etc/profile source /etc/profile

14、设置路径环境变量并立即生效.png

下面是初始化数据库```html/xmlcd /usr/local/mysql/bin/

./mysqld \--initialize-insecure \--user=mysql \--basedir=/usr/local/mysql \--datadir=/usr/local/mysql/data

![15、初始化数据库.png](https://s2.51cto.com/images/20220110/1641800987295098.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) 添加mysql系统服务 ```html/xml cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/ systemctl daemon-reload systemctl start mysqld.service systemctl enable mysqld

16、添加mysqld系统服务.png

修改mysql 的登录密码 ```html/xmlmysqladmin -u root -p password "abc123" #mysql管理员密码改成abc123mysql -u root -p #授权远程等六

![17、更改root密码abc123 2验证.png](https://s2.51cto.com/images/20220110/1641801492304961.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) ![17、更改root密码abc123.png](https://s2.51cto.com/images/20220110/1641801499544616.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) ### 安装PHP (php-7.1.10.tar.bz2 压缩包) 安装环境依赖包 ```html/xml 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

18、先安装PHP的环境依赖包.png

用winscp将压缩包传到opt,解压后进入压缩包,执行软件的编译安装```html/xmlcd /opttar jxvf php-7.1.10.tar.bz2cd 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

![19、解压PHP压缩包.png](https://s2.51cto.com/images/20220110/1641801964192270.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) ![20、进去安装包中,并进行软件配置.png](https://s2.51cto.com/images/20220110/1641801967970986.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) 完成软件配置后,执行编译安装(8核心) ![21 8核心编译并安装.png](https://s2.51cto.com/images/20220110/1641802021424226.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) 制作软连接-路径优化 ```html/xml ln -s /usr/local/php/bin/* /usr/local/bin/ ln -s /usr/local/php/sbin/* /usr/local/sbin/

22 制作软连接(路径优化).png

下面调整PHP配置文件

```html/xmlphp有三个配置文件: php.ini 主配置文件 php-fpm.conf 进程服务配置文件 www.conf 扩展配置文件

首先调整主配置文件 ```html/xml cp /opt/php-7.1.10/php.ini-development /usr/local/php/lib/php.ini vim /usr/local/php/lib/php.ini

939行23 调整主配置文件  939行更改.png1170行23 调整主配置文件 1170行修改.png

下面是调整进程服务配置文件```html/xmlcd /usr/local/php/etc/cp php-fpm.conf.default php-fpm.confvim php-fpm.conf

17行 ![24 调整配置文件 去掉注释.png](https://s2.51cto.com/images/20220110/1641802226618173.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) 最后调整扩展配置文件: ```html/xml cd /usr/local/php/etc/php-fpm.d/ cp www.conf.default www.conf

25 调整扩展配置文件.png

启动php-fpm,并查看相关端口```html/xml/usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ininetstat -anpt | grep 9000cd /opt/php-7.1.10/sapi/fpmcp php-fpm.service /usr/lib/systemd/system/php-fpm.servicesystemctl restart php-fpm.service

![26 启动phpfpm 查看端口.png](https://s2.51cto.com/images/20220110/1641802963375403.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) ![26 启动phpfpm 查看端口 2.png](https://s2.51cto.com/images/20220110/1641802956628969.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) 配置 Nginx 支持 PHP 解析 vim /usr/local/nginx/conf/nginx.conf 65行,取消注释 ![27 配置Nginx支持PHP解析 2.png](https://s2.51cto.com/images/20220110/1641803013654257.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) ```html/xml systemctl restart nginx.service #重启服务

27 配置Nginx支持PHP解析 3.png创建验证网页vim /usr/local/nginx/html/index.php(里面的内容)```html/xml<?phpphpinfo();?>

![28 验证PHP测试页 1.png](https://s2.51cto.com/images/20220110/1641803107587716.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) ![28 验证PHP测试页 2.png](https://s2.51cto.com/images/20220110/1641803166750110.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) 验证:客机使用浏览器访问 http://192.168.206.5/index.php ![28 客机访问网站 成功.png](https://s2.51cto.com/images/20220110/1641803075641996.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) 验证:数据库工作是否正常 ```html/xml 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; quit

29 验证数据库是否正常.png

替换原来的测试页内容```html/xmlvim /usr/local/nginx/html/index.php

<?php$link=mysqli_connect('192.168.80.10','bbsuser','admin123');if($link) echo "Success!!";else echo "Fail!!";?>

![30 替换原来的测试内容 2.png](https://s2.51cto.com/images/20220110/1641803260105124.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) ![30 替换原来的测试内容.png](https://s2.51cto.com/images/20220110/1641803266767648.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) 验证:再次登录 http://192.168.206.5/index.php ![30 再次客机登录 成功.png](https://s2.51cto.com/images/20220110/1641803276833938.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) ### 部署 Discuz 论坛 首先是winscp传文件去opt目录,解压后进入,替换网站缓存 ```html/xml 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/

31 部署 Discuz 1.png31 进入解压目录,实行文件替换.png下面是调整论坛的文件权限(用于按装条件)

```html/xmlcd /usr/local/nginx/html/bbs/

chown -R root:nginx ./config/chown -R root:nginx ./data/chown -R root:nginx ./uc_client/chown -R root:nginx ./uc_server/

chmod -R 777 ./config/chmod -R 777 ./data/chmod -R 777 ./uc_client/chmod -R 777 ./uc_server/

![32 调整论坛目录的权限 3.png](https://s2.51cto.com/images/20220110/1641803410696101.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) 论坛页面访问 http://192.168.19.20/bbs/install/index.php #填写数据库信息 数据库服务器:localhost ###本地架设就用localhost,如何不是在在本机上就要填写IP地址和端口号 数据库名字:bbs 数据库用户名:bbsuser 数据库密码:123456 管理员账号:admin 管理员密码:admin123 #结束 论坛内部页面 http://192.168.19.20/bbs/index.php 论坛后台管理员页面 http://192.168.19.20/bbs/admin.php ![33 客机登录测试,论坛安装完成·.png](https://s2.51cto.com/images/20220110/1641803461643278.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) ![33 客机安装论坛.png](https://s2.51cto.com/images/20220110/1641803464239216.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) ![33 客机安装论坛 2.png](https://s2.51cto.com/images/20220110/1641803474116929.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) 完成后即可。访问论坛页面: ```html/xml http://192.168.206.5/bbs/index.php #网页 http://192.168.206.5/bbs/admin.php #后台管理界面

拓展实验 fpm参数优化

1、首先是进入进程置文件vim /usr/local/php/etc/php-fpm.conf 17行取消注释2、17行取消注释.png

2、然后进入扩展配置文件vim /usr/local/php/etc/php-fpm.d/www.conf117行3、 117行下动态方式下最小空闲进程数.png

122行3、 122行下动态方式下最大空闲进程数.png

96行3、96行 fpm进程启动方式,动态的.png

107行3、107行最大进程数更改.png112行3、112行默认开启的进程数量.png

3、重启phpfpm。并查看相关端口是否开启``html/xml<br/>kill -USR2cat /usr/local/php/var/run/php-fpm.pid` #重启php-fpm netstat -anpt | grep 9000

ps -elf | grep php-fpm #去进程管理器也可以查看fpm的三个进程是否完成

![4、重启phpfpm。并查看相关端口.png](https://s2.51cto.com/images/20220110/1641803733632001.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=)
上一篇:Nginx 网站服务
下一篇:没有了
网友评论