标签:增强 inf 使用 lock bre freetype 域名 dmi efi
最新版LAMP架构+Discuz论坛LAMP指的Linux(操作系统)、ApacheHTTP 服务器,MySQL(有时也指MariaDB,数据库软件) 和PHP(有时也是指Perl或Python) 的第一个字母,一般用来建立web应用平台。
这个架构经过了漫长时间的考验,但随着时间更迭,各个软件也进行了版本的更新升级,因为公司也有Discuz论坛,但版本比较老,所以想着搭建一套最新版的论坛。下面就为大家介绍当下最新版的LAMP+Discuz论坛。
系统环境介绍
系统 | IP地址 | 内存 | cpu |
---|---|---|---|
centos7.6 | 192.168.70.133 | 5G | 4核 |
使用软件包地址
http://mirrors.hust.edu.cn/apache//httpd/httpd-2.4.37.tar.gz
http://mirrors.hust.edu.cn/apache//apr/apr-1.6.5.tar.gz
http://mirrors.hust.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
http://am1.php.net/distributions/php-7.3.1.tar.gz
discuz论坛包https://pan.baidu.com/s/14ZPFy35pnpYpKeePDFoArw 密码:2olg
mysql解压版https://pan.baidu.com/s/11b_ccrosT0IPdnXhRrU4yQ
密码:ruh5
1、安装环境依赖包
yum -y install \
gcc \
gcc-c++ \
make \
pcre-devel \
expat-devel \
perl \
zlib-devel \
libxml2-devel \
openssl \
openssl-devel \
bzip2-devel
2、解压httpd2.4.37
[root@localhost opt]# tar zxf httpd-2.4.37.tar.gz
3、解压apr-1.6.5、apr-util-1.6.1到httpd-2.4.37/srclib/目录中并更名
[root@localhost opt]# tar zxf apr-1.6.5.tar.gz -C httpd-2.4.37/srclib/
[root@localhost opt]# tar zxf apr-util-1.6.1.tar.gz -C httpd-2.4.37/srclib/
[root@localhost opt]# cd httpd-2.4.37/srclib/
[root@localhost srclib]# mv apr-1.6.5/ apr
[root@localhost srclib]# mv apr-util-1.6.1/ apr-util
[root@localhost srclib]# ls
apr apr-util Makefile.in
以上步骤将apr-1.65和apr-util-1.61包解压并且放到了httpd2.4.37/srclib/下并且更名为apr和apr-util
4、编译
[root@localhost srclib]# cd /opt/httpd-2.4.37/
[root@localhost httpd-2.4.37]#
./configure \
--prefix=/usr/local/httpd \
--enable-deflate \
--enable-expires \
--enable-rewrite \
--enable-charset-lite \
--with-mpm=event \
--enable-mpms-shared=all \
--enable-so \
--enable-modules=most \
--enable-cgi \
--quiet
编译注解
--enable-deflate #压缩模块
--enable-expires #缓存模块
--enable-so #让apache核心装载DSO
--enable-mods-shared=most #采用动态编译进来大多数模块
--enable-modules=most #安装大多数模块
--enable-modules-shared=most #安装大多数共享模块
--enable-mpms-shared=all #支持全部多道处理方式
--with-mpm=prefork #prefork工作模式,派生子进程提供服务
--enable-cgi 启动CGI脚本支持,便于扩展网站的用于访问能力
--enable-rewirte :支持URL重写
--with-mpm=worker #worker工作模式,核心线程处理,使用于使用人群少的场景
--with-mpm=event Apache最新的工作模式,它和worker模式很像
优点:不同的是在于它解决了keep-alive长连接的时候占用线程资源被浪费的问题(HTTP的Keepalive方式能减少TCP连接数量和网络负载),在event工作模式中,会有一些专门的线程用来管理这些keep-alive类型的线程,当有真实请求过来的时候,将请求传递给服务器的线程,执行完毕后,又允许它释放。这增强了在高并发场景下的请求处理
--quiet 安静的输出编译信息
5、正式安装
[root@localhost httpd-2.4.37]# make && make install
6、修改配置文件
[root@localhost httpd-2.4.37]# cd /usr/local/httpd/conf/
[root@localhost conf]# vim httpd.conf #去掉如下行的注释
LoadModule include_module modules/mod_include.so #服务器端的包过滤
LoadModule logio_module modules/mod_logio.so #修改日志格式需要开启
LoadModule filter_module modules/mod_filter.so #过滤器模块
LoadModule rewrite_module modules/mod_rewrite.so #重写模块
LoadModule deflate_module modules/mod_deflate.so #压缩模块
LoadModule expires_module modules/mod_expires.so #缓存模块
在#LoadModule info_module modules/mod_info.so该行下添加如下优化语句
#连接超时时间
TraceEnable off
Timeout 600
KeepAlive Off
KeepAliveTimeout 20
MaxKeepAliveRequests 100
HostnameLookups Off
ServerSignature Off
ServerTokens Prod
#pid文件格式
#PidFile pid/httpd.pid
#防止被点击劫持 SAMEORIGIN为拒绝,ALLOW-FROM为允许
Header always append X-Frame-Options "SAMEORIGIN "
Header always append Frame-Options "SAMEORIGIN"
#设定接收请求的超时时间和最低数据速率
<IfModule reqtimeout_module>
RequestReadTimeout header=5-40,MinRate=500 body=20,MinRate=500
</IfModule>
#压缩模块,压缩级别6,可调DeflateCompressionLevel
<IfModule mod_deflate.c>
DeflateCompressionLevel 6
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-javascriptapplication/x-httpd-php
AddOutputFilterByType DEFLATE *.js
AddOutputFilterByType DEFLATE *.css
AddOutputFilterByType DEFLATE *.htm
AddOutputFilterByType DEFLATE application/ms* application/vnd* application/postscriptapplication/javascript application/x-javascript
AddOutputFilterByType DEFLATE application/x-httpd-php application/x-httpd-fastphp
SetEnvIfNoCase Request_URI .(?:gif|jpeg|png)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI .(?:exe|tgz|zip|bz2|sit|rar)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI .(?:pdf|mov|avi|mp3|mp4|rm)$ no-gzip dont-vary
</IfModule>
#缓存模块
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault A86400
ExpiresByType image/x-icon A2592000
ExpiresByType application/x-javascript A2592000
ExpiresByType text/css A2592000
ExpiresByType image/gif A604800
ExpiresByType image/png A604800
ExpiresByType image/jpeg A604800
ExpiresByType text/plain A604800
ExpiresByType application/x-shockwave-flash A604800
ExpiresByType video/x-flv A604800
ExpiresByType application/pdf A604800
ExpiresByType text/html A900
</IfModule>
#工作模式
<IfModule mpm_prefork_module>
ServerLimit 1200
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxRequestWorkers 1200
MaxConnectionsPerChild 2000
</IfModule>
<IfModule mpm_worker_module>
ServerLimit 20
StartServers 3
MinSpareThreads 75
MaxSpareThreads 100
ThreadsPerChild 64
MaxRequestWorkers 1280
MaxConnectionsPerChild 20000
</IfModule>
<IfModule mpm_event_module>
ServerLimit 20
StartServers 3
MinSpareThreads 75
MaxSpareThreads 100
ThreadsPerChild 64
MaxRequestWorkers 1280
MaxConnectionsPerChild 20000
</IfModule>
#解决中文乱码
<Files ~ "\.html?$">
Header set Content-Type "text/html; charset=utf-8"
</Files>
修改ServerName,去掉注释并进行修改
ServerName www.bbstest.com:80
7、创建httpd命令软链接并查看配置文件语法正确性
[root@localhost conf]# ln -s /usr/local/httpd/bin/apachectl /usr/bin/httpd
[root@localhost conf]# httpd -t
Syntax OK
[root@localhost conf]# httpd start
这个时候我们可以去网页中访问我们的apache的默认主页了,可以先暂时关闭防火墙和selinux,不然无法访问80端口。因为设置了域名在本地主机中进行解析,方便用域名访问。
windows添加本地解析步骤如下:win+r调出这个界面
保存退出就好了。下面我们就能用我们指定的域名去访问网页了。
到这里httpd就搭建完成了。
从mysql5.7开始,源码编译的mysql5.7时间巨长,所以我使用公司mysql5.7的解压版,但这里我会为大家提供mysql5.7编译的链接?源码编译mysql5.7
这是我公司安装mysql5.7的一下相关操作和优化
[root@localhost conf]# cd /opt/
[root@localhost opt]# tar zxf mysql-5.7.21-linux-glibc2.12-x86_64.tgz
[root@localhost opt]# mv mysql-5.7.21-linux-glibc2.12-x86_64 mysql #这里是更名解压包为mysql,方便配置文件修改
[root@localhost opt]# vim /etc/my.cnf #删除里面原有的内容,加入如下
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
character-set-server = utf8mb4
skip_name_resolve = 1
user = mysql
port = 3306
socket = /tmp/mysql.sock
basedir = /opt/mysql/ #从这行到realy-log行,修改路径为mysql存放位置的路径
datadir = /opt/mysql/data
log-error = /opt/mysql/data/log-error.log
pid-file = /opt/mysql/data/mysql.pid
innodb_data_home_dir = /opt/mysql/data
slow-query-log-file=/opt/mysql/data/slow.log
relay-log-index = /opt/mysql/data/relaylog
relay-log-info-file = /opt/mysql/data/relaylog
relay-log = /opt/mysql/data/relaylog
open_files_limit = 10240
table_open_cache = 2048
back_log = 300
max_connections = 10000
max_connect_errors = 20
explicit_defaults_for_timestamp = 1
max_allowed_packet = 64M
thread_cache_size = 300
query_cache_size = 256M
query_cache_limit = 2M
query_cache_min_res_unit = 2k
default-storage-engine = InnoDB
thread_stack = 512K
transaction_isolation = READ-COMMITTED
tmp_table_size = 256M
max_heap_table_size = 256M
key_buffer_size = 2G
sort_buffer_size = 2M
join_buffer_size = 6M
read_buffer_size = 4M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 15G
myisam_repair_threads = 1
interactive_timeout = 1800
wait_timeout = 28800
innodb_data_file_path = ibdata1:120M;ibdata2:200M;ibdata3:200M:autoextend
innodb_buffer_pool_size = 2G
innodb_thread_concurrency = 0
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 16M
innodb_log_file_size = 512M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_purge_threads = 0
slow_query_log = 1
long_query_time = 3
replicate-ignore-db = mysql
replicate-ignore-db = test
replicate-ignore-db = information_schema
#slave-skip-errors = 1032,1062,1026,1114,1146,1048,1396
server-id = 1
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
[mysqldump]
quick
max_allowed_packet = 64M
初始化数据库并启动
ln -s /usr/local/mysql/bin/* /usr/bin #优化命令路径
adduser -s /sbin/nologin mysql #创建mysql用户
mysqld --initialize-insecure #初始化mysql
mysqld_safe & #启动数据库
mysqladmin -uroot -p ‘123123’ #设置数据库密码
搭建之前解决几个小问题,是我编译的时候遇到的
●configure:?error:?off_t undefined; check your library configuration
解决方法:
echo ‘/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64‘>>/etc/ld.so.conf&&ldconfig -v
●configure: error: Please reinstall the libzip distribution
解决方法
wget https://nih.at/libzip/libzip-1.2.0.tar.gz
tar -zxvf libzip-1.2.0.tar.gz
cd libzip-1.2.0
./configure
make
make install
●/usr/local/include/zip.h:59:21: 致命错误:zipconf.h:没有那个文件或目录
解决方法
cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
1、解压
[root@localhost opt]# tar zxf php-7.3.1.tar.gz
2、安装依赖包,因为报错很多因为缺包,所以干脆一起装
yum -y install pcre pcre-devel openssl openssl-devel libicu-devel gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel krb5-devel libidn libidn-devel openldap openldap-devel openldap-servers openldap-client nss_ldap jemalloc-devel cmake boost-devel bison automake libevent libevent-devel gd gd-devel libtool* libmcrypt libmcrypt-devel mcrypt mhash libxslt libxslt-devel readline readline-devel gmp gmp-devel libcurl libcurl-devel openjpeg-devel
3、编译
[root@localhost opt]# cd php-7.3.1/
./configure \
--prefix=/usr/local/php7 \
--with-apxs2=/usr/local/httpd/bin/apxs \
--with-pdo-mysql=/opt/mysql \
--enable-mysqlnd \
--with-pdo-mysql=mysqlnd \
-with-mysqli=mysqlnd \
--with-mysql-sock=/tmp/mysql.sock \
--with-config-file-path=/usr/local/php7 \
--enable-fpm \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-libxml-dir \
--with-xmlrpc \
--with-openssl \
--with-mhash \
--with-pcre-regex \
--with-sqlite3 \
--with-zlib \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--with-cdb \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--with-pcre-dir \
--enable-ftp \
--with-gd \
--with-openssl-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-freetype-dir \
--enable-gd-jis-conv \
--with-gettext \
--with-gmp \
--with-mhash \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-mbregex-backtrack \
--with-onig \
--enable-pdo \
--with-zlib-dir \
--with-pdo-sqlite \
--with-readline \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--with-libxml-dir \
--with-xsl \
--enable-zip \
--with-pear \
--enable-opcache
#这里需要注意,从php5.6之后,编译扩展mysql的语句 --with-mysql=path已经不能使用了。应该添加的是如下几条语句。
--with-pdo-mysql=/opt/mysql \
--enable-mysqlnd \
--with-pdo-mysql=mysqlnd \
-with-mysqli=mysqlnd \
--with-mysql-sock=/tmp/mysql.sock \
扩展指向apache的没变,如下:
--with-apxs2=/usr/local/httpd/bin/apxs
3、安装
make && make install
4、检查httpd.conf文件下有没有php7.so模块,并加以修改
LoadModule php7_module modules/libphp7.so
添加如下位置添加两行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
添加首页识别
5、重启httpd,修改主页信息。
cd /usr/local/httpd/htdocs/
[root@localhost htdocs]# httpd restart
[root@localhost htdocs]# vim index.php #添加如下几行
<?php
phpinfo();
?>
6、网页中查看
www.bbstest.com/index.php
在网页中查找如下内容
有这两个模块说明支持mysql的扩展。
7、php连接mysql
[root@localhost htdocs]# mysql -uroot -p123123
mysql> create database bbs;
mysql> grant all privileges on bbs.* to ‘bbsuser‘@‘192.168.70.%‘ identified by ‘123123‘ with grant option;
mysql> flush privileges;
8、再次修改主页,php连接mysql
vim index.php
<?php
$link=mysqli_connect(‘192.168.70.133‘,‘bbsuser‘,‘123123‘);
if($link) echo "<h1>PHP-link-MYSQL Success!!</h1>";
else echo "PHP-link-MYSQL Fail!!";
?>
网页中直接刷新网页,出现PHP-link-MYSQL Success!!则连接成功。7以前的php连接语句mysql_connect已经被废弃,现使用mysqli_connect。
这样php连接mysql就OK了,下面搭建discuz论坛。
1、修改httpd配置文件
vim /usr/local/httpd/conf/httpd.conf #去掉下行的注释
Include conf/extra/httpd-vhosts.conf
2、重启httpd
httpd restart #会报两个warning,不用管
3、设置虚拟目录
cd /usr/local/httpd/conf/extra
[root@localhost extra]# cp httpd-vhosts.conf httpd-vhosts.conf.bk #先备份下
[root@localhost extra]# vim httpd-vhosts.conf #末行添加如下内容
<VirtualHost *:80>
DocumentRoot "/usr/local/httpd/htdocs/data/www" #这里指定bbs的目录位置,需要创建
ServerName www.bbstest.com
ServerAlias www.bbstest.com
</VirtualHost>
4、解压Discuz论坛包
unzip Discuz_X3.3_SC_UTF8.zip
[root@localhost abc]# ls #会看到如下3个包
Discuz_X3.3_SC_UTF8.zip readme upload utility
cd /usr/local/httpd/htdocs/
[root@localhost htdocs]# mkdir -p data/www/ #创建discuz文件目录
[root@localhost htdocs]# cd data/www/
[root@localhost www]# mv /opt/abc/upload/* . #移动discuz项目内容到当前目录
chown -R daemon config data uc_client/data uc_server/data/ #改变属主
5、重启httpd,网页中访问
httpd restart
www.bbstest.com/install
好了,到这里LAMP最新版的Discuz论坛搭建完成了,呼呼~
Apache2.4.37+mysql5.7+PHP7.31最新版LAMP架构+Discuz论坛
标签:增强 inf 使用 lock bre freetype 域名 dmi efi
原文地址:http://blog.51cto.com/13760226/2344592