简体   繁体   English

关于在亚马逊云ec2上设置git的虚拟问题

[英]Dummy questions about setting up git on amazon cloud ec2

first of all, apologize for dummy questions that I might throw here. 首先,为我可能会抛出的虚假问题道歉。 It would be nice if you could point the directions where should I go from here. 如果你能指出我应该从哪里开始的指示,那将是很好的。

I'm totally new to version control(as well as git) and cloud system. 我完全不熟悉版本控制(以及git)和云系统。 However, it came to the point that I have to develop php web based application on AWS EC2 instance and make codes contributable for future developers. 但是,我必须在AWS EC2实例上开发基于php web的应用程序,并使代码对未来的开发人员有所贡献。

I did successfully create EC2 instance that run PHP/MySQL and map the domain with Elastic IP. 我成功创建了运行PHP / MySQL的EC2实例,并使用弹性IP映射域。 So the website is now publicly accessible via port 80. 因此,该网站现在可通过端口80公开访问。

I also installed git using $sudo yum install git and configed user.name and user.email 我还使用$sudo yum install git和configed user.name和user.email $sudo yum install git

I then, go to root folder of the website (eg public_html) and run ' git init ' which create the fold “.git” and I then add file using “ git add . 然后,我去网站的根文件夹(例如public_html)并运行' git init '创建折叠“.git”,然后我使用“ git add . ”添加文件git add . ” and commit “ git commit -m 'initial upload' “并提交” git commit -m 'initial upload'

Is that the right way to go? 这是正确的方法吗? Would it be ok to have the project folder sitting on /public_html (where accessible from anyone). 是否可以将项目文件夹放在/ public_html(可从任何人访问)。

If above is ok, then where should I go from here? 如果上面没问题,那么我应该从哪里开始呢? I would like to have git server running on EC2 that allow developers to connect from their local machines (eg Eclipse) while being able to keep the backup and compare the different between codes. 我想在EC2上运行git服务器,允许开发人员从他们的本地机器(例如Eclipse)连接,同时能够保持备份并比较代码之间的不同。

What detail do I suppose to give developers so that they can connect to git server and working on project? 我想给开发人员什么细节,以便他们可以连接到git服务器并处理项目?

I quick direction or few keywords to do more research would help. 我快速指导或几个关键词做更多的研究会有所帮助。

look here for more information on setting up git on amazon ec2 在这里查看有关在amazon ec2上设置git的更多信息

to allow developers to use you git, you just need to give them the git server url. 允许开发人员使用你的git,你只需要给他们git服务器的URL。

Direct quote from the site i'm linking to. 直接引用我链接到的网站。

"First and foremost, you need to add your EC2 identity to the ssh authentication agent. This prevents problems with git later, namely getting the error “Permission denied (publickey).” when trying to do a git push to the EC2 repository. “首先,您需要将您的EC2身份添加到ssh身份验证代理。这可以防止以后出现git问题,即在尝试向EC2存储库执行git推送时获取错误”Permission denied(publickey)。“。

 ssh-add path/to/privateEC2key.pem 

Now you can go ahead and create the git repository on the EC2 instance. 现在,您可以继续在EC2实例上创建git存储库。

 ssh username@hostname.com mkdir the_project.git cd the_project.git git init --bare 

So not much going on here, all we do is create an empty repository and then leave. 所以在这里进行的不多,我们所做的只是创建一个空的存储库,然后离开。 Now, on the local machine, you do something like the following: 现在,在本地计算机上,您执行以下操作:

 cd the_project git init git add . git commit -m "Initial git commit message" git remote add origin username@hostname.com:the_project.git git config --global remote.origin.receivepack "git receive-pack" git push origin master 

The 'git config' command is a fix that I found necessary to be able to push to the EC2 repository." 'git config'命令是我发现必须能够推送到EC2存储库的修复。“

