【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>>
一、使用yum下载所需要的包到一个目录下:
yum install --downloaddir ./ --downloadonly nvidia-detect
二、制作脚本文件:
脚本文件需要unix格式(只有0A 换行,没有0D回车),不能是window格式。最后必须是0A结尾。在0A结尾前必须是“###### End install.sh”,用于标识tar.gz文件的开始。如果tar不能解包,一般是最后定位不准,可能差一行。
#!/bin/bash
# 处理命令:tar -zcvf ./local_euler_repo.tar.gz ./local_euler_repo
# 后期处理命令:cat install.sh local_euler_repo.tar.gz > ai_env_install_euleros2.0sp5_gui_x86_64.run
#解包tar.gz文件
echo "$(date '+%Y-%m-%d %H:%M:%S') Extract files to temporary directory"
# 用于定位tar.gz文件的开始位置
lineCount=$(grep -a -n -E "^###### End install.sh" $0|awk -F: '{print $1 + 1}')
tail -n +$lineCount $0 > /tmp/local_euler_repo.tar.gz
tar zxvf /tmp/local_euler_repo.tar.gz -C /tmp
# 创建本地库
echo "$(date '+%Y-%m-%d %H:%M:%S') Create local software repo"
cat > /etc/yum.repos.d/EulerOS-Local.repo <<EOF
[Local-EulerOS-AI]
name=Local EulerOS-2.0SP5 AI - \$basearch
baseurl=file:///tmp/local_euler_repo
enabled=1
gpgcheck=0
priority=1
EOF
# 安装
echo "$(date '+%Y-%m-%d %H:%M:%S') Installation related tools"
yum clean all
yum makecache
yum update -y
yum erase -y systemtap-runtime
yum install -y make gcc kernel-devel
rm -fr /etc/yum.repos.d/EulerOS-Local.repo
rm -fr /tmp/local_euler_repo×
exit 0
# 用于定位tar.gz文件的开始位置
###### End install.sh
三、生成压缩包:
tar -zcvf ./local_euler_repo.tar.gz ./local_euler_repo
四、生成run文件:
cat install.sh local_euler_repo.tar.gz > ai_env_install_euleros2.0sp5_gui_x86_64.run
五、完整的脚本:
#!/bin/bash
# file_name: install.sh
# 处理命令:tar -zcvf ./local_euler_repo.tar.gz ./local_euler_repo
# 后期处理命令:cat install.sh local_euler_repo.tar.gz > ai_env_install_euleros2.0sp5_gui_x86_64.run
echo "$(date '+%Y-%m-%d %H:%M:%S') AI environment install....."
# 必须使用root用户运行
if [ "$(whoami)" != "root" ]; then
echo "Please use root to execute!!!"
exit 0
fi
#repo是否存在,用于判断是否需要重启
repos_file_is_exist=$(ls /etc/yum.repos.d/EulerOS-Local.repo 2>/dev/null|wc -l)
#解包tar.gz文件
echo "$(date '+%Y-%m-%d %H:%M:%S') Extract files to temporary directory"
lineCount=$(grep -a -n -E "^###### End install.sh" $0|awk -F: '{print $1 + 1}')
tail -n +$lineCount $0 > /tmp/local_euler_repo.tar.gz
tar zxvf /tmp/local_euler_repo.tar.gz -C /tmp
# 创建本地库
echo "$(date '+%Y-%m-%d %H:%M:%S') Create local software repo"
cat > /etc/yum.repos.d/EulerOS-Local.repo <<EOF
[Local-EulerOS-AI]
name=Local EulerOS-2.0SP5 AI - \$basearch
baseurl=file:///tmp/local_euler_repo
enabled=1
gpgcheck=0
priority=1
EOF
# 安装
echo "$(date '+%Y-%m-%d %H:%M:%S') Installation related tools"
yum clean all
yum makecache
yum update -y
yum erase -y systemtap-runtime
yum install -y make gcc kernel-devel
# 禁用nouveau
if [ "$(ls /boot/initramfs-*nouveau.img 2>/dev/bull|wc -l)" == "0" ]; then
echo "$(date '+%Y-%m-%d %H:%M:%S') Disable nouveau"
sed -i '/GRUB_CMDLINE/ s/auto/auto rd.driver.blacklist=nouveau nouveau.modeset=0/g' /etc/default/grub
grub2-mkconfig -o /boot/grub2/grub.cfg #生成配置
echo -e "blacklist nouveau\noptions nouveau modeset=0" >> /etc/modprobe.d/blacklist.conf
mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r)-nouveau.img
dracut /boot/initramfs-$(uname -r).img $(uname -r) #更新配置,并重启
else
echo "$(date '+%Y-%m-%d %H:%M:%S') Nouveau is disabled"
fi
# 重启系统
if [ $repos_file_is_exist == "0" ]; then
echo "$(date '+%Y-%m-%d %H:%M:%S') Reboot system"
echo "The system restarts 10 seconds later !!!"
echo "*****After the restarts, please run the file again !!!"
sleep 10
# 进入字符模式
systemctl disable gdm.service
reboot
fi
#开机后确认是否禁用
if [ "$(lsmod | grep nouveau | grep -v grep | wc -l)" == "0" ]; then
echo "Nouveau is disabled"
else
echo "Nouveau disable failed, please check manually. Yes to continue, otherwise exit the installation:[N]"
read your_input
sleep 1
if [ $your_input != "yes" -a $your_input != "Yes" -a $your_input != "Y" -a $your_input != "y"]; then
rm -fr /etc/yum.repos.d/EulerOS-Local.repo
rm -fr /tmp/local_euler_repo×
echo exit 0
fi
fi
# 安装docker
echo "$(date '+%Y-%m-%d %H:%M:%S') Install docker"
chattr -i /etc/gshadow
chattr -i /etc/shadow
chattr -i /etc/group
chattr -i /etc/passwd
groupadd docker
chattr -i /etc/gshadow
chattr -i /etc/shadow
chattr -i /etc/group
chattr -i /etc/passwd
yum install -y docker-ce
yum install -y nvidia-docker2
systemctl enable docker
# 设置网络
sed -i "s/net.ipv4.ip_forward=0/net.ipv4.ip_forward=1/g" /etc/sysctl.conf
systemctl restart network
sed -i 's/^MACs/#MACs/g' /etc/ssh/sshd_config
systemctl restart sshd
# 安装显卡驱动
yum install -y nvidia-detect
echo "$(date '+%Y-%m-%d %H:%M:%S') Install nvidia driver"
echo "Select the type of Graphics:"
echo " 1. NVIDIA RTX 2080 Ti"
echo " 2. NVIDIA Tesla P4"
echo " 3. Installer driver by IEF"
echo " 4. other"
echo " q. quit"
echo "Please your choice[1|2|3|q]:"
read your_input
sleep 1
if [ "$your_input" == "1" ]; then
echo "$(date '+%Y-%m-%d %H:%M:%S') Install RTX 2080 Ti Driver...."
chmod a+x /tmp/local_euler_repo/nvidia_drivers/NVIDIA-Linux-x86_64-440.44.run
sh /tmp/local_euler_repo/nvidia_drivers/NVIDIA-Linux-x86_64-440.44.run --no-opengl-files --no-install-compat32-libs
fi
if [ "$your_input" == "2" ]; then
echo "$(date '+%Y-%m-%d %H:%M:%S') Install Tesla P4 Driver...."
chmod a+x /tmp/local_euler_repo/nvidia_drivers/NVIDIA-Linux-x86_64-410.129-diagnostic.run
sh /tmp/local_euler_repo/nvidia_drivers/NVIDIA-Linux-x86_64-410.129-diagnostic.run --no-opengl-files --no-install-compat32-libs
fi
if [ "$your_input" == "3" ]; then
echo "Please install the graphics driver manually!!!"
fi
if [ "$your_input" == "4" ]; then
echo "Please install the graphics driver manually!!!"
fi
if [ "$your_input" == "q" ]; then
echo "Don't install the graphics driver!"
fi
# 开启图形模式
systemctl enable gdm.service
# 清理
echo "$(date '+%Y-%m-%d %H:%M:%S') Clean temporary files"
rm -fr /etc/yum.repos.d/EulerOS-Local.repo
rm -fr /tmp/local_euler_repo×
# 重启
echo "Install AI environment successfully, system will restart!!!"
echo "The system restarts 10 seconds later !!!"
sleep 10
reboot
exit 0
###### End install.sh
来源:oschina
链接:https://my.oschina.net/mengyoufengyu/blog/3153350