Linux Server Python production environment Configuration

Source: Internet
Author: User

Linux Server Python production environment Configuration

We often repeat some tutorials during Linux O & M configuration, so we plan to build some knowledge at the O & M level. First, make some simple sorting, and then continue to update as needed.

This document describes the configuration process and precautions for the Python production environment on the Debian Linux server.

Initialize the operating system: Debian Linux1. modify the root user password.

For a newly installed Debian system, you should first modify its root user password. Use the root user to log on to the remote host.

ssh root@xxx.xxx.xxx.xxx

At this time, the command line prompts a warning, indicating that this is a new address and there is a security risk. Type yes to accept. Then, you can successfully log on to the remote host.

Next, modify the password of the root user.

passwd
2. Create a user

First, add a user group (this is assumed to be the admin user group ).

addgroup admin

Then, add a new user (assuming foo ).

useradd -d /home/foo -s /bin/bash -m foo 

In the preceding command, the parameter d specifies the user's home directory, and the parameter s specifies the user's shell. The Parameter m indicates that if the directory does not exist, the directory is created.

Next, set the password for the new user.

passwd foo 

Add the new user (foo) to the user group (admin ).

usermod -a -G admin foo 

The Debian system does not have sudo by default, so you need to install sudo first.

apt-get install sudo

Next, set sudo permissions for the new user.

visudo 

The cmddo command will open the sudo setting file/etc/sudoers and find the following line.

root    ALL=(ALL:ALL) ALL

Add another row under this row.

root    ALL=(ALL:ALL) ALLfoo    ALL=(ALL) NOPASSWD: ALL

The above NOPASSWD indicates that you do not need to enter a password when switching to sudo. It is easier for me to do so. For security reasons, you can also force a password.

root    ALL=(ALL:ALL) ALLfoo    ALL=(ALL:ALL) ALL

Then, log out of the root user and log in as a new user. Check whether everything is normal until this step ends.

exitssh foo@xxx.xxx.xxx.xxx
3. SSH settings

First, make sure that the local machine has an SSH Public Key (usually a file~/.ssh/id_rsa.pub), If not, use the ssh-keygen command to generate one (refer to the SSH tutorial I wrote ).

Open another shell window on the local machine to copy the Local Public Key to the authorized_keys file on the server.

Cat ~ /. Ssh/id_rsa.pub | ssh foo@xxx.xxx.xxx.xxx 'mkdir-p. ssh & cat-> ~ /. Ssh/authorized_keys '# or on the server side, run the following command echo "ssh-rsa [your public key]"> ~ /. Ssh/authorized_keys

Then, go to the server and edit the SSH configuration file./etc/ssh/sshd_config.

sudo cp /etc/ssh/sshd_config ~sudo nano /etc/ssh/sshd_config

In the configuration file, change the default SSH port 22 to any integer from 1025 to 65536 (this is assumed to be 25000 ).

Port 25000

Then, check whether the settings are set as follows to ensure that the # above is removed.

Protocol 2PermitRootLogin noPermitEmptyPasswords noPasswordAuthentication noRSAAuthentication yesPubkeyAuthentication yesAuthorizedKeysFile .ssh/authorized_keysUseDNS no

In the preceding section, root user logon is disabled and Password Logon is disabled.
Next, at the end of the configuration file, specify the user that is allowed to log on.

AllowUsers bill

Save and exit file editing.
Then, change the permissions of the authorized_keys file.

sudo chmod 600 ~/.ssh/authorized_keys && chmod 700 ~/.ssh/

Then, Restart SSHD.

Sudo service ssh restart # or sudo/etc/init. d/ssh restart

The following steps are optional. On the local machine ~ /. Create the config file in the ssh folder. The content is as follows.

Host s1HostName xxx.xxx.xxx.xxxUser fooPort 25000

Finally, open a shell window on the local machine to test whether SSH can log on smoothly.

ssh s1
4. Running Environment Configuration

First, check the region settings of the server.

locale

If the result is noten_US.UTF-8, We recommend that you set it.

sudo locale-gen en_US en_US.UTF-8 en_CA.UTF-8sudo dpkg-reconfigure locales

Then, update the software.

sudo apt-get updatesudo apt-get upgrade

Finally, make some security settings as needed, such as building a firewall, closing ports other than HTTP, HTTPs, and SSH, and installing Fail2Ban, for details, refer to Securing a Linux Server.

Install common software installation packages
sudo apt-get install curl git
Install VIM
Sudo apt-get install vim # download configuration curl https://gist.githubusercontent.com/fengluo/3749890/raw> ~ /. Vimrc

We use Vundle to manage and install the VIM plug-in.

git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim

After installation, you can enable vim to run

:PluginInstall

You can also install the configuration directly from the command line.

vim +PluginInstall +qall
Deploy the Python Environment
Sudo apt-get install python-pip python-dev build-essential # update pipsudo pip install -- upgrade pip
Install virtualenv

Virtualenv helps us create an isolated python environment. Each python application should use an independent python environment to prevent mutual interference.

sudo pip install virtualenv
Install supervisor

Supervisor is a powerful process management tool that helps users monitor and control system processes.

Pip install supervisor # If no configuration is written, use the following command to generate a configuration echo_supervisord_conf>/etc/supervisord. conf
Install MySQL
sudo apt-get install mysql-serversudo apt-get install libmysqlclient-dev
Install Nginx
sudo apt-get install nginx

-------------------------------------- Split line --------------------------------------

Deployment of Nginx + MySQL + PHP in CentOS 6.2

Build a WEB server using Nginx

Build a Web server based on Linux6.3 + Nginx1.2 + PHP5 + MySQL5.5

Performance Tuning for Nginx in CentOS 6.3

Configure Nginx to load the ngx_pagespeed module in CentOS 6.3

Install and configure Nginx + Pcre + php-fpm in CentOS 6.4

Nginx installation and configuration instructions

Nginx log filtering using ngx_log_if does not record specific logs

-------------------------------------- Split line --------------------------------------

This article permanently updates the link address:

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.