阿里云服务器 怎么用git部署代码

阿里云服务器 怎么用git部署代码,第1张

使用阿里云Ubuntu 12.0.4 64位 *** 作系统做git服务器。

首先git服务器有两种访问方式可以选择:http方式和ssh的方式,http方式更容易使用。

1、http方式的git服务器搭建以及使用git命令行访问:

On the Server

1) Install Ubuntu Server, this is the base of our git server obviously

2) Now we need to install a couple of packages, these being ‘git-core’ and ‘apache2′, we do this like so:-

apt-get update

apt-get install apache2 git-core

3) Now we need to create a new folder for your new repository and set some inital permissons, we do this like so:-

cd /var/www

mkdir test-repo.git

cd test-repo.git

git --bare init

git update-server-info

chown -R www-data.www-data .

4) We now need to enable WebDAV on Apache2 of which we will use to serve the repository:-

a2enmod dav_fs

5) We now need to configure the access restrictions to our repository by creating the following file:-

/etc/apache2/conf.d/git.conf

Then fill it in with the following content:-

<Location /test-repo.git>

DAV on

AuthType Basic

AuthName "Git"

AuthUserFile /etc/apache2/passwd.git

Require valid-user

</Location>

Then save and close the file, lets move on to the next bit..

6) Next we need to create a user account of which you will need to use to browse of commit to the repository..

htpasswd -c /etc/apache2/passwd.git <user>

You could then be prompted to enter the password for the user too and confirm it!

7) Ok that’s it for the server side configuration… we just need to restart Apache2 like so and then we should be ready to move on to the client side stuff!

/etc/init.d/apache2 restart

…you can now move on to the client side stuff!

On the client side

Ok so now we need to create a local (on your desktop machine) repository and then we’ll initiate the new remote repository… So, if your using Linux/MacOSX bring up the terminal and type the following commands:-

mkdir ~/Desktop/test-project

cd ~/Desktop/test-project

git init

git remote add origin http://<user>@<server name or IP address>/test-project.git

touch README

git add .

git commit -a -m “Initial import”

git push origin master

Done! – Your intiial file named ‘README’ which currently is just blank has now been committed and you’ve pushed your code to your new git server which has now completed the Git reposity creation process, now in future you can ‘clone’ your resposity like so:-

git clone <user>@<server name or IP address>/test-project.git

注意上面连接http://<user>@<server name or IP address>/test-project.git中的user就是你htpasswd -c /etc/apache2/passwd.git <user>输入的用户名。

另外新建仓库的时候,只需执行:

cd /var/www

mkdir 项目名

cd 项目名

git --bare init

git update-server-info

chown -R www-data.www-data .

然后在/etc/apache2/conf.d/git.conf中对应添加上面类似段即可。

其中:

AuthUserFile 密码文件名

后面的文件就是你指定的密码文件,你可以

htpasswd -c 密码文件名 <user>

对应指定该项目的用户名和密码即可。添加用户是不要-c参数:

htpasswd 密码文件名 <user>

小鸟云服务器niaoyun实例创建好之后,您可以使用以下任意一种方式登录服务器:

远程桌面连接(MicrosoftTerminalServicesClient,MSTSC):采用这种方式登录,请确保实例能访问公网。如果在创建实例时没有购买带宽,则不能使用远程桌面连接。

管理终端VNC:无论您在创建实例时是否购买了带宽,只要您本地有网页浏览器,都可以通过管理控制台的管理终端登录实例。

使用远程桌面连接(MSTSC)登录实例

打开开始菜单>远程桌面连接,或在开始菜单>搜索中输入mstsc。也可以使用快捷键Win+R来启动运行窗口,输入mstsc后回车启动远程桌面连接。

在远程桌面连接对话框中,输入实例的公网IP地址。单击显示选项。

输入用户名,如小鸟云默认为niaoyun。单击允许我保存凭据,然后单击连接。这样以后登录就不需要手动输入密码了。

前提条件

1. 为 Python 应用程序安装 virtualenv 和 virtualenv wrapper,目的在于为 Python 项目创建独立的环境。

● 安装 pip

sudo apt-get install python-pip

● 安装 virtualenv

sudo pip install virtualenv

● 创建目录以存储您的 virtualenv

mkdir ~/.virtualenvs

● 安装 virtualenwrapper

sudo pip install virtualenvwrapper

● 将 WORKON_HOME 设置为您的 virtualenv 目录

导出 WORKON_HOME=~/.virtualenvs

● 将 WORKON_HOME 设置为您的 virtualenv 目录

导出 WORKON_HOME=~/.virtualenvs

● 将 virtualenvwrapper.sh 添加到 .bashrc

将此行添加到 ~/.bashrc 的末尾,以便加载 virtualenvwrapper 命令。/usr/local/bin/virtualenvwrapper.sh

退出,然后重新打开您的 shell,或者使用 .bashrc or source ~/.bashrc 命令重新加载 .bashrc,然后一切准备就绪。

2. 安装 git。

apt-get install git

3. 安装 Nginx 作为 Web 服务器,这样您便可在其之后运行您的应用程序。

Sudo apt-get install nginx

启动您的第一个 Linux 实例

