个人搭建虚拟机linux系统过程

版权声明:欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置标出原文地址。 https://blog.csdn.net/wohiusdashi/article/details/81147059
本人与网上找到与上面一篇一模一样(关于tomcat的安装)的,但发布于2015。
在此贴上链接 https://www.cnblogs.com/xdp-gacl/p/4097608.html


1.下载虚拟机及linux系统的链接

链接:https://pan.baidu.com/s/13_nnI_YlCtFMQbwKQIbsmg
提取码:q4l8
(虚拟机软件及linux安装教程,以及xshell软件。并没有CentOS7)
dalao的链接

2.下载虚拟机

链接里有虚拟机的软件,貌似没什么特别需要注意的地方。按引导下载就好了,笔者写笔记是时候里搭建好已经很久了,印象不是很清楚了,抱歉。
选择清华镜像:http://mirrors.tuna.tsinghua.edu.cn/centos/7.5.1804/isos/x86_64/CentOS-7-x86_64-DVD-1804.iso

3.搭建linux
  1. 链接里有CentOS7的安装教程pdf,按照教程安装就好了。设置好开机密码。进入linux系统后,输入账号root与密码,进入系统(密码输入时不会显示)。
  2. 进入系统后,通过ifconfig可以查看自己的网卡ip段,得知自己ip段后,可以通过安装链接里的xsell来远程链接linux,只需要输入开机账号和密码,以及链接的ip地址就可以。xsell可以实现代码段的复制粘贴。
  3. 如果查找不到自己的ip段,可能是因为在虚拟机设置里没设置好网卡
    • 可以打开虚拟机设置->网络适配器->(选择桥接模式或者NAT模式)
    • 可能虚拟机网卡服务没能开启:在电脑中搜索服务–>检查虚拟机的5个服务是否开启。或者打开资源管理器,看看能否找到VMwore的5个服务,如果没打开,就打开(反正就打开图片中的服务就对了)。
      五个服务
    • 可能linux中的管卡管理影响了你的网卡链接,在CentOS7中,新添加了一个networkmanager,用于网卡管理,但是如果对这个不懂,不知道怎么操作的话,可以直接关闭这个网卡管理。(笔者通过方式3成功)
      暂时关闭和永久关闭
    systemctl stop NetworkManager
    systemctl disable NetworkManager
    
  4. CentOS7显示的网卡类型可能是ens33,这与以往的网卡类型eth0不同,可能不使用与之前版本的某些服务,如果想将之改动的话,可以以下方式转载自
    • vim /etc/sysconfig/network-scripts/ifcfg-ens33
      将NAME和DEVICE两个属性的值从ens33改为eth0
    • mv ifcfg-ens33 ifcfg-eth0
      然后将文件名从ifcfg-ens33改为ifcfg-eth0
      -vim /etc/default/grub
      禁用该可预测命名规则。对于这一点,你可以在启动时传递“net.ifnames=0 biosdevname=0 ”的内核参数。这是通过编辑/etc/default/grub并加入“net.ifnames=0 biosdevname=0 ”到GRUBCMDLINELINUX变量来实现的。
    • grub2-mkconfig -o /boot/grub2/grub.cfg
      运行命令grub2-mkconfig -o /boot/grub2/grub.cfg 来重新生成GRUB配置并更新内核参数。
    • 重启电脑
4.搭建jdk ,tomcat环境(笔者的方法)
  1. 安装jdk
    从jdk官网(百度)下载linux系统的jdk包(推荐下载时选择契合自己使用的版本),下载后可以通过ftps或者lszrz方式上传到linux系统,解压到/usr/loval目录下
    设置环境变量 vim /etc/profile
    在底下添加
    export JAVA_HOME=/usr/local/jdk0.8.0_181
    export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
    export PATH=$JAVA_HOME/bin:$PATH
    
    检查安装(和window很像) 输入:java -verison
    本质上就是想window上配置jdk环境一样,然后通过export设置为全局变量(自己选好目录不然报错的)
  2. 安装tomcat
    直接下载linux tomcat安装包,解压安装就可以了
    修改默认端口,则时修改conf目录下的service.xml文件,找到端口设置修改(笔者认为不难不写了)
    tomcat打开与关闭:使用bin目录下的shell脚本 (./startup.sh)和(./shutdown.sh)
    记得打开linux的tomcat相关的端口防火墙,才可以访问linux上的tomcat
    firewall-cmd --zone=public --add-port=5121/tcp --permanent
    #–zone 作用域
    #–add-port=5121/tcp 添加端口,格式为:端口/通讯协议
    #–permanent 永久生效,没有此参数重启后失效
