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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18439760/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 08:57:37  来源:igfitidea点击:

Dummy questions about setting up git on amazon cloud ec2

linuxeclipsegitamazon-ec2

提问by Chanon

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. 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.

我对版本控制(以及 git)和云系统完全陌生。但是,到了我必须在 AWS EC2 实例上开发基于 php Web 的应用程序并为未来的开发人员编写代码的地步。

I did successfully create EC2 instance that run PHP/MySQL and map the domain with Elastic IP. So the website is now publicly accessible via port 80.

我确实成功创建了运行 PHP/MySQL 的 EC2 实例并使用弹性 IP 映射域。因此,该网站现在可以通过端口 80 公开访问。

I also installed git using $sudo yum install gitand configed user.name and user.email

我还使用$sudo yum install git并配置了 user.name 和 user.email安装了 git

I then, go to root folder of the website (e.g. public_html) and run ‘git init' which create the fold “.git” and I then add file using “git add .” and commit “git commit -m ‘initial upload'

然后,我转到网站的根文件夹(例如 public_html)并运行 ' git init' 创建折叠“.git”,然后我使用“ git add .”添加文件并提交“ 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 (e.g. Eclipse) while being able to keep the backup and compare the different between codes.

如果以上没问题,那么我应该从哪里开始?我想让 git 服务器在 EC2 上运行,允许开发人员从他们的本地机器(例如 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.

我快速的方向或几个关键字做更多的研究会有所帮助。

回答by VisualBean

look herefor 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.

ssh-add path/to/privateEC2key.pem

Now you can go ahead and create the git repository on the EC2 instance.

ssh [email protected] 
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 [email protected]: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."

“首先,您需要将您的 EC2 身份添加到 ssh 身份验证代理。这可以防止 git 出现问题,即出现“权限被拒绝(公钥)”错误。尝试对 EC2 存储库执行 git push 时。

ssh-add path/to/privateEC2key.pem

现在您可以继续在 EC2 实例上创建 git 存储库。

ssh [email protected] 
mkdir the_project.git 
cd the_project.git 
git init --bare

所以这里没有太多事情要做,我们所做的就是创建一个空的存储库,然后离开。现在,在本地机器上,您执行以下操作:

cd the_project 
git init
git add . 
git commit -m "Initial git commit message" 
git remote add origin [email protected]:the_project.git 
git config --global remote.origin.receivepack "git receive-pack" 
git push origin master

'git config' 命令是一个修复程序,我发现它是能够推送到 EC2 存储库所必需的。”

回答by Anshul

The mentioned link by Alex gives a good starting point to setup git on ec2. But I followed a little different approach as mentioned here. link. Direct Quotes from the page:

Alex 提到的链接为在 ec2 上设置 git 提供了一个很好的起点。但是我遵循了此处提到的一些不同的方法。链接。从页面直接引用:

"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. Steps to be followed are:

“在没有 PEM 密钥的情况下使用 SSH 连接”:因此,您可以添加 ec2 私钥并将其作为实体添加到您的 ssh 身份验证代理中,或者为您的用户创建一个新的 ssh 密钥并使用它。要遵循的步骤是:

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 [email protected]

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 [email protected]:<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

回答by Eslam Mahmoud

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 [email protected]:~/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 [email protected]:~/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