402v /posts/wo-de-fu-wu-qi-da-jian-huan-jing-jie-shao
我的服务器搭建环境介绍
服务器搭建多了就是个体力活儿,记录一下我自己每次搭建服务器的配置过程,每次搭建新的服务器都会查看,也希望对其他人有用处。
非root环境下运行apt-get等命令记得加sudo,下文不特意说明了。
涉及到的方面:
- DigitalOcean
- Git
- Dotfile(强烈建议把各种dotfile上传到git,同步很方便,同时也可以去借鉴别人的dotfile)
- vim
- Vundle
- command-t
- Oh my zsh
- z plugin
- ruby
- rbenv
- rails
- bundler
- unicorn
- nginx
- ghost blog
#开始搭建
创建droplet的时候记得选中ssh文件,否则还要密码登录,很麻烦
-
DigitalOcean新建Droplet;
-
mkdir -p ~/ws/github -
git clone git@github.com:kimimaro/Dotfile.git 到 /root/ws/github -
拷贝 Dotfile/vim/.vim 和 Dotfile/vim/.vimrc 到/root
-
拷贝 Dotfile/git/.gitconfig 到/root
-
安装Vundle:
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim打开vim运行:PluginInstall或者直接运行:vim +PluginInstall +qall -
安装oh-my-zsh: 首先安装
zsh:apt-get install zsh再运行sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
拷贝 Dotfile/zsh/.zshrc 到/root
7. source ~/.zshrc
重新登录后默认用zsh运行
###ruby环境(用于运行 command-t)
-
安装rbenv:
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc echo 'eval "$(rbenv init -)"' >> ~/.zshrc source ~/.zshrc
这时候运行type rbenv,则会输出:rbenv is a shell function,表示安装成功
-
安装ruby: rbenv默认不提供install命令,需要安装插件:
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
安装ruby需要先安装依赖,Ubuntu下运行:
apt-get install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev
其他环境的依赖可以在这里找到:https://github.com/sstephenson/ruby-build/wiki
-
然后运行
rbenv install 2.0.0-p645(我通常用这个版本的ruby) -
waiting for a really long time
-
使用这个ruby版本:rbenv global 2.0.0-p645
-
ruby安装的同时可以安装带有ruby的vim版本,ubuntu 14.04默认是不带的,通过
vim —version | grep ruby可以验证,log出 +ruby是支持,-ruby是不支持 -
安装支持ruby的vim方法如下:
apt-get update # DigitalOcean 的默认环境上apt-get不是最新,其实每次install前都应该update一下才好 apt-get install mercurial # 这里也是漫长的等待 mkdir ~/tmp cd !$ hg clone https://vim.googlecode.com/hg/ vim cd vim ./configure --enable-rubyinterp make make install
vim 默认装在了/usr/local/bin/vim,重启shell之后再次运行 vim --version | grep ruby 验证ruby已经支持了
进入vim,打印一下ruby的版本::ruby puts "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
显示:2.0.0-p645 则表示ruby环境正确,因为编译command-T时要求与vim支持的ruby版本相同。
-
安装command-T:
cd ~/.vim/bundle/command-t/ruby/command-t ruby extconf.rb make
安装成功
###配置域名指向
访问DNSPod上
###glone我的Ghost
mv /var/www/ghost /var/www/ghost_backup
git clone git@github.com:kimimaro/ghost_blog.git /var/www/ghost
注意:root账户clone下来的目录用户组为root root,而DigitalOcean启动Ghost时使用的用户组是ghost ghost,见:
因此需要 chmod -R ghost /var/www/ghost && chgrp -R ghost /var/www/ghost
#clone vno主题
git submodule init
git submodule update
同样需要切换用户组: chmod -R ghost /var/www/ghost/content/themes/vno/ && chgrp -R ghost /var/www/ghost/content/themes/vno/
###clone JSPatchConvertor(iOS JSPatch的一个转换工具)
git@github.com:kimimaro/JSPatchConvertor.git /var/www/JSPatchConvertor.git
###创建deploy用户
adduser deploy
按照上述步骤再配置一次deploy用户
###clone aboutme(我的个人主页)
-
首先安装bundler:
git clone git://github.com/carsomyr/rbenv-bundler.git ~/.rbenv/plugins/bundler gem install bundler rbenv rehash -
进入aboutme目录:
cap deploy
安装sqlite3会报错,因为本地没有安装:apt-get install libsqlite3-dev
###clone projects(我的项目主页)
bundle安装:gem install kgio -v ‘2.10.0’ 时会出错,进入服务器运行bundle install就好了
进入projects目录:cap deploy
启动自动运行unicorn:
vi /etc/init.d/unicorn_projects
chmod 755 /etc/init.d/unicorn_projects
update-rc.d unicorn_projects defaults
update-rc.d unicorn_projects enable
- chmod 755 /etc/init.d/unicorn_aboutme
- update-rc.d unicorn_aboutme defaults
- update-rc.d unicorn_aboutme enable
删除用户的shell使的用户不能被登录:usermod -s /sbin/nologin ghost
更改用户主目录: usermod -d /home/ghost ghost
更改用户shell: usermod -s /bin/bash ghost
linux启动运行
$ sudo update-rc.d ghost defaults
$ sudo update-rc.d ghost enable
#创建新的Ghost blog
- clone blog库到本地,并更改用户和组到ghost
- 创建etc/init
- 启动新的ghost进程
- 添加nginx配置,重启nginx
- 重启服务器后即可访问
如果上述过程配置不成功(ghost用户执行
npm install --production失败),则尝试copy一个已有的/var/www/ghost项目,这样不需要执行npm install
#Where to go
- node-modules本地化
- ruby gems本地化
评论 · 0
还没有评论。