5.安装mysql

yum方式:https://www.cnblogs.com/caoxb/p/9405323.html

  1. 下载mysql源安装包
    shell> wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
  2. 安装mysql源
    shell> yum localinstall mysql57-community-release-el7-8.noarch.rpm
  3. 检查mysql源是否安装成功
    shell> yum repolist enabled | grep “mysql.-community.
  4. 修改 vim /etc/yum.repos.d/mysql-community.repo源 ,改变默认安装的mysql版本。比如要安装5.6版本,将5.7源的enabled=1改成enabled=0。然后再将5.6源的enabled=0改成enabled=1即可。
  5. 安装MySQL
    shell> yum install mysql-community-server
  6. 启动MySQL服务
    shell> systemctl start mysqld
  7. 开机启动
    shell> systemctl enable mysqld
    shell> systemctl daemon-reload
  8. 修改root本地登录密码
    1)查看mysql密码
    shell> grep ‘temporary password’ /var/log/mysqld.log
    2)连接mysql
    shell> mysql -uroot -p
    3)修改密码[注意:后面的分号一定要跟上]
    mysql> ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘MyNewPass4!’;
    或者:
    mysql> set password for ‘root’@‘localhost’=password(‘MyNewPass4!’);
    mysql> show variables like ‘%password%’;
  9. 添加远程登录用户
    mysql> GRANT ALL PRIVILEGES ON . TO ‘caoxiaobo’@’%’ IDENTIFIED BY ‘Caoxiaobo0917!’ WITH GRANT OPTION;
