Apache 特性
1、Apache 是 LAMP 架构最核心的 Web Server,开源、稳定、模块丰富是 Apache 的优势。但 Apache 的缺点是有些臃肿,内存和 CPU 开销大,性能上有损耗,不如一些轻量级的 Web 服务器(譬如:Nginx、Tengine等)高效,轻量级的 Web 服务器对于静态文件的响应能力来说远高于 Apache 服务器。
2、Apache 做为 Web Server 是负载 PHP 的最佳选择,如果流量很大的话,可以采用 Nginx 来负载非 PHP 的 Web 请求。Nginx 是一个高性能的 HTTP 和反向代理服务器,Nginx 以其稳定、丰富功能集、示例配置文件和低系统资源的消耗而闻名。Nginx 现能支持 PHP 和 FastCGI,也支持负载均衡和容错,可和 Apache 配合使用,是轻量级的 HTTP 服务器的首选。
3、Web 服务器缓存也有多种方案,Apache 提供了自己的缓存模块,也可以使用外加的 Squid 模块进行缓存,这两种方式均可有效提高 Apache 的访问响应能力。Squid Cache 是一个 Web 缓存服务器,支持高效缓存,可作为网页服务器的前置 cache 服务器缓存相关请求以提高 Web 服务器速度。把 Squid 放在 Apache 的前端来缓存 Web 服务器生成动态内容,而 Web 应用程序只需要适当地设置页面实效时间即可。如访问量巨大,则可考虑使用 memcache 作为分布式缓存。
4、PHP 的加速可使用 eAccelerator 加速器,eAccelerator 是一个自由开放源码的 PHP 加速器。它会优化动态内容缓存,提高 PHP 脚本缓存性能,使 PHP 脚本在编译状态下,对服务器的开销几乎完全消除。它还可对脚本起优化作用,以加快其执行效率。 使 PHP 程序代码执效率可提高 1-10 倍。
##以上资料来源:https://www.zhihu.com/question/19697826
mkdir /application/nginx/conf/extra -p
##把我们的虚拟主机文件放在这个扩展目录中,可以在管理网站的时候更加方便
vim /application/nginx/conf/nginx.conf
##将主配置文件修改为以下内容
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
include extra/blog.conf;
include extra/easy.conf;
include extra/bad.conf;
}
vim /application/nginx/conf/extra/blog.conf
##将虚拟主机blog配置文件配置为以下内容,不存在则创建
server {
listen 80;
server_name www.blog.vperson.org.cn;
location / {
root html/blog;
index index.html index.htm;
}
}
vim /application/nginx/conf/extra/easy.conf
##将虚拟主机easy配置为以下内容,不存在则创建
server {
listen 80;
server_name www.easy.vperson.org.cn;
location / {
root html/easy;
index index.html index.htm;
}
}
vim /application/nginx/conf/extra/bad.conf
##将虚拟主机bad配置文件修改为以下内容,不存在则创建
server {
listen 80;
server_name www.bad.vperson.org.cn;
location / {
root html/bad;
index index.html index.htm;
}
}
cd /application/nginx/html/
for name in blog bad easy;do mkdir $name; echo "$name.vperson.org.cn" >
$name/index.html;
done
##利用for循环创建目录,并向index.html中写入内容
tree ./
bad
│ └── index.html
├── blog
│ └── index.html
├── easy
│ └── index.html
tar zxvf mysql-5.5.32-linux2.6-x86_64.tar.gz
cp -avr mysql-5.5.32-linux2.6-x86_64/ /application/
cd /application/
mv mysql-5.5.32-linux2.6-x86_64/ mysql-5.5.32/
ln -s mysql-5.5.32/ mysql
useradd -M -s /sbin/nologin mysql
cd mysql
mkdir /application/mysql/data -p
chown -R mysql:mysql /application/mysql-5.5.32/
-----------------------------------------------------------------
./scripts/mysql_install_db --basedir=/application/mysql/
--datadir=/application/mysql/data/ --user=mysql
##初始化数据库
mysql_install_db根据版本的不同可能存放的路径也不一样
--basedir是mysql的安装路缙
--datadir是数据文件存放路径
--user是用户名
成功的标准是echo $?没有错误+两个OK没有error
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
##想要开机自动启动,就把mysql.server放到正确的位置即/etc/init.d/mysqld
/application/mysql//bin/mysqladmin -u root password 'new-password'
/application/mysql//bin/mysqladmin -u root -h vperson password 'new-password'
Alternatively you can run:
/application/mysql//bin/mysql_secure_installation
##设置密码的方法
You can start the MySQL daemon with:
cd /application/mysql/ ; /application/mysql//bin/mysqld_safe &
##运行数据库
You can test the MySQL daemon with mysql-test-run.pl
cd /application/mysql//mysql-test ; perl mysql-test-run.pl
##测试数据库
提示:/etc/init.d/mysqld实质是复制了mysql.server文件,所以一定不要和cd /application/mysql/
; /application/mysql//bin/mysqld_safe &方法一起用否则会出错
---------------------------------------------------------------
\cp support-files/my-medium.cnf /etc/my.cnf
\cp support-files/mysql.server /etc/init.d/mysqld
--------------------------------------
vim /etc/init.d/mysqld
..................
basedir=/application/mysql/
datadir=/application/mysql/data
...................
或者
#sed -i'46s/\(basedir=\)/\1\/application\/mysql/p' /etc/init.d/mysqld
##修改46行为basedir=/application/mysql,只限定当前环境,其他环境可能有变化
#sed -i'47s/\(datadir=\)/\1\/application\/mysql\/data/p' /etc/init.d/mysqld
##修改datadir为/application/mysq/data
----OK---------------------------------
chmod +x /etc/init.d/mysqld
/etc/init.d/mysqld start
echo "export PATH=/application/mysql/bin:$PATH" >> /etc/profile
source /etc/profile
----------------------------------------------------
mysql_secure_installation
##以下内容看自己的需求
mysql -uroot -p
mysql>show databases;
mysql> use mysql
mysql> show tables;
mysql> select User,Host from user;
mysql>DELETE FROM user WHERE User='root' and Host='::1';
## 目前是不会用的到的所以删除,如果有需求就不用删除
mysql> quit
--OK--------------------------------------------------
总结:
a) 针对自己的硬件平台选用合适的编译器来优化编译后的二进制代码;
b) 根据不同的软件平台环境调整相关的编译参数;
c) 针对我们特定应用场景选择需要什么组件不需要什么组件;
d) 根据我们的所需要存储的数据内容选择只安装我们需要的字符集;
e) 同一台主机上面可以安装多个MySQL;
f) 等等其他一些可以根据特定应用场景所作的各种调整。
在源码安装给我们带来更大灵活性的同时,同样也给我们带来了可能引入的隐患:
a) 对编译参数的不够了解造成编译参数使用不当可能使编译出来的二进制代码不够稳定;
b) 对自己的应用环境把握失误而使用的优化参数可能反而使系统性能更差;
c) 还有一个并不能称之为隐患的小问题就是源码编译安装将使安装部署过程更为复杂,所花费的
时间更长;
slowlog = /app/logs/$pool.log.slow
request_slowlog_timeout = 10
--------------------------------------------------------------------------
../sbin/php-fpm -t
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
错误:ERROR: Unable to create or open slowlog(/applog/logs/www.log.slow): No such file or directory (2)
解决:mkdir /applog/logs/ -p
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
../sbin/php-fpm
lsof -i :9000
================================================
我编译PHP遇到的错误:
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
错误:configure: error: Don't know how to define struct flock on this system, set --enable-opcache=no
解决:
ln -s /application/mysql/lib/libmysqlclient.so /usr/lib64/
ln -s /application/mysql/lib/libmysqlclient.so.18 /usr/lib64/
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
问题:checking whether to enable embeddedMySQLi support... yes
checking for mysql_set_server_optionin -lmysqlclient... no
configure: error: wrong mysql libraryversion or lib not found. Check config.log for more information.
解决:--with-mysqli后面不加路径
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
问题:Don't know how to define struct flockon this system, set --enable-opcache=no
解决:
以下红色路径看具体mysql安装路径而定
32位系统:
ln -s /usr/local/MySQL/lib/libmysqlclient.so /usr/lib/
ln -s /usr/local/mysql/lib/libmysqlclient.so.18/usr/lib/libmysqlclient.so.18