接下来向您介绍使用阿里云管理控制台运行 ECS 实例的相关步骤。

1. 登录到您的帐户,然后导航到“产品与服务”部分下的“云服务器”。单击侧边栏菜单中的概览。这会显示运行中的实例列表。单击购买实例从任意地域购买实例,或者继续到下一步创建新实例。

2. 单击侧边栏菜单中的实例。在实例列表中选择所需地域,然后单击右上方栏中的创建实例。

3. 系统会将您重新定向到“产品购买”控制台,在此您需要选择偏好的资源包 - 对 ECS 实例和数据传输提供特殊定价的初级资源包或提供两种定价模式的高级购买资源包。您可以根据自身需求选择订阅(按月或按年)或者按量付费。此案例中,我们选择了“按量付费”。

4. 在此窗口中,选择要在其中启动 ECS 实例的数据中心地域和可用性区域。如果选择了地域但未选择可用性区域,系统会将实例随机放在任何区域。

5. 现在您需要选择自己想要创建的实例类型。根据自身需求,从“生成”选项卡中选择生成实例类型。生成类型根据配置和所用的计算能力表示不同的实例类型。

6. 接下来,选择网络类型以启动您的 ECS 实例。可根据自身需求选择经典网络或专有网络。在经典网络中,阿里云以分布式方式分配 IP 地址。它适合于需要简单快速地使用 ECS 的用户。专有网络更多的是一种逻辑隔离私有网络,它支持专用连接。它适合于熟悉网络管理的用户。选择适当的网络类型后,选择网络计费类型:数据传输或固定带宽。在这两种情况下,您都需要设置网络带宽峰值(最大数据传输速率)。

7. 现在,您需要选择 *** 作系统。每个选项下都提供了不同 *** 作系统版本的列表。选择 Ubuntu。

8. 根据自身需要,从下拉菜单中选择系统磁盘类型。您还可以通过单击“添加磁盘”向此列表添加更多磁盘。

9. 在“安全设置”部分中,您可以创建密码以提高安全性,或者在此阶段跳过此步骤并稍后从管理控制台执行此 *** 作。

10. 在“采购计划”部分中,键入您的实例名称并设置要启动的实例的数量。

11. 在“概览”部分查看配置详情和总价,然后单击立即购买。

12. 单击开通确认业务订单并启动实例。

13. 启动实例后,您可以在控制台的实例选项卡中查看该实例。

安装和部署 Django 应用程序

您已使用阿里云管理控制台创建和启动 ECS 实例,接下来让我们了解如何安装和部署 Django 应用程序。

1. 使用 ssh 命令登录到您的服务器

2. 输入密码

3. 通过创建一个新的 virtualenv 为部署 Django 应用程序设置环境:

mkvirtualenv DjangoApp

要退出新的 virtualenv,请使用 deactivate。

您可以使用 workon 在环境之间切换。要加载或在 virtualenv 之间切换,请使用 workon 命令:workon DjangoApp

4. 在您的当前环境中安装 Django

pip install Django

5. 使用 django-admin 命令创建样本项目并将目录更改为项目文件夹。

django-admin startproject todoApp

cd todoApp/

6. 迁移或引导您的数据库。

python manage.py migrate

7. 创建超级用户以访问管理面板。

python manage.py createsuperuser

8. 设置用户后,通过运行由 manage.py *** 作的 runserver 命令测试您的应用程序

python manage.py runserver 0.0.0.0:8000

您将看到以下内容在端口 8000 上运行

转至 /admin,这是您的管理面板,您可在此管理应用程序。

现在使用 Nginx 将您的应用程序置于 Web 服务器之后。

9. 创建数据库架构 开通 python 环境。

● 将目录更改为 Django 项目目录

● 运行以下命令

python manage.py migrate

10. 收集所有静态文件(css、js 等)

● 运行以下命令以在任意特定位置收集所有静态文件

Python manage.py collectstatic --noinput

● 开发人员负责将 STATIC_URL 路径设置为将收集所有静态文件的位置。

● 这些变量在项目目录内的 setting.py 中定义。

1. STATIC_URL

2. STATICFILES_DIRS

3. STATIC_ROOT

11. 使用 uwsgi 服务器安装 uwsgi 库并启动服务器。

pip install uWSGI

● 创建用于部署 Django 应用程序的 ini 文件vim uwsgi.ini

● 将其保存到应用程序目录上的 uwsgi.ini。如需进一步了解如何编写 ini 文件,请参阅 Python/WSGI 应用程序快速入门。运行此命令以启动您的应用程序。

uwsgi uwsgi.ini (您的 ini 文件)

12. 更改 nginx 配置文件以用于应用程序。

server   {       listen 80 default_server        listen [::]:80 default_server ipv6only=on        server_name localhost location /static/   {         include uwsgi_params        alias /root/todoApp/public/ }  location  /    {        include uwsgi_params       uwsgi_pass unix:/tmp/uwsgi.sock    } }

13. 重启 nginx,随后您的应用程序将启动并在端口 80 上的 nginx 之后运行。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11394424.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-15
下一篇2023-05-15

发表评论

登录后才能评论

评论列表(0条)

    保存