GigsGigsCloud 教程 GigsGigsCloud 教程

  • GigsGigsCloud.com
  • GigsGigs.com
Home / 网站构建教程 / #教程#Directadmin 速度/稳定/性能/安全优化教程大全

#教程#Directadmin 速度/稳定/性能/安全优化教程大全

4081 views 1 min , 38 sec read 0

Apache问题优化

Apache 自动关闭的问题:

以前遇到这问题…只会重启解决 , 而且Apache也没办法启动(除了重启机子). 发信询问Directadmin技术后 , 只需要清理ipcs信号即可

官方原文 : https://help.directadmin.com/item.php?id=572

只需要在 /etc/cron.hourly/ipcs_check 该文件(如果没有请创建) , 写入以下内容 (我稍微精简了一下  , 将发送邮件提醒部分去除了)

#!/bin/sh

MAX_SEMAPHORES=15

IPCS=/usr/bin/ipcs
IPCRM=/usr/bin/ipcrm

COUNT=`${IPCS} | grep apache | wc -l`

if [ "$COUNT" -le $MAX_SEMAPHORES ]; then
#all is well, there are no semaphore build-ups.
exit 0;
fi

#we have more than MAX_SEMAPHORES, so clear them out and restart Apache.

LIST=/root/sem.txt

${IPCS} | grep apache | awk '{print $2}' > ${LIST}
for i in `cat ${LIST}`; do
{
${IPCRM} -s $i;
};
done;

/etc/init.d/httpd restart

exit 1;

然后给该文件赋予执行权限 , 可执行以下命令赋予

chmod 755 /etc/cron.hourly/ipcs_check

并重启 , 如果问题依旧 . 请尝试更改内核参数 , 将一下两个参数追加到 /etc/systpl.conf 末尾即可

kernel.msgmni = 1024
kernel.sem = 250 256000 32 1024

MYsql问题优化

在优化MySQL性能这方面我选用了TCMalloc来实现。

什么是TCMalloc

TCMalloc(Thread-Caching Malloc)与标准glibc库的malloc实现一样的功能,但是TCMalloc在效率和速度效率都比标准malloc高很多。TCMalloc是google-perftools工具中的一个(gperftools四个工具分别是:TCMalloc、heap-checker、heap-profiler和cpu-profiler),这个工具是开源的,以源码形式发布。如果觉得自己维护一个内存分配器麻烦的话,可以考虑将TCMalloc静态库连接到你的程序中。使用的时候和glibc中的malloc调用方式一模一样。你需要做的只是把TCMalloc的动态库或者静态库连接进你的程序中,你就可以获得一个高效,快速,安全的内存分配器。

与标准的glibc库的malloc相比,TCMalloc在内存的分配效率和速度要高,可以在高并发的情况下很好的控制内存的使用,提高服务器的性能,降低负载。

如何安装TCMalloc

首先,以root账户登陆服务器。

如果服务器采用64位的Centos,则需要先安装libunwind库,32位系统可略过此步。

wget http://download.savannah.gnu.org/releases/libunwind/libunwind-0.99-alpha.tar.gz
tar zxvf libunwind-0.99-alpha.tar.gz
cd libunwind-0.99-alpha/
CFLAGS=-fPIC ./configure
make CFLAGS=-fPIC
make CFLAGS=-fPIC install

接下来,我们开始安装Tcmalloc。

wget http://gperftools.googlecode.com/files/gperftools-2.0.tar.gz
tar zxvf  gperftools-2.0.tar.gz
cd gperftools-2.0/
./configure
make && make install
echo “/usr/local/lib” > /etc/ld.so.conf.d/usr_local_lib.conf

/sbin/ldconfig

编译完成后,我们编辑mysqld_safe文件,加入Tcmalloc部分。

vi /usr/bin/mysqld_safe

找到# executing mysqld_safe,在下面加入:

export LD_PRELOAD=/usr/local/lib/libtcmalloc.so

保存,退出,重启MySQL。

service mysqld restart

接下来再检查是否生效,运行。