The mentioned link by Alex gives a good starting point to setup git on ec2. Alex提到的链接为在ec2上设置git提供了一个很好的起点。 But I followed a little different approach as mentioned here. 但我遵循了这里提到的一种不同的方法。 link . 链接 Direct Quotes from the page: 从页面直接引用:

"Connecting with SSH without a PEM key" : So either you add the ec2 private key and add it as a entity in your ssh authentication agent or create a new ssh key for your user and use that. “使用没有PEM密钥的SSH连接”:所以要么添加ec2私钥并将其作为实体添加到ssh身份验证代理中,要么为您的用户创建一个新的ssh密钥并使用它。 Steps to be followed are: 要遵循的步骤是:

Create SSH Key 创建SSH密钥

First up you will need to navigate to your .ssh folder on your local machine : 首先,您需要导航到本地计算机上的.ssh文件夹:

cd
cd .ssh

if this folder doesn't exist use mkdir to make it. 如果此文件夹不存在,请使用mkdir进行创建。

Once in your ssh folder on your local machine which should be in /Users/yourusername/.ssh generate your key by executing the following. 进入本地计算机上的ssh文件夹后,应该在/Users/yourusername/.ssh中执行以下操作生成密钥。

ssh-keygen -t rsa -b 1024

When prompted enter the file name to save the key enter id_rsa_aws, when prompted to enter a password leave blank. 当提示输入文件名保存密钥时输入id_rsa_aws,当提示输入密码时留空。

In your .ssh directory execute the following command and copy the output to paste later. 在.ssh目录中,执行以下命令并将输出复制到以后粘贴。

cat id_rsa_aws.pub

Now connect to you AWS instance using you PEM key 现在使用您的PEM密钥连接到您的AWS实例

ssh -i path/to/yourkeyname.pem ubuntu@xx.xxx.xxx.xxx

Once in 曾在

echo 'the key you copied from id_rsa_aws.pub' >> .ssh/authorized_keys
chmod 640 .ssh/authorized_keys
chmod 750 .ssh

Now you go to your machine and type 现在你去你的机器并输入

cd desired directory
git clone ubuntu@xx.xxx.xxx.xxx:<path_to_your_just_created_git_server>

If you did all the above mentioned steps correct, the only warning you might get is 如果您执行了上述所有步骤,那么您可能会收到的唯一警告就是

warning: You appear to have cloned an empty repository.

That's ok. 没关系。 Now you can copy all your code into the clone directory, and follow the following steps: 现在,您可以将所有代码复制到克隆目录中,并按照以下步骤操作:

git add . 
git commit -m "Initial commit"
git push origin master // If working on master branch

i created a GitHub gist with all the details hope it helps https://gist.github.com/eslam-mahmoud/35777e4382599438023abefc9786a382 我创建了一个GitHub的要点,所有细节都希望它有所帮助https://gist.github.com/eslam-mahmoud/35777e4382599438023abefc9786a382

//add your EC2 .pem file to ssh kys
ssh-add ~/aws/mypemfile.pem 

//create bare repo on AWS EC2 webserver and deploy on demand
mkdir ~/git/the_project 
cd ~/git/the_project
git init --bare

//create local repo and track remote one
cd ~/git/the_project 
git init
git add . 
git commit -m "Initial git commit message" 
git remote add aws ubuntu@1.1.1.1:~/git/the_project 
git config --global remote.origin.receivepack "git receive-pack" 
git push aws master
//create tag
git tag -a v0.1 -m "my version 0.1"
//push tags
git push aws --tags

//Or you have one so you push your updates 
git remote add aws ubuntu@1.1.1.1:~/git/the_project 
git config --global remote.origin.receivepack "git receive-pack" 
git push aws master
//create tag
git tag -a v0.1 -m "my version 0.1"
//push tags
git push aws --tags

//on server create another local repo that track the bare one to deploy
git clone ~/git/the_project
cd ./the_project
//checkout tag
git checkout v0.1
//install clear cache ...
npm install

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM