美文网首页
CentOS7(VirtualBox) 搭建开发环境 Java,

CentOS7(VirtualBox) 搭建开发环境 Java,

作者: Muscleape | 来源:发表于2018-12-06 17:57 被阅读21次

    1、配置网卡

    1. 查看本机网卡信息
    [root@localhost ~]# ip addre
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
        inet 127.0.0.1/8 scope host lo
           valid_lft forever preferred_lft forever
        inet6 ::1/128 scope host 
           valid_lft forever preferred_lft forever
    2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
        link/ether 08:00:27:71:59:70 brd ff:ff:ff:ff:ff:ff
        inet 192.168.101.59/24 brd 192.168.101.255 scope global enp0s3
           valid_lft forever preferred_lft forever
        inet6 fe80::a00:27ff:fe71:5970/64 scope link 
           valid_lft forever preferred_lft forever
    3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
        link/ether 08:00:27:6b:74:69 brd ff:ff:ff:ff:ff:ff
        inet 10.0.3.15/24 brd 10.0.3.255 scope global dynamic enp0s8
           valid_lft 77547sec preferred_lft 77547sec
        inet6 fe80::a00:27ff:fe6b:7469/64 scope link 
           valid_lft forever preferred_lft forever
    
    1. 进入网卡配置信息目录
    [root@localhost network-scripts]# cd /etc/sysconfig/network-scripts/
    [root@localhost network-scripts]# ll
    total 240
    -rw-r--r--. 1 root root   346 Dec  6 14:15 ifcfg-enp0s3
    -rw-r--r--. 1 root root   310 Nov 29 18:01 ifcfg-enp0s8
    -rw-r--r--. 1 root root   254 Sep 16  2015 ifcfg-lo
    
    1. 备份要修改网卡的配置文件
    [root@localhost network-scripts]# cp ifcfg-enp0s3 ifcfg-enp0s3.backup20181206
    [root@localhost network-scripts]# ll
    total 240
    -rw-r--r--. 1 root root   346 Dec  6 14:15 ifcfg-enp0s3
    -rw-r--r--. 1 root root   277 Dec  6 14:01 ifcfg-enp0s3.backup20181206
    
    1. 修改网卡的配置:
    ## 打开文件(还没安装vim):
    [root@localhost network-scripts]# vi ifcfg-enp0s3
    
    ## 编辑内容如下:
    TYPE=Ethernet
    DEFROUTE=yes
    PEERDNS=yes
    PEERROUTES=yes
    IPV4_FAILURE_FATAL=no
    IPV6INIT=yes
    IPV6_AUTOCONF=yes
    IPV6_DEFROUTE=yes
    IPV6_PEERDNS=yes
    IPV6_PEERROUTES=yes
    IPV6_FAILURE_FATAL=no
    NAME=enp0s3
    UUID=23e59767-4151-4a4d-9385-e4c9cc5990ad
    DEVICE=enp0s3
    ONBOOT=yes
    BOOTPROTO=static
    IPADDR=192.168.101.59
    GATEWAY=192.168.101.1
    NETMASK=255.255.255.0
    
    1. 重启网络服务
    [root@localhost network-scripts]# systemctl restart network
    
    1. 查看网络服务状态(Active: active.....表示为正常启动状态)
    [root@localhost network-scripts]# systemctl status network
    ● network.service - LSB: Bring up/down networking
       Loaded: loaded (/etc/rc.d/init.d/network)
       Active: active (exited) since Thu 2018-12-06 16:43:32 CST; 6s ago
         Docs: man:systemd-sysv-generator(8)
      Process: 20160 ExecStop=/etc/rc.d/init.d/network stop (code=exited, status=0/SUCCESS)
      Process: 20483 ExecStart=/etc/rc.d/init.d/network start (code=exited, status=0/SUCCESS)
    
    Dec 06 16:43:29 localhost.localdomain network[20483]: Bringing up loopback interface:  Could not load file '/etc/sysconfig/network-script...cfg-lo'
    Dec 06 16:43:29 localhost.localdomain network[20483]: Could not load file '/etc/sysconfig/network-scripts/ifcfg-lo'
    Dec 06 16:43:30 localhost.localdomain network[20483]: Could not load file '/etc/sysconfig/network-scripts/ifcfg-lo'
    Dec 06 16:43:30 localhost.localdomain network[20483]: Could not load file '/etc/sysconfig/network-scripts/ifcfg-lo'
    Dec 06 16:43:30 localhost.localdomain network[20483]: [  OK  ]
    Dec 06 16:43:30 localhost.localdomain network[20483]: Bringing up interface enp0s3:  Connection successfully activated (D-Bus active path...tion/3)
    Dec 06 16:43:30 localhost.localdomain network[20483]: [  OK  ]
    Dec 06 16:43:31 localhost.localdomain network[20483]: Bringing up interface enp0s8:  Connection successfully activated (D-Bus active path...tion/4)
    Dec 06 16:43:31 localhost.localdomain network[20483]: [  OK  ]
    Dec 06 16:43:32 localhost.localdomain systemd[1]: Started LSB: Bring up/down networking.
    Hint: Some lines were ellipsized, use -l to show in full.
    
    1. 测试能否正常联网
    [root@localhost log]# ping www.baidu.com
    PING www.a.shifen.com (115.239.210.27) 56(84) bytes of data.
    64 bytes from 115.239.210.27: icmp_seq=1 ttl=54 time=26.3 ms
    64 bytes from 115.239.210.27: icmp_seq=2 ttl=54 time=28.0 ms
    64 bytes from 115.239.210.27: icmp_seq=3 ttl=54 time=26.5 ms
    64 bytes from 115.239.210.27: icmp_seq=4 ttl=54 time=38.2 ms
    64 bytes from 115.239.210.27: icmp_seq=5 ttl=54 time=26.9 ms
    64 bytes from 115.239.210.27: icmp_seq=6 ttl=54 time=26.5 ms
    ^C64 bytes from 115.239.210.27: icmp_seq=7 ttl=54 time=27.4 ms
    
    --- www.a.shifen.com ping statistics ---
    7 packets transmitted, 7 received, 0% packet loss, time 6018ms
    rtt min/avg/max/mdev = 26.371/28.599/38.262/3.981 ms
    

    2、 修改yum源

    网易YUM源下载地址:https://mirrors.163.com/.help/centos.html

    按照网站说明依次执行【备份】、【下载】、【生成缓存】操作

    3、安装SunJDK(可能需要卸载OpenJDK)

    参考链接:https://www.jianshu.com/p/58f311bfe332

    参考链接:https://www.cnblogs.com/muscleape/p/6385370.html

    1. 如果需要卸载OpenJDK,请参照以上链接
    2. 下载JDK文件,下载地址:https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
    3. 安装jdk
    ## 默认的安装路径在 /usr/java/
    [root@localhost ~]# rpm -ivh jdk-8u131-linux-x64.rpm
    
    1. 验证是否安装成功
    [root@localhost ~]# java -version
    java version "1.8.0_131"
    Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
    Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
    
    1. 配置环境变量
    ## 打开环境变量配置文件
    [root@localhost ~]# vi /etc/profile
    ## 添加一下jdk配置信息
    # SunJDK 1.8
    JAVA_HOME=/usr/java/jdk1.8.0_131
    JRE_HOME=/usr/java/jdk1.8.0_131/jre
    PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
    CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
    export JAVA_HOME JRE_HOME PATH CLASSPATH
    
    1. 使配置文件起作用
    [root@localhost ~]# source /etc/profile
    
    1. 查看环境变量
    ## 其中已经包含jdk配置信息
    [root@localhost ~]# echo $PATH
    /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/java/jdk1.8.0.131/bin:/usr/java/jdk1.8.0.131/jre/bin:/usr/java/jdk1.8.0_131/bin:/usr/java/jdk1.8.0_131/jre/bin
    

    4、安装Maven

    1. 下载安装包,地址:https://maven.apache.org/download.cgi
    2. 解压安装包,并放到指定目录中
    [root@localhost ~]# tar xzvf apache-maven-3.6.0-bin.tar.gz
    [root@localhost ~]# mv apache-maven-3.6.0/ /usr/apache-maven/ 
    
    1. 创建配置文件,并添加配置信息
    ## 创建配置文件
    [root@localhost ~]# cd /etc/profile.d/
    [root@localhost profile.d]# vim maven.sh
    ## 添加以下配置信息
    # Apache Maven Environment Variables
    # MAVEN_HOME for Maven 1 - M2_HOME for Maven 2
    export M2_HOME=/usr/apache-maven
    export PATH=${M2_HOME}/bin:${PATH}
    
    1. 修改配置文件权限,并使配置信息起作用
    [root@localhost profile.d]# chmod +x maven.sh
    [root@localhost profile.d]# ll
    total 60
    -rwxr-xr-x. 1 root root  152 Dec  6 15:28 maven.sh
    [root@localhost profile.d]# source /etc/profile.d/maven.sh
    
    1. 验证Maven安装情况
    [root@localhost profile.d]# mvn --version
    Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-25T02:41:47+08:00)
    Maven home: /usr/apache-maven
    Java version: 1.8.0_131, vendor: Oracle Corporation, runtime: /usr/java/jdk1.8.0_131/jre
    Default locale: en_US, platform encoding: UTF-8
    OS name: "linux", version: "3.10.0-327.el7.x86_64", arch: "amd64", family: "unix"
    

    5、安装MySQL(YUM方式安装)

    MySQL官网的完整安装步骤,暂时还没有用到这么多,这里只是摘取部分功能安装

    官方安装说明:https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/

    1. 下载MySQL的YUM Repository仓库文件(并不是安装文件),地址:https://dev.mysql.com/downloads/repo/yum/
    2. 安装下载的仓库配置文件
    [root@localhost files]# rpm -Uvh mysql80-community-release-el7-1.noarch.rpm
    
    1. 仓库文件中包含多个可安装的程序,查看一下:
    [root@localhost files]# yum repolist all | grep mysql
    mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community   disabled
    mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - disabled
    mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Community   disabled
    mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - disabled
    mysql-connectors-community/x86_64  MySQL Connectors Community    enabled:     74
    mysql-connectors-community-source  MySQL Connectors Community -  disabled
    mysql-tools-community/x86_64       MySQL Tools Community         enabled:     74
    mysql-tools-community-source       MySQL Tools Community - Sourc disabled
    mysql-tools-preview/x86_64         MySQL Tools Preview           disabled
    mysql-tools-preview-source         MySQL Tools Preview - Source  disabled
    mysql55-community/x86_64           MySQL 5.5 Community Server    disabled
    mysql55-community-source           MySQL 5.5 Community Server -  disabled
    mysql56-community/x86_64           MySQL 5.6 Community Server    disabled
    mysql56-community-source           MySQL 5.6 Community Server -  disabled
    mysql57-community/x86_64           MySQL 5.7 Community Server    disabled
    mysql57-community-source           MySQL 5.7 Community Server -  disabled
    mysql80-community/x86_64           MySQL 8.0 Community Server    enabled:     49
    mysql80-community-source           MySQL 8.0 Community Server -  disabled
    ##
    ## 可以看到默认的可安装的版本是 mysql80(倒数第二行最后的属性值为enabled)
    
    1. 查看安装信息文件
    ## 查找安装配置文件
    [root@localhost files]# cd /etc/yum.repos.d/
    [root@localhost yum.repos.d]# ll
    total 40
    -rw-r--r--. 1 root root 1864 Feb 22  2018 mysql-community.repo
    -rw-r--r--. 1 root root 1885 Feb 22  2018 mysql-community-source.repo
    
    1. 修改默认安装的版本,修改配置信息中特定版本的enabled属性值为1(只能有一个)
    ## 修改配置信息
    [root@localhost yum.repos.d]# vim mysql-community.repo
    ## 例如修改5.7的版本为默认安装的版本
    # Enable to use MySQL 5.7
    [mysql57-community]
    name=MySQL 5.7 Community Server
    baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
    enabled=1
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
    
    1. 确认安装版本变更为MySQL5.7
    [root@localhost yum.repos.d]# yum repolist all | grep mysql
    mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community   disabled
    mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - disabled
    mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Community   disabled
    mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - disabled
    mysql-connectors-community/x86_64  MySQL Connectors Community    enabled:     74
    mysql-connectors-community-source  MySQL Connectors Community -  disabled
    mysql-tools-community/x86_64       MySQL Tools Community         enabled:     74
    mysql-tools-community-source       MySQL Tools Community - Sourc disabled
    mysql-tools-preview/x86_64         MySQL Tools Preview           disabled
    mysql-tools-preview-source         MySQL Tools Preview - Source  disabled
    mysql55-community/x86_64           MySQL 5.5 Community Server    disabled
    mysql55-community-source           MySQL 5.5 Community Server -  disabled
    mysql56-community/x86_64           MySQL 5.6 Community Server    disabled
    mysql56-community-source           MySQL 5.6 Community Server -  disabled
    mysql57-community/x86_64           MySQL 5.7 Community Server    enabled:    307
    mysql57-community-source           MySQL 5.7 Community Server -  disabled
    mysql80-community/x86_64           MySQL 8.0 Community Server    disabled
    mysql80-community-source           MySQL 8.0 Community Server -  disabled
    
    1. 安装server
    [root@localhost yum.repos.d]# yum install mysql-community-server
    
    1. 查看已安装MySQL
    [root@localhost yum.repos.d]# rpm -qa | grep mysql
    mysql80-community-release-el7-1.noarch
    mysql-community-server-5.7.24-1.el7.x86_64
    mysql-community-libs-5.7.24-1.el7.x86_64
    mysql-community-libs-compat-5.7.24-1.el7.x86_64
    mysql-community-common-5.7.24-1.el7.x86_64
    mysql-community-client-5.7.24-1.el7.x86_64
    
    1. 查看MySQL服务状态
    [root@localhost yum.repos.d]# systemctl status mysqld
    ● mysqld.service - MySQL Server
       Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
       Active: inactive (dead)
         Docs: man:mysqld(8)
               http://dev.mysql.com/doc/refman/en/using-systemd.html
    [root@localhost yum.repos.d]# systemctl start mysqld
    [root@localhost yum.repos.d]# systemctl status mysqld
    ● mysqld.service - MySQL Server
       Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
       Active: active (running) since Thu 2018-12-06 16:11:21 CST; 6s ago
         Docs: man:mysqld(8)
               http://dev.mysql.com/doc/refman/en/using-systemd.html
      Process: 20035 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
      Process: 19961 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
     Main PID: 20038 (mysqld)
       CGroup: /system.slice/mysqld.service
               └─20038 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
    
    Dec 06 16:11:13 localhost.localdomain systemd[1]: Starting MySQL Server...
    Dec 06 16:11:21 localhost.localdomain systemd[1]: Started MySQL Server.
    
    1. 查看安装生成的默认密码
    [root@localhost log]# grep "password" ./mysqld.log
    2018-12-06T08:11:14.339301Z 1 [Note] A temporary password is generated for root@localhost: CQj-#jME0W2s
    
    1. 登录数据库
    [root@localhost log]# mysql -u root -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 2
    Server version: 5.7.24
    
    1. 修改root账户密码(密码格式默认需要满足一定的复杂度)
    mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
    
    1. 开放远程主机连接
    mysql> use mysql;
    mysql> select host,user from user;
    +-----------+---------------+
    | host      | user          |
    +-----------+---------------+
    | localhost | mysql.session |
    | localhost | mysql.sys     |
    | localhost | root          |
    +-----------+---------------+
    3 rows in set (0.00 sec)
    
    mysql> update user set host = '%' where user ='root';
    Query OK, 1 row affected (0.00 sec)
    Rows matched: 1  Changed: 1  Warnings: 0
    
    mysql> select host,user from user;
    +-----------+---------------+
    | host      | user          |
    +-----------+---------------+
    | %         | root          |
    | localhost | mysql.session |
    | localhost | mysql.sys     |
    +-----------+---------------+
    3 rows in set (0.00 sec)
    
    mysql> flush privileges;
    
    mysql> exit
    Bye
    
    1. 防火墙开放3306端口
    ## 输出success则表示添加成功
    [root@localhost ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
    success
    ## 重启防火墙
    [root@localhost ~]# systemctl restart firewalld
    
    1. 使用其他机器连接数据库,测试是否可连接

    相关文章

      网友评论

          本文标题:CentOS7(VirtualBox) 搭建开发环境 Java,

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