Last active
December 22, 2015 02:28
-
-
Save loveky/6403179 to your computer and use it in GitHub Desktop.
快速部署Rails部署环境 Nginx + PostgreSQL + Git + RVM + 1.9.3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
deployer_username='deployer' | |
deploy_ssh_pubkey='' | |
db_name='bisaikong' | |
db_username='bisaikong' | |
db_password='bisaikong' | |
# 安装软件包 | |
export DEBIAN_FRONTEND=noninteractive | |
apt-get -y update | |
apt-get -y install curl git-core python-software-properties | |
apt-get -y install nginx | |
#apt-get -y install mysql-server libmysql-ruby libmysqlclient-dev | |
#apt-get -y install postgresql libpq-dev | |
apt-get -y install nodejs | |
apt-get -y install expect | |
# 删除Nginx默认配置,重启Nginx | |
rm /etc/nginx/sites-enabled/default | |
service nginx restart | |
# 安装RVM | |
#curl -L https://get.rvm.io | bash -s stable --ruby=1.9.3 | |
# 创建PostgreSQL用户,数据 | |
#su -c "psql -c \"create user $db_username with password '$db_password'\"" postgres | |
#su -c "psql -c \"create database $db_name owner $db_username\"" postgres | |
# 创建MySQL用户,数据 | |
#mysql -u root -e "CREATE USER '$db_username'@'localhost' IDENTIFIED BY '$db_password';" | |
#mysql -u root -e "CREATE DATABASE IF NOT EXISTS $db_name default charset utf8;" | |
#mysql -u root -e "GRANT ALL ON $db_username.* TO '$db_name'@'localhost';" | |
# 创建部署用户,添加sudo权限,导入ssh登录公钥 | |
adduser --disabled-password --gecos "$deployer_username,,," $deployer_username | |
echo "$deployer_username ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers | |
mkdir "/home/$deployer_username/.ssh" | |
if [ ! -z "$deploy_ssh_pubkey" ]; then | |
echo $deploy_ssh_pubkey >> "/home/$deployer_username/.ssh/authorized_keys" | |
fi | |
# 将Github服务器RSA key fingerprint添加到本地信任列表 | |
expect -c " | |
spawn /usr/bin/ssh \"[email protected]\" | |
expect { | |
\"*yes/no*\" { send \"yes\r\" } | |
} | |
expect eof | |
" | |
cp ~/.ssh/known_hosts /home/$deployer_username/.ssh/ | |
chown -R $deployer_username:$deployer_username /home/$deployer_username/.ssh | |
# 本脚本执行完毕后请继续进行以下配置 | |
# 1. 上传SSH公钥到Github仓库Deploy Key列表(可选) | |
# 2. 为数据库用户更改密码(可选) | |
# 3. 为部署用户设置密码(可选) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment