Configure the Go server

Source: Internet
Author: User
Tags configuration settings vps pscp scp command secure copy
This is a creation in Article, where the information may have evolved or changed.

For the server, it is a bit of a hassle to configure the servers to deploy the project to the service side. Here because of the use of foreign cloud server reasons, so not like the general configuration of the server so smooth, and even the difference is relatively large. The CentOS7.2 version of the VPS is used here.

In Pycharm, when you add a deployed server through tools->deployment->configuration, it simply doesn't work if you simply use the IP address of a VPS that you just configured from the cloud server, From using putty to login to the VPS you can understand that for security reasons, it is impossible to access the VPS casually. Therefore, the service side needs to be configured.

In CentOS, you already have Python installed, you can connect via putty, and then view the version via PYTHON-V (note that this is the uppercase V), so you can use Pip to install the Python-related package. However, installing the CentOS package requires the use of yum,dpkg,rpm.

To see if a package is installed through Yum, you can use the Yum list installed, or yum list installed | grep "Software name" view.

To see if a package has been installed via RPM, you can use Rpm-qa | "Software name" view. In practice, for example rpm-q httpd, you can query whether HTTPD is already installed.

See if the Deb package is installed and can be Dpkg-l | grep "Software Name"

If it is compiled and installed by the source package itself, such as. tar.gz, you can only see if the executable file exists.

Executable files installed with the root user are usually/sbin or/usr/bin.


You can find a program by using the Find/-name file name in Centos,ubuntu. It is important to note that Linux does not install Apache by default, and here, my CentOS does not have Apache installed, so I need to install Apache on my own. Note that the Apache Foundation has now renamed Apache Web server as httpd, so it was installed with yum-y install httpd. It is important to note that the use of Find/-name httpd.conf in CentOS can be found in the configuration file, the path is generally/etc/httpd/conf/ Httpd.conf, while the httpd.conf file is not found in Ubuntu at all, it needs to use Find/-name apache2.conf lookup, the general path under the/etc/apache2/apache2.conf path. Finally, most importantly, it is important to note that the VirtualHost configuration is not found under the configuration folder, in fact, this is because the configuration is placed in the/etc/apache2/sites-enabled/000-default folder.

In addition, if it is in CentOS, you can use Find-name ' httpd ' to see where the httpd is installed. It is also important to note that under Apache, the Web file placement path under/VAR/WWW, which can be seen in httpd.conf or apache2.conf.

It is important to note that some frameworks come with test servers, such as Bottle,flask, which are all with test servers, but are not recommended for use. So you still have to use httpd, and the most troublesome part of httpd is the need to configure. It's a good idea to use Find/-name ' httpd ' before you start to see what directories the httpd is installed in, and then do a little bit more secure.


For some VPS merchants, you can select the installed server directly, for example, here my VPS choose to install lamp when installed. Of course there are many other, such as Docker,django, etc. can be selected.


The most important thing to note here is that Apache has asked us to provide a good guide, after the installation of Apache, the input IP address can see the boot page, IP address/info.php can see some of the required information, and actually enter the IP address to see the/var/www /html/index.html file, and in fact, the info.php,index.html file is under the/var/www/html path, and/var/www is the placement path of the Web file. In addition, for some do not understand the problem can be viewed on the Apache official website.

To put it simply, when you first start doing Apache, you need to look at the index.html page before you know how to do the Apache configuration. And info.php inside is the information we generally need, such as the location of some configuration files.

In fact, as long as the search for each system Apache how to build it, generally have a very detailed configuration, such as search Ubuntu under Apache2 Web project deployment.


You can use the cmd command's Telnet IP port method to see if the IP port is closed. In general, if it is not closed, then the background becomes black, or give some other hints.

In addition, the firewall in CentOS uses iptables, and Ubuntu does not, but you can use the UFW command, UFW is actually Ubuntu fire wall shorthand. In general, if you want to be familiar with the system firewall, you can directly search for a system firewall, such as search: CentOS firewall, Ubuntu firewall.

Firewalls may listen to ports that cause ports to be inaccessible, so firewalls are also important. For uploading items to the server, you need to open ports, and ports generally have their own role, so open ports need to be aware.



To implement uploads using putty, you need to be aware that you need to download the. zip format, because the. exe encapsulates the following tools. Open the Putty folder, which will be like pscp.exe,psftp.exe these tools, they can be used to transfer files, the role with the SCP command in Putty Upload project is similar, here SCP is the meaning of secure copy. It is important to note that SCP is useful for transferring data between Linux, and if you are transferring data between Windows to Linux, you need to use Pscp.exe, but pscp.exe can only transfer individual files, and if you need to transfer items, you need to use Psftp.exe. In addition, for the server-side folder needs to set Chmod-r 777/var/www set Read and write permissions, otherwise the transfer will fail.


For transferring files using psftp, use CMD to navigate to the path of Psftp.exe, where you can use psftp-h to see which parameters are available for selection. And then:

