月度归档:2014年03月

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写入优化

wine中文字体美化

sudo yum install wqy*

vim ~/font.reg

[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\FontLink\SystemLink]
"Lucida Sans Unicode"="wqy-microhei.ttc"
"Microsoft Sans Serif"="wqy-microhei.ttc"
"MS Sans Serif"="wqy-microhei.ttc"
"Tahoma"="wqy-microhei.ttc"
"Tahoma Bold"="wqy-microhei.ttc"
"SimSun"="wqy-microhei.ttc"
"Arial"="wqy-microhei.ttc"
"Arial Black"="wqy-microhei.ttc"
[HKEY_CURRENT_USER\Control Panel\Desktop]
"FontSmoothing"="2"
"FontSmoothingType"=dword:00000002
"FontSmoothingGamma"=dword:00000578
"FontSmoothingOrientation"=dword:00000001
[HKEY_CURRENT_USER\Software\Wine\X11 Driver]
"ClientSideAntiAliasWithCore"="Y"
"ClientSideAntiAliasWithRender"="Y"
"ClientSideWithRender"="Y"

wine regedit,选择导入,重新开启应用

使用vagrant快速搭建MariaDB Galera Cluster集群测试环境

参考

下载并安装ubuntu 12.04的32位box 初始化vagrant box

wget http://files.vagrantup.com/precise32.box
vagrant box add base Downloads/precise32.box
vagrant init

设置最大内存512

vim ~/VagrantFile

config.vm.provider :virtualbox do |vb|
    # Don't boot with headless mode
    vb.gui = false

    # Use VBoxManage to customize the VM. For example to change memory:
    vb.customize ["modifyvm", :id, "--memory", "512"]
end

配置虚拟IP

config.vm.network :private_network, ip: "10.0.1.100"

启动虚拟机修改为163源

启动虚拟机,并通过ssh登录到客户机

vagrant up
vagrant ssh

采用163.com的源

sudo vim /etc/apt/sources.list

deb http://mirrors.163.com/ubuntu/ precise main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ precise-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ precise-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ precise-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ precise-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ precise main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ precise-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ precise-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ precise-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ precise-backports main restricted universe multiverse

deb http://archive.ubuntu.com/ubuntu/ precise main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ precise-security main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ precise-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ precise-proposed main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ precise-backports main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ precise main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ precise-security main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ precise-updates main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ precise-proposed main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ precise-backports main restricted universe multiverse

更新源

sudo aptitude update

添加mariadb源,并安装集群版

大部分linux的二进制发行包都可以在这里找到:https://downloads.mariadb.org/mariadb/repositories/

apt-get install python-software-properties
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
sudo add-apt-repository &#039;deb http://mirrors.tuna.tsinghua.edu.cn/mariadb/repo/5.5/ubuntu precise main&#039;
sudo aptitude update
sudo aptitude install mariadb-galera-server mariadb-client

打包虚拟机,以便再次安装 退出客户机,回到主机界面

vargrant package --output galera-db.box
vargant box add db galera-db.box

配置虚拟机

vim ~/Vagrantfile

Vagrant.configure("2") do |config|
  config.vm.provision "shell", inline: "echo Hello"
  config.vm.define "db1" do |db1|
    db1.vm.box = "db"
    db1.vm.network :private_network, ip: "10.0.1.100"
  end

  config.vm.define "db2" do |db2|
    db2.vm.box = "db"
    db2.vm.network :private_network, ip: "10.0.1.101"
  end
end

重新加载虚拟机配置

vagrant reload

配置第一台db节点

vagrant ssh db1
sudo service mysql start
sudo mysql_secure_installation mysql -uroot -p

mysql> GRANT USAGE ON *.* to sst@'%' IDENTIFIED BY 'sstpass123';
mysql> GRANT ALL PRIVILEGES on *.* to sst@'%';
mysql> FLUSH PRIVILEGES;
mysql> quit

sudo cp /usr/share/mysql/wsrep.cnf /etc/mysql/conf.d/ sudo vim /etc/mysql/conf.d/wsrep.cnf

wsrep_provider=/usr/lib/galera/libgalera_smm.so
wsrep_cluster_address="gcomm://"
wsrep_sst_auth=sst:sstpass123
wsrep_sst_method=rsync
wsrep_node_name=db1
wsrep_node_address=10.0.1.100

sudo service mysql restart

安装第二个节点

vagrant ssh db2

除了wsrep.cnf有少许不同外,其他同第一节点

wsrep_cluster_address="gcomm://10.0.1.100"
wsrep_node_name=db2
wsrep_node_address=10.0.1.101

sudo service mysql restart

测试节点同步

mysql -usst -psstpass123 -h10.0.1.100 show status like 'wsrep%'; 可以看到wsrep_connected都为ON

create database testdb;
use testdb;
create table t(id int primary key auto_increment);
insert into t values(null);
insert into t values(null);
select * from t;
exit;

mysql -usst -psstpass123 -h10.0.1.101

use testdb;
select * from t;
insert into t values(null);
insert into t values(null);
select * from t;

参考:

使用vagrant快速搭建phalcon开发环境

vagrant是一款开发环境快速搭建的工具,phalcon是一个c语言的php框架。

参考:

http://www.vagrantup.com/

http://phalconphp.com/en/download/vagrant

下载并安装vagrant

http://www.vagrantup.com/downloads.html

支持windows,linux,mac

下载并启动phalcon镜像

vagrant init phalconbox https://s3-eu-west-1.amazonaws.com/phalcon/phalcon125-apache2-php54-mysql55.box
vagrant up