6. redis
  1. 安装
  2. 官网:https://redis.io/download
  3. 安装异常处理来自
    (1)若出现如下提示,则说明未安装gcc,使用命令安装gcc:yum install gcc
    [root@localhost redis-4.0.11]# make
    cd src && make all
    make[1]: Entering directory `/root/redis-4.0.11
    /src‘ CC adlist.o /bin/sh: cc: command not found make[1]: *** [adlist.o] Error 127 make[1]: Leaving directory `/root/redis-2.8.17/src‘ make: *** [all] Error 2
    
    (2)若出现如下提示,则将make改为make MALLOC=libc,推测是因为编译库的问题。
    	[root@localhost redis-4.0.11]# make
    	cd src && make all
    	make[1]: Entering directory `/root/redis-2.8.17/src‘
        	CC adlist.o
    	In file included from adlist.c:34:
    	zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directory
    	zmalloc.h:55:2: error: #error "Newer version of jemalloc required"
    	make[1]: *** [adlist.o] Error 1
    	make[1]: Leaving directory `/root/redis-2.8.17/src‘
    	make: *** [all] Error 2
    
    (3)make test错误
    hadoop@stormspark:~/workspace/redis2.6.13/src$ make test
    You need tcl 8.5 or newer in order to run the Redis test
    make: *** [test] Error 1
    
    处理
    wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz  
    sudo tar xzvf tcl8.6.1-src.tar.gz  -C /usr/local/  
    cd  /usr/local/tcl8.6.1/unix/  
    sudo ./configure  
    sudo make  
    sudo make install   
    
    (4)make test报错
    	*** [err]: Test replication partial resync: ok psync (diskless: yes, reconnect: 1) in tests/integration/replication-psync.tcl
    Expected condition '[s -1 sync_partial_ok] > 0' to be true ([s -1 sync_partial_ok] > 0)
    Cleanup: may take some time... OK
    make[1]: *** [test] Error 1
    make[1]: Leaving directory `/usr/local/src/redis-3.2.1/src'
    make: *** [test] Error 2
    
    解决办法
    1,只用单核运行 make test:
    taskset -c 1 sudo make test
    2,更改 tests/integration/replication-psync.tcl 文件:
    vi tests/integration/replication-psync.tcl
    把对应报错的那段代码中的 after后面的数字,从100改成 500。我个人觉得,这个参数貌似是等待的毫秒数。
    在这里插入图片描述
    这两种方法都可以解决这个报错。(笔者觉得第一种治标不治本,所以选了第二种,成功解决。)
修改镜像地址

清华大学开源镜像

linux常用
  1. 有点粗糙,勉强能用
  2. 超实用的常见命令
  3. 初学者福音
防火墙
  1. 防火墙操作
    如果想使用iptables服务
    systemctl stop firewalld
    systemctl disable firewalld
    
    yum install iptables-services
    
    touch /etc/sysconfig/iptables
    systemctl start iptables
    systemctl enable iptables
    
    systemctl stop iptables
    
    touch /etc/sysconfig/ip6tables
    systemctl start ip6tables
    systemctl enable ip6table
    
    vim /etc/sysconfig/iptables
    #添加80和3306端口 等等(自己配置)
    -A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT           #80端口开放
    
    -A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT    #3306端口开放
    
    -I INPUT -s 113.106.93.110 -p tcp --dport 8089 -j DROP                         #禁止指定IP访问 8089
    
    -I INPUT -s 113.106.93.110 -p tcp --dport 8080 -j ACCEPT                    #开放固定ipIP访问 8080
    #重启防火墙使配置文件生效  
    systemctl restart iptables.service
    
    #设置iptables防火墙为开机启动项 
    systemctl enable iptables.service
    service iptables  start     #启动服务
    service iptables  stop     #停止服务
    service iptables  restart  #重启服务
    
    如果还不行,那就查看一下自己得网卡文件,修改其中得onboot为yes 然后重启服务
    vim /etc/sysconfig/network-scripts/ifcfg-ens32
    修改其中的onboot为yes
    然后重启服务
    systemctl restart network.service
    
    使用CentOS7的操作
    安装firewalld和firewall-cmd
    检查防火墙状态
    firewall-cmd --stat
    临时开放ftp服务
    firewall-cmd --add-service=ftp
    永久开放ftp服务
    firewall-cmd --add-service=ftp --permanent
    关闭ftp服务
    firewall-cmd --remove-service=ftp --permanent
    配置防火墙在public区域永久开放http服务
    firewall-cmd --permanent --zone=public --add-service=http
    加入指定开放端口
    firewall-cmd --add-port=1324/tcp
    为了让之前的设定生效当然要重启服务咯
    systemctl restart firewalld
    或者使用下面的命令免去重启服务(防火墙策略配置后重新载入)
    firewall-cmd --complete-reload
    firewall-cmd --reload (这两句功能相同)
    检查ftp服务的21端口是否开放
    iptables -L -n | grep 21
    ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:21 ctstate NEW
    查询ftp服务启用状态
    firewall-cmd --query-service ftp
    查看当前规则
    firewall-cmd --list-all
    仅允许部分IP访问本机服务配置
    firewall-cmd --permanent --zone=public --add-rich-rule="rule family="ipv4" \
    source address="192.168.0.4/24" service name="http" accept"
    仅允许部分IP访问本机端口配置
    firewall-cmd --permanent --zone=public --add-rich-rule="rule family="ipv4" \
    source address="192.168.0.4/24" \
    port protocol="tcp" port="8080" accept" 
    firewall-cmd --zone=public --add-port=3306/tcp --permanent
    输入命令,开通端口报错,
    FirewallD is not running 
    开启防火墙即可。
    systemctl start firewalld 
    
Linux组操作
出现的问题
  • 解决pwd /could not retrieve mirrorlist
    1.sudo vim /etc/sysconfig/network-scripts/ifcfg-ens33 ​
    2.将ONBOOT改为yes,wq!保存退出
    3.重新启动网络 $ service network restart
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值