CentOS 6.2 x86_64 el6 全新系统安装Adspot小记

本文以流水账为主,记录在阿里云的全新CentOS 6.2 x86_64上安装adspot相关软件

一、SSH登录

  1. 首先在本机执行,ssh-keygen -t rsa,默认会在~/.ssh/下生成id_rsa(私钥), id_rsa.pub(公钥)。如果已有,就不用再生成。
  2. 将id_rsa.pub scp到远程服务器~/.ssh/下
  3. cat id_rsa.pub >> authorized_keys,将你的公钥追加到authorized_keys中。如果没有这个文件,touch一个。
  4. chmod -R 600 ~/.ssh (如果需要的话)

二、yum和gcc

  1. yum install gcc时报错,经网友告知,这是阿里云机器限制,必须将/etc/yum.conf的这一行注释:exclude=kernel*
  2. yum -y install gcc-c++ automake autoconf libtool make,全装上 (c++后面cmake要用)

三、mysql

  1. 添加用户和组:
    groupadd mysql
    useradd -g mysql mysql
  2. 下载了mysql-5.5.28.tar.gz,最新版本的源码都需要用cmake编译,所以先yum install cmake先。关于cmake,这篇文章介绍的很好详细:http://who0168.blog.51cto.com/253401/469898
  3. 解压mysql源码包进入目录后执行:cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql (这是最基本的,还可以带许多编译参数,比如下面这个我采用的(当然大部分都可以以后在my.cnf中设置):
    cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
     -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
     -DDEFAULT_CHARSET=utf8 \
     -DDEFAULT_COLLATION=utf8_general_ci \
     -DWITH_MYISAM_STORAGE_ENGINE=1 \
     -DWITH_INNOBASE_STORAGE_ENGINE=1 \
     -DWITH_MEMORY_STORAGE_ENGINE=1 \
     -DWITH_READLINE=1 \
     -DENABLED_LOCAL_INFILE=1 \
     -DMYSQL_DATADIR=/usr/local/mysql/data \
     -DMYSQL_USER=mysql \
     -DMYSQL_TCP_PORT=3306
    在cmake编译过程中,可能会出现必要的package缺失的error,所以cmake之前先安装下面两个包:
    yum -y install ncurses-devel bison 
  4. make && make install
  5. 安装数据库:scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql 
  6. 配置文件: cp support-files/my-medium.cnf /etc/my.cnf
  7. 更改权限: chown -R mysql:mysql /usr/local/mysql (不一定需要)
  8. cp share/mysql.server /etc/init.d/mysql, 以后就可以/etc/init.d/mysql start|stop|restart 启动数据库了
  9. mysqladmin -u root password "newpass"  添加root的新密码。有必要的话再export一下path

四、ruby/rails/git

  1. yum -y install readline,这是为了rails console,必须在安装ruby之前安装
  2. rvm安装: \curl -L https://get.rvm.io | bash -s stable。 在安装过程中,出现过libyaml找不到的问题,目前还没找到很好的解决方法。如果需要rvm本身升级,rvm get stable && rvm reload。如果需要升级ruby,rvm upgrade 1.9.3。rvm基本使用命令:rvm list, rvm use 1.9.3-p327 --default
  3. gem安装下面2个本地包(for nokogiri): yum -y install libxml2-devel libxslt-devel
  4. gem install rails (或在deploy.rb中指定在bundle之前自行安装)
  5. gem install bundle
  6. gem install rb-readline
  7. rake RAILS_ENV=production db:setup (setup=create+schema:load+seed)

五、Nginx

  1. 由于需要代理rails请求,所以先安装passenger。使用gem安装passenger相当简单:
    sudo gem install passenger 
    sudo(rvmsudo) passenger-install-nginx-module
    安装程序会一步步提示进行编译。
  2. 下载最新的stable版本nginx,为了确保编译,先yum安装以下的包: 
    yum -y install pcre-devel openssl openssl-devel cpan
  3. Nginx编译:
    ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_gzip_static_module --with-cc-opt='-Wno-error' --add-module='/Users/tony/.rvm/gems/ruby-1.9.3-p327/gems/passenger-3.0.18/ext/nginx' --with-http_stub_status_module --without-poll_module --without-select_module --with-http_realip_module --with-http_perl_module

    这里采用epoll,去掉了其他event模式,并加入embeded perl的支持。注意:安装完成后可以随时通过/usr/local/nginx/sbin/nginx -V查看编译参数。注意修改为实际安装passenger的路径

  4. 启动:/usr/local/nginx/sbin/nginx
    重启:kill -HUP `cat /usr/local/nginx/logs/nginx.pid`
    测试配置文件:/usr/local/nginx/sbin/nginx -t
    查看编译参数: /usr/local/nginx/sbin/nginx -V

六、Capistrano

  1. 由于默认ssh连接需要一个tty终端,所以在cap deploy之前需要修改一下服务器的/etc/sudoers,注释掉Defaults requiretty这一行
  2. 为了区分staging和production环境,在rails项目的config下建立production.rb和staging.rb。注意默认rvm_path是在$HOME/.rvm,如果安装不是在这个路劲(比如在/usr/local/rvm),则需要设置rvm_path和rvm_bin_path。
    require "rvm/capistrano"
    require "bundler/capistrano"
    require 'capistrano/ext/multistage'
    
    set :stages, ["staging", "production"]
    set :default_stage, "staging"
    
    set :application, "xxx"
    set :repository, "git://github.com/xxx/xxx.git"
    
    set :scm, :git
    set :deploy_via, :remote_cache
    
    set :rvm_ruby_string, 'ruby-1.9.3-p327'
    set :rvm_path, "/usr/local/rvm"
    set :rvm_bin_path, "/usr/local/rvm/bin"
    #before 'deploy:setup', 'rvm:install_rvm'
    #before 'deploy:setup', 'rvm:install_ruby'
    
    set :user, "user_name"
    set :scm_username, "your_git_account"
    set :deploy_to, "/var/www/#{application}"
    
    role :web, "xx.xx.xx.xx"                          # Your HTTP server, Apache/etc
    role :app, "xx.xx.xx.xx"                          # This may be the same as your `Web` server
    role :db,  "xx.xx.xx.xx", :primary => true # This is where Rails migrations will run
  3. cap production deploy:setup
  4. cap production deploy:check
  5. cap production deploy 正式部署

七、PHP

  1. 先预装一堆包:yum -y install tcl-devel.x86_64 libpng-devel.x86_64 libjpeg-devel.x86_64 ghostscript-devel.x86_64 bzip2-devel.x86_64 freetype-devel.x86_64 libtiff-devel.x86_64
  2. 下载最新源码,解压编译:
    ./configure --prefix=/usr/local/php --with-mysql --with-zlib --enable-fpm --with-gd --with-mcrypt --with-openssl --enable-zip --enable-sockets --enable-mbregex --enable-xml --enable-bcmath --enable-shmop --with-mhash --with-xmlrpc --enable-soap --with-iconv=/usr/local/libiconv --enable-mbstring --with-jpeg-dir=/usr/lib64
    

    如果安装过程中需要native包,请自行安装提示安装。由于GD默认不包括jpeg包,所以如果要加入jpeg支持,需添加--with-jpeg-dir=<DIR>参数进行编译。先运行gdlib-config --all确定libdir的位置(64位操作系统上一般在/usr/lib64)

  3. make && make install

八、安装其他插件: imagemagick, eacclerator

  • ImageMagick通过yum安装即可(yum -y install ImageMagick ImageMagick-devel),装好以后试试看convert命令是否ok。
  • 安装php的imagick插件,在http://pecl.php.net/imagick下载
  • 本地解压后进入该目录,执行/usr/local/php/bin/phpize (或其他phpize路径)
  • ./configure --with-php-config=/usr/local/php/bin/php-config (或其他php-config路径)
  • make && make install(maybe need sudo),此时应该在php的extension目录下看到imagick.so了
  • 编辑/usr/local/php/etc/php.ini(或其他路径),添加extension=imagick.so
  • 装eaccelerator也大致如此,去官网下载tar包如上述方法安装即可。phpize可以用来安装任意的pecl模块,安装dso动态库不需要重新php,适合与已经上线的php服务器增加新模块支持。
  • eaccelerator的配置参数示例:
    extension="eaccelerator.so"
    eaccelerator.shm_size="16"
    eaccelerator.cache_dir="/tmp/eaccelerator"
    eaccelerator.enable="1"
    eaccelerator.optimizer="1"
    eaccelerator.check_mtime="1"
    eaccelerator.debug="0"
    eaccelerator.log_file="/var/log/eaccelerator_log"
    eaccelerator.filter=""
    eaccelerator.shm_max="0"
    eaccelerator.shm_ttl="0"
    eaccelerator.shm_prune_period="0"
    eaccelerator.shm_only="0"
    eaccelerator.compress="1"
    eaccelerator.compress_level="9"
    
posted @ 2012-12-08 00:15  我的白日梦  阅读(449)  评论(0编辑  收藏  举报