1, if there is no SSH key file, direct input psftp, if so, enter the Psftp-i key path. If you need to specify a port, you can bring the-p port number. A password is required to bring the-PW password.

2, fill in the Key account number and password, if the account is a VPS, is generally root.

3, after the successful landing, the current directory is/root, that is, we use the Putty login ~ path, you can use the CD command to transfer the path. If you are unfamiliar with the commands you need to use, you can enter the Help view command.

4. Use LCD to switch local path.

5, use put upload, use get download. But using Put,get can only manipulate a single file

6. Use mget,mput upload to download multiple files.

7. After entering psftp, you can see the usage of the command after entering help.



The upload project can be set up by tools->deployment->configuration, such as Pycharm, to implement a session through the Tools->start SSH session. However, it is important to note that if SSH key is present, the settings should consider importing the SSH key file, otherwise the access will be rejected. In addition tools->deployment->configuration settings, for the choice of protocol need attention, generally choose SFTP, then auth type select key pair (Open ssh or puTTy), and then import SSH Key file, you need to pay special attention here, the use of Putty exported SSH key file will be error, so if the SSH key file has been generated, then you need to use Puttygen import this SSH key file, and then click the Conversions menu button, Choose to export the open SSH file, note that the open SSH file and the ssh file are the same PPK suffix. In fact, if we are using SSH key file, Pycharm will give a hint, the need to open SSH format ssh key file, and then configure it OK. In addition, if you need to determine whether the connection is connected, you can click Test SFTP Connection under Tools->deployment->configuration.

Then Tools->deployment->browse remote host, you can see the connection on the remote server path under the directory, of course, if there is no directory, do not because there is no directory to think of failure.

This can be downloaded via the Tools->deployment menu, or through the remote host interface Tools->deployment->browse remote host. Also, you need to be aware that you need to click on the item that needs to be uploaded in Pycharm, and then the upload Download Action menu item will be displayed tools->deployment, so if you click on the remote host interface, open the tools-> Deployment, you will find that the upload download Operation menu item is not operational, so this needs attention!

For tools->deployment->automatic upload automatic upload function, need to use caution, because automatically upload, will make remote code editing and local code editing, so personal preference to manually upload the download, so that no error.

For the operation of the project, if you need to use remote debugging, then you need to select Add remote in the Settings->project: project name->project interpreter in the upper right corner, then choose SSH from the interface. Credentials, configure it, click OK, and select Project interpreter as him so you can debug remotely. In this process, pycharm uploads local data to the server for remote debugging, where The most important thing is to upload the local pycharm-debug.egg, of course, this can also be directly on the server using command installation, after all, local installation is time-consuming, this thing is mainly for debugging purposes. And of course there's something else to upload. Wait until the upload pycharm helpers complete, although it may be a bit slow, after the download will need to do some such as account password settings. Also, you need to download something locally when you're done. In addition, the Python console connects to the remote Python command line and uses the Python console installed on the server side.

Use the Putty command to get the server to compile the Go project. Note here that the file that appears after using go build has no suffix, and then the Go Run command will stay, which is the same as under Windows, which is already running.

Unlike Apache, the port of the Go project needs to be opened on its own, not directly configured like Apache. You can use Netstat-a to view network status, but it is strange that 80 and 222 ports can be connected, but it is not shown, it is estimated that SSH and Apache are configured for the reason. In addition, it is necessary to pay special attention to the Iptables port is allowed to be connected only, and can not open the opening port, and if the need to operate iptables, you need to follow the iptables rules, using iptables--h can be viewed, the operation of the Internet is basically not used. Finally, use iptables-i input-p tcp--dport 8080-j ACCEPT, then use Iptables-l-N to see that 8080 ports are actually allowed, but using the Telnet command on Windows does not. It should be said that the need for such a process, in general, a newly installed CentOS system will have 22 ports, through this port we can upload downloads, and even operate a lot of things, and then use Iptables can allow a port to be used, then we upload the project through 22 port, Open the desired port through the project. Of course, you can open a port like 80 directly by installing software such as Apache.

It is also important to note that Ubuntu allows access to ports that need to take into account iptables and UFW two places.


The use of nmap this very useful sniffer tool will be more effective, install Nmap in Ubuntu, only need to use nmap localhost to view their local open port. This is more than using Netstat-tanpu | grep "8080" is so much more efficient to find. At the same time, using Nmap will also help you print out which program opens this port. Of course, you can also use Netstat-a to view network usage, including ports.


Open port in fact, when using the Go run xxx.go file, the go built-in server has opened the corresponding port according to the code configuration, and IPTABLES,UFW these just play a permitted access to the role, not to open the port. Note here, do not think in the Web page to open their own configured website address after the success of the port did not open to the success, the opening opened successfully, to use the Telnet command. This means go run xxx.go and then use the Telnet command to view it. PS: It is not possible to use Nmap in putty at this time, because the Go run xxx.go command will block you from entering commands.


In general, if it is a generic use, then use the go built-in server is enough, but for large web projects, or with the server used better.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.