Centos 7 创建简单的实验环境

Posted obybo

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Centos 7 创建简单的实验环境相关的知识,希望对你有一定的参考价值。

搭建Centos 7 实验环境

环境

  - VMware workstation 15 pro; Centos 7 
  - 镜像 :CentOS-7-x86_64-DVD-1908.iso 觉得麻烦的可以使用后面的这个地址:[https://mirror.umd.edu/centos/7/isos/x86_64/CentOS-7-x86_64-DVD-1908.iso](下载地址)
  >> - **最好别使用LiveGNOME环境**,部分机器每次重启都需要重新设置 语言 以及其他部分选项,很麻烦。
  - Windows 10 1909版本 os 内部版本 1836.836  
  >> - 查看版本方式: 按下windows 同时按 R ,在输入框中输入winver 按回车 会弹出 Windows 系统的信息

安装步骤

  1. 下载VMware 并安装,具体教程百度下,很多。简述下
  >> >> 1. 官网下载安装包,[https://my.vmware.com/en/web/vmware/info/slug/desktop_end_user_computing/vmware_workstation_pro/15_0](下载地址) 选择 你当前电脑 操作系统 种类对应的安装包
  >> 2. Windows 下,直接双击安装包,简易安装就直接一路next就好。记得看到分配硬盘空间的时候 分配稍大的空间,后续 扩展空间相对麻烦,可以自行百度下。
  2. 下载centos 7镜像(上面给出下载地址了)
  3. 在安装好的VMware workstation pro 中选择虚拟机安装,一路next就好。
  4. 在点击完成后,会进入界面。选择 install centos

搭建环境

  1. 进入Linux(Centos 7)环境下,点击右上角 电源按钮,在有线连接(即使你自己电脑(宿主机)使用的是WiFi,Linux中也会显示有线连接,这是VMware workstation pro软件本身设计好的))处点击连接。不点的话可能在运行下边命令的时候提示你没联网。
  2. 运行命令
        >> 安装zsh(shell的一种)
        >> `sudo su`
        >> 然后输入你在安装系统时设置好的密码
        >> `yum install zsh`
        >> 更换Centos 7源(所谓 源 就是一个公共库,用户centos 7进行相关插件 软件的更新及安装)
        >> 先备份系统初始 源
        >> cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
        >> 更改源
        >> `gedit /etc/yum.repos.d/CentOS-Base.repo`
        >> ctrl + a选中文件中所有内容将下边代码复制进去,保存。
        >>`# CentOS-Base.repo

The mirror system uses the connecting IP address of the client and the

update status of each mirror to pick mirrors that are updated to and

geographically close to the client. You should use this for CentOS updates

unless you are manually picking other mirrors.

If the mirrorlist= does not work for you, as a fall back you can try the

remarked out baseurl= line instead.

[base]
name=CentOS-$releasever - Base
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/

mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os

enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-7

released updates

[updates]
name=CentOS-$releasever - Updates
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/

mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates

enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-7

additional packages that may be useful

[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/

mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras

enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-7

additional packages that extend functionality of existing packages

[centosplus]
name=CentOS-$releasever - Plus
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/

mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus

gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-7
>> yum makecache >> 此时可以进行更新 也可以不更新 >>yum upgrade >> gedit install.sh >> 在弹出的界面中复制粘贴下列内容(用于下载安装oh-my-zsh —— 一种用于美化zsh shell 的插件,由于该插件被墙了,给出安装所需的bash文件代码) >>#!/bin/sh

This script should be run via curl:

sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

or wget:

sh -c "$(wget -qO- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

As an alternative, you can first download the install script and run it afterwards:

wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh

sh install.sh

You can tweak the install behavior by setting variables when running the script. For

example, to change the path to the Oh My Zsh repository:

ZSH=~/.zsh sh install.sh

Respects the following environment variables:

ZSH - path to the Oh My Zsh repository folder (default: $HOME/.oh-my-zsh)

REPO - name of the GitHub repo to install from (default: ohmyzsh/ohmyzsh)

REMOTE - full remote URL of the git repo to install (default: GitHub via HTTPS)

BRANCH - branch to check out immediately after install (default: master)

Other options:

CHSH - ‘no‘ means the installer will not change the default shell (default: yes)

RUNZSH - ‘no‘ means the installer will not run zsh after the install (default: yes)

KEEP_ZSHRC - ‘yes‘ means the installer will not replace an existing .zshrc (default: no)

You can also pass some arguments to the install script to set some these options:

--skip-chsh: has the same behavior as setting CHSH to ‘no‘

--unattended: sets both CHSH and RUNZSH to ‘no‘

--keep-zshrc: sets KEEP_ZSHRC to ‘yes‘

For example:

sh install.sh --unattended

set -e

Default settings

ZSH=${ZSH:-~/.oh-my-zsh}
REPO=${REPO:-ohmyzsh/ohmyzsh}
REMOTE=${REMOTE:-https://github.com/${REPO}.git}
BRANCH=${BRANCH:-master}

Other options

CHSH=${CHSH:-yes}
RUNZSH=${RUNZSH:-yes}
KEEP_ZSHRC=${KEEP_ZSHRC:-no}

command_exists() {
command -v "$@" >/dev/null 2>&1
}

error() {
echo ${RED}"Error: $@"${RESET} >&2
}

setup_color() {
# Only use colors if connected to a terminal
if [ -t 1 ]; then
RED=$(printf ‘33[31m‘)
GREEN=$(printf ‘33[32m‘)
YELLOW=$(printf ‘33[33m‘)
BLUE=$(printf ‘33[34m‘)
BOLD=$(printf ‘33[1m‘)
RESET=$(printf ‘33[m‘)
else
RED=""
GREEN=""
YELLOW=""
BLUE=""
BOLD=""
RESET=""
fi
}

setup_ohmyzsh() {
# Prevent the cloned repository from having insecure permissions. Failing to do
# so causes compinit() calls to fail with "command not found: compdef" errors
# for users with insecure umasks (e.g., "002", allowing group writability). Note
# that this will be ignored under Cygwin by default, as Windows ACLs take
# precedence over umasks except for filesystems mounted with option "noacl".
umask g-w,o-w

echo "${BLUE}Cloning Oh My Zsh...${RESET}"

command_exists git || {
	error "git is not installed"
	exit 1
}

if [ "$OSTYPE" = cygwin ] && git --version | grep -q msysgit; then
	error "Windows/MSYS Git is not supported on Cygwin"
	error "Make sure the Cygwin git package is installed and is first on the $PATH"
	exit 1
fi

git clone -c core.eol=lf -c core.autocrlf=false 	-c fsck.zeroPaddedFilemode=ignore 	-c fetch.fsck.zeroPaddedFilemode=ignore 	-c receive.fsck.zeroPaddedFilemode=ignore 	--depth=1 --branch "$BRANCH" "$REMOTE" "$ZSH" || {
	error "git clone of oh-my-zsh repo failed"
	exit 1
}

echo

}

setup_zshrc() {
# Keep most recent old .zshrc at .zshrc.pre-oh-my-zsh, and older ones
# with datestamp of installation that moved them aside, so we never actually
# destroy a user‘s original zshrc
echo "${BLUE}Looking for an existing zsh config...${RESET}"

# Must use this exact name so uninstall.sh can find it
OLD_ZSHRC=~/.zshrc.pre-oh-my-zsh
if [ -f ~/.zshrc ] || [ -h ~/.zshrc ]; then
	# Skip this if the user doesn‘t want to replace an existing .zshrc
	if [ $KEEP_ZSHRC = yes ]; then
		echo "${YELLOW}Found ~/.zshrc.${RESET} ${GREEN}Keeping...${RESET}"
		return
	fi
	if [ -e "$OLD_ZSHRC" ]; then
		OLD_OLD_ZSHRC="${OLD_ZSHRC}-$(date +%Y-%m-%d_%H-%M-%S)"
		if [ -e "$OLD_OLD_ZSHRC" ]; then
			error "$OLD_OLD_ZSHRC exists. Can‘t back up ${OLD_ZSHRC}"
			error "re-run the installer again in a couple of seconds"
			exit 1
		fi
		mv "$OLD_ZSHRC" "${OLD_OLD_ZSHRC}"

		echo "${YELLOW}Found old ~/.zshrc.pre-oh-my-zsh." 			"${GREEN}Backing up to ${OLD_OLD_ZSHRC}${RESET}"
	fi
	echo "${YELLOW}Found ~/.zshrc.${RESET} ${GREEN}Backing up to ${OLD_ZSHRC}${RESET}"
	mv ~/.zshrc "$OLD_ZSHRC"
fi

echo "${GREEN}Using the Oh My Zsh template file and adding it to ~/.zshrc.${RESET}"

sed "/^export ZSH=/ c

export ZSH="$ZSH"
" "$ZSH/templates/zshrc.zsh-template" > ~/.zshrc-omztemp
mv -f ~/.zshrc-omztemp ~/.zshrc

echo

}

setup_shell() {
# Skip setup if the user wants or stdin is closed (not running interactively).
if [ $CHSH = no ]; then
return
fi

# If this user‘s login shell is already "zsh", do not attempt to switch.
if [ "$(basename "$SHELL")" = "zsh" ]; then
	return
fi

# If this platform doesn‘t provide a "chsh" command, bail out.
if ! command_exists chsh; then
	cat <<-EOF
		I can‘t change your shell automatically because this system does not have chsh.
		${BLUE}Please manually change your default shell to zsh${RESET}
	EOF
	return
fi

echo "${BLUE}Time to change your default shell to zsh:${RESET}"

# Prompt for user choice on changing the default login shell
printf "${YELLOW}Do you want to change your default shell to zsh? [Y/n]${RESET} "
read opt
case $opt in
	y*|Y*|"") echo "Changing the shell..." ;;
	n*|N*) echo "Shell change skipped."; return ;;
	*) echo "Invalid choice. Shell change skipped."; return ;;
esac

# Check if we‘re running on Termux
case "$PREFIX" in
	*com.termux*) termux=true; zsh=zsh ;;
	*) termux=false ;;
esac

if [ "$termux" != true ]; then
	# Test for the right location of the "shells" file
	if [ -f /etc/shells ]; then
		shells_file=/etc/shells
	elif [ -f /usr/share/defaults/etc/shells ]; then # Solus OS
		shells_file=/usr/share/defaults/etc/shells
	else
		error "could not find /etc/shells file. Change your default shell manually."
		return
	fi

	# Get the path to the right zsh binary
	# 1. Use the most preceding one based on $PATH, then check that it‘s in the shells file
	# 2. If that fails, get a zsh path from the shells file, then check it actually exists
	if ! zsh=$(which zsh) || ! grep -qx "$zsh" "$shells_file"; then
		if ! zsh=$(grep ‘^/.*/zsh$‘ "$shells_file" | tail -1) || [ ! -f "$zsh" ]; then
			error "no zsh binary found or not present in ‘$shells_file‘"
			error "change your default shell manually."
			return
		fi
	fi
fi

# We‘re going to change the default shell, so back up the current one
if [ -n "$SHELL" ]; then
	echo $SHELL > ~/.shell.pre-oh-my-zsh
else
	grep "^$USER:" /etc/passwd | awk -F: ‘{print $7}‘ > ~/.shell.pre-oh-my-zsh
fi

# Actually change the default shell to zsh
if ! chsh -s "$zsh"; then
	error "chsh command unsuccessful. Change your default shell manually."
else
	export SHELL="$zsh"
	echo "${GREEN}Shell successfully changed to ‘$zsh‘.${RESET}"
fi

echo

}

main() {
# Run as unattended if stdin is closed
if [ ! -t 0 ]; then
RUNZSH=no
CHSH=no
fi

# Parse arguments
while [ $# -gt 0 ]; do
	case $1 in
		--unattended) RUNZSH=no; CHSH=no ;;
		--skip-chsh) CHSH=no ;;
		--keep-zshrc) KEEP_ZSHRC=yes ;;
	esac
	shift
done

setup_color

if ! command_exists zsh; then
	echo "${YELLOW}Zsh is not installed.${RESET} Please install zsh first."
	exit 1
fi

if [ -d "$ZSH" ]; then
	cat <<-EOF
		${YELLOW}You already have Oh My Zsh installed.${RESET}
		You‘ll need to remove ‘$ZSH‘ if you want to reinstall.
	EOF
	exit 1
fi

setup_ohmyzsh
setup_zshrc
setup_shell

printf "$GREEN"
cat <<-‘EOF‘
	         __                                     __
	  ____  / /_     ____ ___  __  __   ____  _____/ /_
	 / __ / __    / __ `__ / / / /  /_  / / ___/ __ 	/ /_/ / / / /  / / / / / / /_/ /    / /_(__  ) / / /
	\____/_/ /_/  /_/ /_/ /_/\__, /    /___/____/_/ /_/
	                        /____/                       ....is now installed!


	Please look over the ~/.zshrc file to select plugins, themes, and options.

	p.s. Follow us on https://twitter.com/ohmyzsh

	p.p.s. Get stickers, shirts, and coffee mugs at https://shop.planetargon.com/collections/oh-my-zsh

EOF
printf "$RESET"

if [ $RUNZSH = no ]; then
	echo "${YELLOW}Run zsh to try it out.${RESET}"
	exit
fi

exec zsh -l

}

main "$@" >>./install.sh >> 然后等待安装 >> 安装好后 >> 安装vscode IDE 因为之前Windows 中使用vscode挺方便的就安装了这个。 >> [安装链接](https://code.visualstudio.com/docs/setup/linux) >>rpm --import https://packages.microsoft.com/keys/microsoft.asc >>sh -c ‘echo -e "[code] name=Visual Studio Code baseurl=https://packages.microsoft.com/yumrepos/vscode enabled=1 gpgcheck=1 gpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/vscode.repo‘ >>yum check-update >>yum install code`
>> 然后就可以进行编程了。同时vscode中支持很多插件,可以根据你的需要进行安装,网上也有很多相关教程可以查看。

以上是关于Centos 7 创建简单的实验环境的主要内容,如果未能解决你的问题,请参考以下文章

CentOS 7中修复MBR扇区故障实验

centos7系统创建Xshell6.0会话环境部署(可跟做)

简单操作Zabbix安装配置与邮件报警(centos 7.4)

CentOS 7 Redis 集群安装

Centos7环境下安装Mysql5.7版本

CentOS 7中修复GRUB菜单故障实验