php-fpm配置及管理(无须重启,即可重新加载配置及LOG日志)

PHP-FPM参数

php-fpm {start|stop|quit|restart|reload|logrotate}
--start 启动php的fastcgi进程
--stop 强制终止php的fastcgi进程
--quit 平滑终止php的fastcgi进程
--restart 重启php的fastcgi进程
--reload 重新平滑加载php的php.ini
--logrotate 重新启用log文件

master进程信号

SIGINT, SIGTERM 立刻终止
SIGQUIT 平滑终止
SIGUSR1 重新打开日志文件
SIGUSR2 平滑重载所有worker进程并重新载入配置和二进制模块

示例:
php-fpm 关闭:
kill -SIGINT `cat /usr/local/php/var/run/php-fpm.pid`
php-fpm 重启:
kill -SIGUSR2 `cat /usr/local/php/var/run/php-fpm.pid`

nginx ssl 配置

生成证书

openssl genrsa -des3 -out xxx.key 1024  
openssl req -new -x509 -key xxx.key -out xxx.crt -days 3650  
openssl rsa -in openssl.key -out xxx_nopass.key 

默认配置

ssl                     on;
ssl_certificate         /etc/nginx/certs/xxx.crt;
ssl_certificate_key     /etc/nginx/certs/xxx_nopass.key;
ssl_session_timeout     5m;

ssl_protocols           SSLv2 SSLv3 TLSv1;
ssl_prefer_server_ciphers       on;

gitolite使用

本地生成一个证书,并传到远程服务器

生成证书

cd ~/.ssh/
ssh-kengen -f shining

将证书传送到远程服务器

scp YourName.pub  YourName@HostName:YourName.pub

安装gitolite(git服务器端)

新增一个git用户,不需要密码。
登录到git用户,可以从root用户通过su切换过去。
确认 ~/.ssh/authorized_keys 不存在
将公钥放在 ~/YourName.pub
运行下面的命令:

# 获取版本库
git clone git://github.com/sitaramc/gitolite
# 创建bin目录,用于存放安装后的文件
mkdir -p ~/bin
# 将gitolite安装到bin目录
gitolite/install -to ~/bin
# 使用YourName.pub公钥初始化版本库
gitolite setup -pk YourName.pub

设置本地的.ssh/config

vim ~/.ssh/config

host githost
  user git
  hostname HostName
  port xxx 
  identityfile ~/.ssh/YourName.pub

管理项目、人员、证书

git clone githost:gitolite-admin.git
conf下是项目及人员配置
keydir下是证书

给fastestmirror再提速

fedora和centos安装了fastermirror之后会快一些,但是还是经常选到国外的站点。

方法1:修改源配置文件(推荐,以fedora20为例)

sudo vim fedora.repo
# 找到以下这行
metalink=https://mirrors.fedoraproject.org/metalink?repo=fedora-$releasever&arch=$basearch
# 后面添加&country=cn
metalink=https://mirrors.fedoraproject.org/metalink?repo=fedora-$releasever&arch=$basearch&country=cn
sudo vim fedora-updates.repo
# 找到以下这行
metalink=https://mirrors.fedoraproject.org/metalink?repo=updates-released-f$releasever&arch=$basearch
# 后面添加&country=cn
metalink=https://mirrors.fedoraproject.org/metalink?repo=updates-released-f$releasever&arch=$basearch&country=cn

方法2:修改fastestmirror.conf

sudo vim /etc/yum/pluginconf.d/fastestmirror.conf

修改后清除fastestmirror和metalink缓存

sudo yum clean metadata plugins
sudo yum -y update

gitlab安装及使用

操作系统是ubuntu12.04,先下载gitlab deb,https://www.gitlab.com/downloads/

参考地址:https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md

apt-get install postfix
wget https://downloads-packages.s3.amazonaws.com/gitlab_6.7.2-omnibus-1.ubuntu.12.04_amd64.deb
sudo dpkg -i gitlab_6.7.2-omnibus-1.ubuntu.12.04_amd64.deb
sudo gitlab-ctl reconfigure

facebook hack 试用

fedora 20下安装hhvm

添加hhvm源:
vim /etc/yum.repos.d/hhvm.repo

[hhvm]
name=HHVM for Fedora $releasever - $basearch
baseurl=http://dl.hhvm.com/fedora/$releasever/$basearch/

更新

wget http://dl.hhvm.com/conf/hhvm.gpg.key
sudo rpm --import hhvm.gpg.key
sudo yum install hhvm

性能比较

PHP hello world

hhvm -m daemon -p 9910 t.php
ab -n10000 -c100 http://localhost:9910/t.php  # 15687/sec
ab -n10000 -c100 http://localhost/t.php # nginx+fpm: 11016/sec

Yii test

hhvm -m daemon -p 9910 yiitest/index.php 
ab -n10000 -c100 http://localhost:9910/yiitest/index.php # 4039/sec
ab -n10000 -c100 http://localhost/yiitest/index.php # nginx+fpm: 259/sec

vim hack.php

<?hh
echo 'hello';

test hack.php

hhvm -m daemon -p 9910 hack.php 
ab -n10000 -c100 http://localhost:9910/hack.php # 15169/sec 基本无变化,可能因为程序太简单

mysql配置优化

SHOW VARIABLES LIKE ‘%cache%’;
+——————————+———————-+
| Variable_name | Value |
+——————————+———————-+
| binlog_cache_size | 32768 |
| binlog_stmt_cache_size | 32768 |
| have_flashcache | YES |
| have_query_cache | YES |
| key_cache_age_threshold | 300 |
| key_cache_block_size | 1024 |
| key_cache_division_limit | 100 |
| max_binlog_cache_size | 18446744073709547520 |
| max_binlog_stmt_cache_size | 18446744073709547520 |
| metadata_locks_cache_size | 1024 |
| query_cache_limit | 1048576 |
| query_cache_min_res_unit | 4096 |
| query_cache_size | 16777216 |
| query_cache_strip_comments | OFF |
| query_cache_type | ON |
| query_cache_wlock_invalidate | OFF |
| stored_program_cache | 256 |
| table_definition_cache | 400 |
| table_open_cache | 400 |
| thread_cache_size | 8 |
+——————————+———————-+

show status like ‘%cache%’;
+——————————–+———-+
| Variable_name | Value |
+——————————–+———-+
| Binlog_cache_disk_use | 2 |
| Binlog_cache_use | 15514049 |
| Binlog_stmt_cache_disk_use | 0 |
| Binlog_stmt_cache_use | 1170 |
| Com_assign_to_keycache | 0 |
| Flashcache_enabled | OFF |
| Qcache_free_blocks | 2005 |
| Qcache_free_memory | 6565712 |
| Qcache_hits | 77732 |
| Qcache_inserts | 590516 |
| Qcache_lowmem_prunes | 557510 |
| Qcache_not_cached | 338374 |
| Qcache_queries_in_cache | 7191 |
| Qcache_total_blocks | 16631 |
| Ssl_callback_cache_hits | 0 |
| Ssl_session_cache_hits | 0 |
| Ssl_session_cache_misses | 0 |
| Ssl_session_cache_mode | NONE |
| Ssl_session_cache_overflows | 0 |
| Ssl_session_cache_size | 0 |
| Ssl_session_cache_timeouts | 0 |
| Ssl_used_session_cache_entries | 0 |
| Threads_cached | 3 |
+——————————–+———-+

 

mysql缓存参数
MYSQL缓冲区和缓存设置
MySQL 数据库性能优化之缓存参数优化
MySQL写入优化