lsof -n | grep tcmalloc

若看到类似如下内容,即表示成功。

mysqld     7758     mysql  mem       REG              253,0   1943001  109233156 /usr/local/lib/libtcmalloc.so.4.1.0

修改DirectAdmin配置文件

DirectAdmin默认的MySQL配置文件还真是非常的简洁。

[mysqld]

local-infile=0

我们需要修改配置文件,参考下面的内容(vim /etc/my.cnf)

[mysqld]
local-infile=0
skip-locking
query_cache_limit=1M
query_cache_size=32M
query_cache_type=1
max_connections=500
interactive_timeout=100
wait_timeout=100
connect_timeout=10
thread_cache_size=128
key_buffer=16M
join_buffer=1M
max_allowed_packet=16M
table_cache=1024
record_buffer=1M
sort_buffer_size=2M
read_buffer_size=2M
max_connect_errors=10
# Try number of CPU’s*2 for thread_concurrency
thread_concurrency=4
myisam_sort_buffer_size=64Mserver-id=1
[safe_mysqld]
err-log=/var/log/mysqld.log
open_files_limit=8192
[mysqldump]
quick
max_allowed_packet=16M
[mysql]
no-auto-rehash
#safe-updates
[isamchk]
key_buffer=64M
sort_buffer=64M
read_buffer=16M
write_buffer=16M
[myisamchk]
key_buffer=64M
sort_buffer=64M
read_buffer=16M
write_buffer=16M
[mysqlhotcopy]
interactive-timeout

 

以上配置内容来自DirectAdmin官方帮助中心(http://help.directadmin.com/item.php?id=44),大家请根据自己的情况自行修改参数。

完成后保存,退出,重启MySQL。

/sbin/service mysqld restart

OK,关于DirectAdmin主机面板下的MySQL性能优化就全部完成,接下来可以去观察下你的MySQL性能有没得到质的飞跃。

Directadmin软件性能优化

升级到Custom Build 2.0

在SSH中执行以下命令即可升级到CB2.0 , CB2.0有大量新组件可用 (但是PHP5.2被废弃) . 升级耗时较长 , 请在screen里面执行 , 避免掉线中断

cd /usr/local/directadmin
mv custombuild custombuild_1.x
wget -O custombuild.tar.gz http://files.directadmin.com/services/custombuild/2.0/custombuild.tar.gz
tar xvzf custombuild.tar.gz
cd custombuild
./build
./build all d
./build rewrite_confs

升级MySQL为MariaDB

升级过程中 , MySQL的数据将会被自动备份到 /usr/local/directadmin/custombuild/mysql_backups 中 , 升级失败会自动回滚

cd /usr/local/directadmin/custombuild
./build set mysql_inst mariadb
./build set mariadb 10.1
./build mysql

将Apache替换成Apahce(后端)+Nginx(前端)

这样做好处非常多 而且没有坏处 , 可以直接使用.htaccess重写规则 . nginx的高并发能力 , 执行以下命令进行升级

cd /usr/local/directadmin/custombuild
./build set webserver nginx_apache
./build nginx_apache
./build rewrite_confs

将php运行模式更改成php-fpm

php-fpm隔离性强 性能佳 跑php的不二选择, 执行以下命令进行更改

cd /usr/local/directadmin/custombuild
./build set php1_mode php-fpm
./build set php2_mode php-fpm
./build php
./build rewrite_confs
DirectAdmin优化 网站构建教程

About MONSTER

View all posts by MONSTER →

Related Articles

  • DirectAdmin/Linux面板的安装脚本+教程
  • VDVEST定制版/Linux面板的安装脚本+教程(vDDoS Proxy+Fail2ban+File Manager)
  • Kangle/Linux面板的安装脚本+教程
  • LNMP/军哥Linux一键包的安装脚本+教程
COPYRIGHT © GIGSGIGSCLOUD.COM GIGSGIGS.COM. 本站教程仅供参考,本站不提供任何技术支持, 也不负责任何有可能引起的问题,如遇问题请借助搜索引擎。