美文网首页
【操作系统】Linux:重常用开发环境的安装部署

【操作系统】Linux:重常用开发环境的安装部署

作者: Share猿 | 来源:发表于2018-07-26 16:03 被阅读59次

    小猿“思前享后”为大家分享优质内容!————Share猿

    1.Nginx在Linux下的安装

    1.1.ubuntu环境下的安装配置

    1.1.1.Nginx的基本安装

    #1.Nginx的下载安装
      sudo apt-get update
      apt-get install nginx
    #2.Nginx的配置文件路径
      sudo vi /etc/nginx/nginx.conf
    #3.Nginx的启动和停止
      sudo service nginx start
      sudo service nginx stop
    

      ubuntu中安装Nginx相对来说比较简单,默认端口是80,在浏览器中输入ip:80即可访问。

    1.1.2.Nginx配置vhost

      所谓vhost说白了就是把多个应用映射到一个ip地址上,达到多对一的效果。

    #1.创建nginx虚拟主机配置文件 
      sudo vi /etc/nginx/sites-available/mydefault.vhost 
    #mydefault.vhost文件内容如下:
    #-----------------------------mydefault.vhost--------------------------------------#
    #用户端api接口转发
    server {
      listen       80;
      server_name  192.168.0.65;
      index index.html;
      
      location /uc {
        index index.html;
        client_max_body_size    5m;
        proxy_pass http://127.0.0.1:6001;
          proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
      }
      location /otc {
        index index.html;
        client_max_body_size    5m;
        proxy_pass http://127.0.0.1:6002;
          proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
      }
      location /exchange {
        index index.html;
        client_max_body_size    5m;
        proxy_pass http://127.0.0.1:6003;
          proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
      }
      location /market {
        index index.html;
        client_max_body_size    5m;
        proxy_pass http://127.0.0.1:6004;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header X-Real-IP $remote_addr;
      }
      location /chat {
        index index.html;
        client_max_body_size    5m;
        proxy_pass http://127.0.0.1:6007;
        proxy_set_header Host $host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header X-Real-IP $remote_addr;
      }
    }
    #后台api接口转发
    server {
      listen       80;
      server_name  api.admin.domain.com;
      index index.html;
      location / {
        index index.html;
        client_max_body_size    5m;
        proxy_pass http://127.0.0.1:6010;
        proxy_set_header Host $host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header X-Real-IP $remote_addr;
      }
    }
    #---------------------------mydefault.vhost----------------------------------#
    #2.建立一个mydefault.vhost文件的链接
    #(因为nginx的主配置文件nginx.conf会自动应用sites-enabled中的配置文件,所以我们需要在sites-enabled中建立一个mydefault.vhost文件的链接)
      cd /etc/nginx/sites-enabled
      sudo ln -s /etc/nginx/sites-available/mydefault.vhost mydefault.vhost
    #3.重新加载nginx使配置生效 
      sudo /etc/init.d/nginx reload
    

    1.2.centos环境下的安装配置

      centos7系统库中默认是没有nginx的rpm包的,所以我们自己需要先更新下rpm依赖库

    #1.使用yum安装nginx需要包括Nginx的库,安装Nginx的库
    rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
    #2.rpm包的安装:
    #2.1.安装一个包
      rpm -ivh
    #2.2.升级一个包,没安装过的不能使用升级命令
      rpm -Uvh
    #2.3.移走一个包
      rpm -e
    #3.安装准备依赖lib库
      yum install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
    #4.使用下面命令安装nginx
      yum install nginx
    #5.启动/重启/停止Nginx
      service nginx start 或 systemctl start nginx.service
      service nginx restart
      /etc/init.d/nginx stop
      /etc/init.d/nginx start
    

    2.kafka在Linux下的安装

    2.1.ubuntu环境下的安装配置

    2.1.1.Kafka的基本环境的安装

    ##Install and Start Apache Kafka Server : 0.0.0.0:9092
    #0: update and upgrade
      sudo apt-get update -y
    #1: home dir
      cd /home/imex
    #2: find new package @ www.apache.org
      http://mirror.bit.edu.cn/apache/kafka/1.0.1/kafka_2.11-1.0.1.tgz
    #3: download
      wget http://mirror.bit.edu.cn/apache/kafka/1.0.1/kafka_2.11-1.0.1.tgz
    #4: mkdir
      sudo mkdir /opt/Kafka
      cd /opt/Kafka
    #5: install
        sudo tar -xvf /home/imex/kafka_2.11-1.0.1.tgz -C /opt/Kafka/
    #6: start
      sudo  /opt/Kafka/kafka_2.11-1.0.1/bin/kafka-server-start.sh         
      /opt/Kafka/kafka_2.11-1.0.1/config/server.properties
    #7: to start the Kafka server as a background process:
      sudo nohup /opt/Kafka/kafka_2.11-1.0.1/bin/kafka-server-start.sh /opt/Kafka/kafka_2.11-1.0.1/config/server.properties /tmp/kafka.log 2>&1 &
    #check 
       netstat -ant | grep :9092
    #8: Testing Kafka Server
    #-- To test Kafka, create a sample topic with name "testing" in Apache Kafka using the following command:
      sudo /opt/Kafka/kafka_2.11-1.0.1/bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1  --partitions 1 --topic testing       
    #-- Now, ask Zookeeper to list available topics on Apache Kafka by running the following command:
      sudo /opt/Kafka/kafka_2.11-1.0.1/bin/kafka-topics.sh --list --zookeeper localhost:2181    
    #--Now, publish a sample messages to Apache Kafka topic called testing by using the following producer command:
      sudo /opt/Kafka/kafka_2.11-1.0.1/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic testing
    #--Now, use consumer command to check for messages on Apache Kafka Topic called testing by running the following command:
      sudo /opt/Kafka/kafka_2.11-1.0.1/bin/kafka-console-consumer.sh --    zookeeper localhost:2181 --topic testing --from-beginning
    

    2.1.2.Kafka的服务配置

    #1.创建服务文件
      cd /etc/systemd/system/
      sudo vi kafka.service
    #2.填充内容
    [Unit]
    Description=Redis In-Memory Data Store
    After=network.target
    
    [Service]
    Type=forking
    ExecStart= /opt/Kafka/kafka_2.12-1.1.0/bin/kafka-server-start.sh /opt/Kafka/kafka_2.12-1.1.0/config/server.properties
    ExecStop=/opt/Kafka/kafka_2.12-1.1.0/bin/kafka-server-stop.sh
    Restart=alwaiys
    PrivateTmp=true
    
    [Install]
    WantedBy=multi-user.target
    #3.启动、停止命令
      sudo systemctl start kafka.service
      sudo systemctl stop kafka.service
    

    2.1.3.Kafka常见问题解决

    1).Kafka自动关闭问题

      Kafka在启动一段时间后,如果出现服务自动关闭情况,可在启动kafka的时使用守护进程模式启动,即在原启动命令中加 -daemon。

    kafka-server-start.sh  -daemon  config/server.properties  &
    

    3.mysql在Linux下的安装

    3.1.ubuntu环境下的安装配置

    3.1.1.mysql的基本环境的安装

    #1.首先执行下面三条命令:
      sudo apt-get install mysql-server
      sudo apt isntall mysql-client
      sudo apt install libmysqlclient-dev
    #2.安装成功后可以通过下面的命令测试是否安装成功:
      sudo netstat -tap | grep mysql
    #3.现在设置mysql允许远程访问,首先编辑文件/etc/mysql/mysql.conf.d/mysqld.cnf:
      sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
      #注释掉bind-address = 127.0.0.1:
    #4.保存退出,然后进入mysql服务,执行授权命令:
      grant all on *.* to root@'%' identified by '你的密码' with grant option;
      flush privileges;
      #然后执行quit命令退出mysql服务,执行如下命令重启mysql:
      service mysql restart
    

    3.1.2.mysql的基本环境的卸载

    #1. 删除mysql
      a. sudo apt-get autoremove --purge mysql-server-5.0
      b. sudo apt-get remove mysql-server
      c. sudo apt-get autoremove mysql-server
      d. sudo apt-get remove mysql-common (非常重要)
    #2. 清理残留数据
      dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P
    

    3.zookeeper在Linux下的安装

    3.1.ubuntu环境下的安装配置

    3.1.1.zookeeper的基本环境的安装

    # 1.下载zookeeper
        wget http://apache.osuosl.org/zookeeper/stable/zookeeper-3.4.12.tar.gz
    # 2.解压到相关目录
       tar -xf zookeeper-3.4.12.tar.gz
    # 3.将zookeeper-3.4.3/conf目录下的zoo_sample.cfg文件拷贝一份,命名为为“zoo.cfg”
    # 4.修改zoo.cfg配置文件
        dataDir=/home/gradven/zookeeper-3.4.6/data # 数据存放位置,可根据需要修改
        clientPort=2181 # 服务监听端口,可根据需要修改。
    # 5.启动服务
       bin/zkServer.sh start
    # 6.启动客户端测试
      bin/zkCli.sh -server 127.0.0.1:2181
    #  显示根目录下、文件:
      ls /
    # 创建文件,并设置初始内容:
      [zk: 127.0.0.1:2181(CONNECTED) 1] create /treeroot hello
      Created /treeroot
      [zk: 127.0.0.1:2181(CONNECTED) 2] get /treeroot
      hello
      cZxid = 0x2
      ctime = Tue Oct 20 00:30:34 CST 2015
      mZxid = 0x2
      mtime = Tue Oct 20 00:30:34 CST 2015
      pZxid = 0x2
      cversion = 0
      dataVersion = 0
      aclVersion = 0
      ephemeralOwner = 0x0
      dataLength = 5
      numChildren = 0
      [zk: 127.0.0.1:2181(CONNECTED) 3] delete /treeroot
      [zk: 127.0.0.1:2181(CONNECTED) 4]
    # 退出客户端:
      quit
    # 7.查看zookeeper的状态
       ./zkServer.sh status ./zkServer.sh status
    # 8.重启zookeeper 命令
       ./zkServer.sh status ./zkServer.sh restart
    

    3.1.1.zookeeper的服务配置

    # 1.设置开机自启动
      在/etc/rc.local的末尾添加一行以绝对路径启动脚本的行;
      /usr/local/sbin/zookeeper/zookeeper-3.4.12/bin/zkServer.sh start
    # 2.zookeeper服务配置
      
    

    4.JDK在Linux下的安装

    4.1.ubuntu环境下的安装配置

    4.1.1.apt-get的安装方式

    4.1.2.解压安装方式

    #1.下载jdk
    wget 路径
    #2.解压
    tar -zxvf 包名
    #3.环境变量配置
    vi ~/.bashrc
    #在最下面添加如下内容
    #set oracle jdk environment
    export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_60  ## 这里要注意目录要换成自己解压的jdk 目录
    export JRE_HOME=${JAVA_HOME}/jre  
    export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib  
    export PATH=${JAVA_HOME}/bin:$PATH  
    

    然后编译该文件

    4.查看是否安装成功

    java -version
    source ~/.bashrc

    5.maven在Linux下的安装

    5.1.ubuntu环境下的安装配置

    5.1.1.apt-get的安装方式

    5.1.2.解压安装方式

    #1.到官网下载相关版本maven
    
    #2.复制解压
    sudo mv apache-maven-3.5.3-bin.tar.gz /usr/local/
    sudo tar -zxvf apache-maven-3.5.4-bin.tar.gz
    sudo rm -rf apache-maven-3.5.4-bin.tar.gz
    #3.配置环境变量
    sudo vi ~/.bashrc
    #添加如下内容
    export M2_HOME=/usr/local/software/maven/apache-maven-3.5.4
    export PATH=${M2_HOME}/bin:$PATH
    #编译
    source ~/.bashrc
    

    扫描以下公众号关注小猿↓↓↓↓↓↓↓↓

    更多资讯请在简书、微博、今日头条、掘金、CSDN都可以通过搜索“Share猿”找到小猿哦!!!

    相关文章

      网友评论

          本文标题:【操作系统】Linux:重常用开发环境的安装部署

          本文链接:https://www.haomeiwen.com/subject/eqmosftx.html