MYSQL_PASSWD="test"
MYSQL_RHODECODE="rhodecode"
MYSQL_RHODECODE_USER="rhodecode"
MYSQL_RHODECODE_PASSWD="test"
RHODECODE_DIR="/home/hui/rhodecode1"
RHODECODE_USER="admin"
RHODECODE_PASSWD="test"
WEB_SERVER_NAME="hg.server.com"
#安装mysql
sudo apt-get install -y mysql-server python-mysqldb (done)
mysql root 密码:hui
#开启mysql
/etc/init.d/mysql start
#新建Mysql账号、数据库 (done)
create database rhodecode;
GRANT ALL PRIVILEGES ON rhodecode.* TO 'rhodecode'@'localhost' IDENTIFIED BY 'test';
#重启Mysql服务 (done)
sudo /etc/init.d/mysql restart
#安装rhodecode的各种依赖包 (done)
sudo apt-get install -y python-setuptools python-dev mysql-client
#######安装rhodecode########## #pip改为豆瓣源 (done)
sudo pip install "rhodecode==1.5.4"
ps:源码方式安装pip
wget http://pypi.python.org/packages/source/p/pip/pip-0.7.2.tar.gz (替换为最新的包)
tar xzf pip-0.7.2.tar.gz
cd pip-0.7.2
python setup.py install
pip的语法有很多,例如 列出安装的packages:pip freeze | sort
安装特定版本的package: pip install "rhodecode==1.5.4" 通过使用==, >=, <=, >, <来指定一个版本号。
#建立工作目录
mkdir -p /home/hui/rhodecode1
#生成配置文件 (done)
cd /home/hui/rhodecode1
paster make-config rhodecode /home/hui/rhodecode1/production.ini
#关联mysql数据库 (done)
sed -i -e "s/^sqlalchemy.db1.url.*/sqlalchemy.db1.url = mysql:\/\/rhodecode:test@localhost\/rhodecode/g" /home/hui/rhodecode1/production.ini
#中文界面 (done)
sed -i -e "s/^lang.*/lang = zh_CN/g" /home/hui/rhodecode1/production.ini
#生成管理员账户 (done)
paster setup-rhodecode /home/hui/rhodecode1/production.ini --user=admin --password=test --email=root@localhost --repos=/home/hui/rhodecode1 --force-yes
#更新权限,改为www-data用户所有
chmod -R 755 /home/hui/rhodecode1
chown -R www-data.www-data /home/hui/rhodecode1
#####将Nginx和rhodecode进行结合#######
WEB_SERVER_NAME="hg.server.com"
#停止nginx服务,防止错误
/etc/init.d/nginx stop 2>/dev/null
#安装nginx
apt-get install -y nginx
#利用proxy关联nginx和rhodecode
cd /etc/nginx/sites-available/
cat <<EOF >/etc/nginx/sites-available/rhodecode
upstream rc {
server 127.0.0.1:5000;
}
server {
listen 80;
server_name $WEB_SERVER_NAME;
access_log /var/log/nginx/rhodecode.access.log;
error_log /var/log/nginx/rhodecode.error.log;
location / {
try_files \$uri @rhode;
}
location @rhode {
proxy_pass http://rc;
include /etc/nginx/proxy_rhodecode.conf;
}
}
EOF
cd ../sites-enabled
ln -s ../sites-available/rhodecode .
#配置proxy(如果不是shell脚本,不要直接copy,要把配置中“\$”的“\”符号去掉)
cat <<EOF >/etc/nginx/proxy_rhodecode.conf
proxy_redirect off;
proxy_set_header Host \$host;
proxy_set_header X-Url-Scheme \$scheme;
proxy_set_header X-Host \$http_host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header Proxy-host \$proxy_host;
client_max_body_size 400m;
client_body_buffer_size 128k;
proxy_buffering off;
proxy_connect_timeout 7200;
proxy_send_timeout 7200;
proxy_read_timeout 7200;
proxy_buffers 8 32k;
EOF
#nohup方式开启rhodecode
sudo sed -i -e "s/^nohup paster serve.*//g" /etc/rc.loca
sudo echo "nohup paster serve /home/hui/rhodecode1/production.ini >> /var/log/nginx/rhodecode.log &" >> /etc/rc.local
sudo sed -i -e "s/exit 0//g" /etc/rc.local
/etc/rc.local
#开启Nginx
sudo /etc/init.d/nginx restart
请使用浏览器登录进行测试:
please use web browser to test:
url: http://$WEB_SERVER_NAME/