LinuxLinux服务器(centos7)环境搭建java/python3/nginx

Posted 莫问今朝

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LinuxLinux服务器(centos7)环境搭建java/python3/nginx相关的知识,希望对你有一定的参考价值。

1. 用的服务器是阿里云服务器,系统是CentOS7,远程连接工具是 Xshell 和 Xftp

2. 搭建java环境,我用的是jdk1.8

  需要 jdk-8u181-linux-x64.tar.gz,在自己电脑上下载,然后用Xftp传到服务器上,保存在usr/local文件夹下,解压。我试过用wget下载,不知道为什么解压的时候提示文件损坏。

cd usr/local
tar -zxvf jdk-8u181-linux-x64.tar.gz

  添加环境变量

vim /etc/profile

  在文件末尾添加,然后保存,退出文件编辑

export JAVA_HOME=/usr/local/jdk1.8.0_181
export JRE_HOME=/usr/local/jdk1.8.0_181/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

  让新加的环境变量生效,然后检查java安装是否成功。

[root@iZwz94jyld0skyrwc1772eZ local]# source /etc/profile
[root@iZwz94jyld0skyrwc1772eZ local]# java -version
java version "1.8.0_181"

3. 安装python3

  下载python3.7.0、解压、安装, 需要一点时间

cd /usr/local
wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz
tar -xvJf Python-3.7.0.tar.xz
cd Python-3.7.0
./configure --prefix=/usr/local/python3
make && make install

  发现执行完后有个问题

zipimport.ZipImportError: can\'t decompress data; zlib not available
make: *** [install] Error 1

  百度了一下缺少zlib依赖包,安装一下

yum -y install zlib*

  然后回到python3目录下,重新安装

cd /usr/local/Python-3.7.0
make && make install

  又发现另外一个错误

ModuleNotFoundError: No module named \'_ctypes\'
make: *** [install] Error 1

  安装libffi-devel, 再回到python3安装目录下重新安装, 终于OJBK

yum -y install libffi-devel
cd /usr/local/Python-3.7.0
make && make install

  创建软连接

ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

  检查是否安装成功

[root@iZwz94jyld0skyrwc1772eZ Python-3.7.0]# python3 -V
Python 3.7.0
[root@iZwz94jyld0skyrwc1772eZ Python-3.7.0]# python3
Python 3.7.0 (default, Aug 29 2018, 19:16:43) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> ^Z
[2]+  Stopped                 python3
[root@iZwz94jyld0skyrwc1772eZ Python-3.7.0]# 
[root@iZwz94jyld0skyrwc1772eZ Python-3.7.0]# python
Python 2.7.5 (default, Aug  4 2017, 00:39:18) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 
[3]+  Stopped                 python
[root@iZwz94jyld0skyrwc1772eZ Python-3.7.0]# pip3 install numpy
Looking in indexes: http://mirrors.aliyun.com/pypi/simple/
Collecting numpy
  Downloading http://mirrors.aliyun.com/pypi/packages/1a/2e/4e298c92b1fced64a4414ada9af3253a91083b92b131c2b10c057c507982/numpy-1.15.1-cp37-cp37m-manylinux1_x86_64.whl (13.8MB)
    100% |████████████████████████████████| 13.9MB 5.1MB/s 
Installing collected packages: numpy
Successfully installed numpy-1.15.1
You are using pip version 10.0.1, however version 18.0 is available.
You should consider upgrading via the \'pip install --upgrade pip\' command.

  升级pip3并检查

[root@iZwz94jyld0skyrwc1772eZ Python-3.7.0]# pip3 install --upgrade pip
Looking in indexes: http://mirrors.aliyun.com/pypi/simple/
Collecting pip
  Downloading http://mirrors.aliyun.com/pypi/packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/pip-18.0-py2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 55.1MB/s 
Installing collected packages: pip
  Found existing installation: pip 10.0.1
    Uninstalling pip-10.0.1:
      Successfully uninstalled pip-10.0.1
Successfully installed pip-18.0
[root@iZwz94jyld0skyrwc1772eZ Python-3.7.0]# pip3 -V
pip 18.0 from /usr/local/python3/lib/python3.7/site-packages/pip (python 3.7)
[root@iZwz94jyld0skyrwc1772eZ Python-3.7.0]# 

5. 删除java和python3的安装包

[root@iZwz94jyld0skyrwc1772eZ local]# rm jdk-8u181-linux-x64.tar.gz
rm: remove regular file ‘jdk-8u181-linux-x64.tar.gz’? yes
[root@iZwz94jyld0skyrwc1772eZ local]# rm Python-3.7.0.tar.xz
rm: remove regular file ‘Python-3.7.0.tar.xz’? yes

6. 安装nginx

  看nginx官网安装导航:http://nginx.org/en/linux_packages.html#stable

 

  需要先创建一个/etc/yum.repos.d/nginx.repo文件

touch /etc/yum.repos.d/nginx.repo
vim /etc/yum.repos.d/nginx.repo

  在vim编辑界面把下面这几行加进去(xshell可以直接复制粘贴), 保存。

  要注意的是

  baseurl=http://nginx.org/packages/centos/7/$basearch/
 这一行要把 centos 和 7 改成自己的操作系统和版本
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1

  然后

wget http://nginx.org/keys/nginx_signing.key
sudo rpm --import nginx_signing.key
yum update
cd /usr/local
yum install nginx

  启动nginx, 并查看是否有这个进程

[root@iZwz94jyld0skyrwc1772eZ local]# nginx
[root@iZwz94jyld0skyrwc1772eZ local]# ps -ef|grep nginx
root     17442     1  0 20:19 ?        00:00:00 nginx: master process nginx
nginx    17443 17442  0 20:19 ?        00:00:00 nginx: worker process
root     17456  1105  0 20:20 pts/0    00:00:00 grep --color=auto nginx

  nginx默认的端口号是80,去阿里云控制台开放这个端口

  

浏览器输入服务器的ip,出现 welcome to nginx 表示nginx启动成功

 

 

  

 

以上是关于LinuxLinux服务器(centos7)环境搭建java/python3/nginx的主要内容,如果未能解决你的问题,请参考以下文章

LinuxLinux上安装Nginx

LinuxLinux修改openfiles后不生效问题?

linuxlinux下java环境安装

LVS+Keepalived搭建高可用负载均衡

Centos7下Django开发环境搭建

CentOS7 Nvidia Docker环境