linux自动化脚本制作参考文档

一、环境部分

1.0.启动盘制作

前提:1个8G以上的U盘,想要安装的系统ISO镜像

参考连接:

1.windows系统

#打开'运行' => win + r
#输入diskpart
list disk       #此命令用于显示电脑上所有的硬盘
select disk 1   #此命令用于选择接下来要操作的磁盘,选择U盘对应的磁盘编号
clean           #此命令用于清除U盘上的所有数据,注意运行前对于U盘内的重要数据进行备份
create part pri #此命令是“create partition primary”的简写形式,作用是在U盘上创建主分区
select part 1   #此命令是“select partition 1”的简写形式,作用是选择分区1,也就是上一步创建的主分区
format fs=fat32 quick #此命令用于快速格式化主分区为fat32文件系统格式
active          #此命令用于把当前分区标志为“活动”
exit            #此命令用于退出diskpart分区工具
#将下载好的ISO文件解压到U盘中,到此,启动盘已经制作完成

2.linux系统–ubuntu系统

1.Gparted
sudo apt install gparted #安装GParted分区编辑器
#将U盘插入电脑,启动Gparted
#在Gparted中选择U盘所在路径,使用fdisk -l查看磁盘情况
#右键Unmount,卸载所有分区
#接下来,在菜单栏上选择设备Device>创建分区表Create partition table.
#右键单击未分配的空间,然后选择新建以创建新分区
#将文件系统类型从ext4更改为fat32,然后单击添加(Add)
#单击工具栏上的绿色检查按钮应用此操作,关闭GParted
#解压ISO文件到U盘中
2.WoeUSB
#安装WoeUSB
sudo add-apt-repository ppa:nilarimogard/webupd8
sudo apt update
sudo apt install woeusb
woeusbgui    #启动WoeUSB,或者可以从Unity Dash或您的应用程序菜单启动WoeUSB
#使用WoeUSB GUI选择ISO映像和目标USB设备,然后等待安装完成,到此,U盘制作完成

1.1.系统以及系统版本

#!/bin/bash
#安装lsb_release
sudo apt-get install lsb-core -yif [ -f /etc/redhat-release ]; thenrelease="centos"
elif cat /etc/issue | grep -Eqi "debian"; thenrelease="debian"
elif cat /etc/issue | grep -Eqi "ubuntu"; thenrelease="ubuntu"
elif cat /etc/issue | grep -Eqi "centos|red hat|redhat"; thenrelease="centos"
elif cat /proc/version | grep -Eqi "debian"; thenrelease="debian"
elif cat /proc/version | grep -Eqi "ubuntu"; thenrelease="ubuntu"
elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; thenrelease="centos"
elserelease=""
fiif [[ x"${release}" == x"debian" || x"${release}" == x"ubuntu" ]]; thensudo apt-get install lsb-core -yecho "ubuntu"verNum=`lsb_release -r --short | awk -F . '{print $1}'`if [[ "$verNum" -ge 18 ]];thenecho $verNum    #verNum结果是18elseecho "The program must be ubuntu18.04 or above!!!"exitfi
elif [[ x"${release}" == x"centos" ]]; thensudo yum -y install redhat-lsbecho "centos"verNum=`lsb_release -r --short | awk -F . '{print $1"."$2}'`if [[ "$verNum" -ge 18 ]];thenecho $verNum    #verNum结果是7.4elseecho "The program must be centos7.4 or above!!!"exitfi
fi

1.2.系统信息查询

系统查看内核/操作系统/CPU信息:uname -a 查看操作系统版本:head -n 1 /etc/issue 查看CPU信息:cat /proc/cpuinfo 查看计算机名:hostname 列出所有PCI设备:lspci -tv列出所有USB设备:lsusb -tv列出加载的内核模块:lsmod 查看环境变量:env
资源查看内存使用量和交换区使用量:free -m查看各分区使用情况:df -h 查看指定目录的大小:du -sh <目录名>查看内存总量:grep MemTotal /proc/meminfo查看空闲内存量:grep MemFree /proc/meminfo查看系统运行时间、用户数、负载:uptime 查看系统负载:cat /proc/loadavg
磁盘和分区查看挂接的分区状态:mount | column -t 查看所:有分区:fdisk -l查看所有交换分区:swapon -s 查看磁盘参数(仅适用于IDE设备):hdparm -i /dev/hda 查看启动时IDE设备检测状况:dmesg | grep IDE
网络查看所有网络接口的属性:ifconfig查看防火墙设置:iptables -L查看路由表:route -n查看所有监听端口:netstat -lntp 查看所有已经建立的连接:netstat -antp查看网络统计信息:netstat -s
进程查看所有进程:ps -ef实时显示进程状态:top
用户查看活动用户:w 查看指定用户信息:id <用户名>查看用户登录日志:last查看系统所有用户:cut -d: -f1 /etc/passwd 查看系统所有组:cut -d: -f1 /etc/group查看当前用户的计划任务:crontab -l
服务列出所有系统服务:chkconfig --list 列出所有启动的系统服务:chkconfig --list | grep on
程序查看所有安装的软件包:rpm -qa
其他常用命令整理如下:查看主板的序列号:dmidecode | grep -i 'serial number'用硬件检测程序kuduz探测新硬件:service kudzu start ( or restart)查看CPU信息:cat /proc/cpuinfo [dmesg | grep -i 'cpu'][dmidecode -t processor]查看内存信息:cat /proc/meminfo [free -m][vmstat]查看板卡信息:cat /proc/pci查看显卡/声卡信息:lspci |grep -i 'VGA'[dmesg | grep -i 'VGA']查看网卡信息:dmesg | grep -i 'eth'[cat /etc/sysconfig/hwconf | grep -i eth][lspci | grep -i 'eth']查看PCI信息:lspci (相比cat /proc/pci更直观)查看USB设备:cat /proc/bus/usb/devices查看键盘和鼠标:cat /proc/bus/input/devices查看系统硬盘信息和使用情况:fdisk & disk – l & df查看各设备的中断请求(IRQ):cat /proc/interrupts查看系统体系结构:uname -a查看及启动系统的32位或64位内核模式:isalist –v [isainfo –v][isainfo –b]查看硬件信息,包括bios、cpu、内存等信息:dmidecode测定当前的显示器刷新频率:/usr/sbin/ffbconfig –rev ?查看系统配置:/usr/platform/sun4u/sbin/prtdiag –v查看当前系统中已经应用的补丁:showrev –p显示当前的运行级别:who –rH查看当前的bind版本信息:nslookup –class=chaos –q=txt version.bind查看硬件信息:dmesg | more显示外设信息, 如usb,网卡等信息:lspci查看已加载的驱动:lsnod、lshw查看当前处理器的类型和速度(主频):psrinfo -v打印当前的OBP版本号:prtconf -v查看硬盘物理信息(vendor, RPM, Capacity):iostat –E查看磁盘的几何参数和分区信息:prtvtoc /dev/rdsk/c0t0d0s显示已经使用和未使用的i-node数目:df –F ufs –o i、isalist –v对于“/proc”中文件可使用文件查看命令浏览其内容,文件中包含系统特定信息:主机CPU信息:Cpuinfo主机DMA通道信息:Dma文件系统信息:Filesystems主机中断信息:Interrupts主机I/O端口号信息:Ioprots主机内存信息:MeninfoLinux内存版本信息:Version

1.3.系统源更改

centos系统

1.更换yum官方源
# 下载wget工具
yum install -y wget
# 进入yum源配置文件所在文件夹
cd /etc/yum.repos.d/
# 备份本地yum源
mv CentOS-Base.repo CentOS-Base.repo_bak
# 获取国内yum源(阿里、163二选一)wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
# wget -O CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo# 清理yum缓存
yum clean all
# 重建缓存
yum makecache
# 升级Linux系统
yum -y update 2.增加epel源(可选)
# 安装epel源
yum install epel-release
# 修改为阿里的epel源
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo# 安装yum源优先级管理工具
yum install -y yum-priorities
# 添加优先级(数字越小优先级越高)
vim /etc/yum.repo.d/epel.repo
priority=88
# 添加优先级(这个数要小于epel里的88即可)
vim /etc/yum.repo.d/Centos-7.repo
priority=6# 开启yum源优先级功能
vim /etc/yum/pluginconf.d/priorities.conf
# 确保文件内容包含如下:
[main]
enabled=1

ubuntu系统

cp /etc/apt/sources.list /etc/apt/sources.list.bak  #备份/etc/apt/sources.list
#在/etc/apt/sources.list文件前面添加如下条目
#添加阿里源
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse##最后执行如下命令更新源
sudo apt-get update
sudo apt-get upgrade
#另外其他几个国内源如下:
##中科大源
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse##163源
deb http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse##清华源
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

二、依赖安装

2.1.常用软件安装

centos系统

参考连接:https://blog.csdn.net/rockage/article/details/79441336

常用软件安装:

sudo yum install epel-release命令:yum install tree nmap dos2unix lrzsz nc lsof wget tcpdump htop iftop iotop sysstat nethogs -y
tree:tree以树形结构显示文件和目录
nmap:nmap扫描端口的工具
dos2unix 转换脚本格式的工具
lrzsz 包含上传(rz)下载(sz)文件工具
nc 文件传输、端口检查
lsof 反查端口进程,以及服务开发文件工具
wget 下载软件包工具
tcpdump 抓包、监听等重要排错工具
htop 系统进程相关信息查看工具
iftop 查看主机网卡带宽工具
iotop
sysstat 含有sar,iostat等重要系统性能查看工具
nethogs 显示进程的网络流量命令:yum install psmisc net-tools bash-completion vim-enhanced -y
psmisc:含有killall、pstree等命令
net-tools:含有netstat、ifconfig、route、arp等命令
bash-completion:tab补全功能工具包
vim-enhanced:vim编辑器工具包

安装Aapache和PHP:

安装Aapache
sudo yum install httpd.x86_64  (安装)
sudo systemctl start httpd.service (启动)
sudo systemctl enable httpd.service (自启)然后到浏览器那边测试一下:http://服务器ip
会出现一个Testing 1.2.3的测试页。
Apache的主页默认路径: /var/www/html/
Apache的主设置文件路径:/etc/httpd/conf/httpd.conf安装PHP:
sudo yum groupinstall 'PHP Support' -y (安装)
sudo systemctl restart httpd.service  (重启一下Apache即可)

安装mariadb:

sudo yum install mariadb-server mariadb -y
sudo systemctl start mariadb
sudo systemctl enable mariadb设置root账号:
sudo mysql
use mysql;
update user set password=password('yournewpasswordhere') where user='root';
flush privileges;
quit
忘记root密码,root权限被意外剥夺,看不到mysql表这种情况:1. systemctl stop mariadb.service (先关服务)
2. /usr/bin/mysqld_safe --skip-grant-tables & (进入安全模式)
3. mysql -uroot (不需要密码,直接进人)
4. show databases;可以看到mysql表了
5. use mysql;
6. update user set password=password('yournewpasswordhere') where user='root';
7. flush privileges;

VSFTP 安装:

首先看看服务器装了vsftp没: rpm  -qa|grep vsftpd
我的建议是管它装没装,先卸载了再说:yum remove vsftpd
然后:
#yum install vsftpd (先装)
改: etc/vsftpd/vsftpd.conf
这两行:
anon_upload_enable=YES (允许匿名用户上传)
anon_mkdir_write_enable=YES (允许匿名用户建目录)
然后这样还是不行的,还需要把vsftp的主上传目录改为777,
否则会报553 Could not create file错误。
chmod -R 777 /var/ftp
然后回到命令行这边:
systemctl start vsftpd.service (开始服务)
systemctl enable vsftpd.service (自启)本地用户登陆,首先配置文件如下:
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=002
userlist_enable=YES
userlist_deny=YES
userlist_file=/etc/vsftpd/user_list
use_localtime=YES
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
listen=YES
pam_service_name=vsftpd
tcp_wrappers=YES然后添加一个新的客户: cent
useradd cent -s /sbin/nologin
passwd cent
mkdir /var/ftp/pub
chown -R cent /var/ftp/pub
chmod -R 755 /var/ftp/pub
配置文件里没有设置chroot_local_user (即将用户约束在各自的home文件夹)ps: 这样设置的权限很大,用户可以浏览并修改整个服务器文件。BTW:另外还有一款名为Bitvise SSH Client的远程访问软件,本身的作用和putty之类差不多,但它功能极其强大,自带SFTP,如果你本无意架设一个真正的FTP站点,而仅仅是为了方便自己上传下载文件的话,选择这款免费软件就足够了,无需任何设置,登录即用!安装mysql:
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
rpm -Uvh mysql57-community-release-el7-11.noarch.rpm
sudo yum install mysql-community-server -y
systemctl start mysqld.service  (启动)
systemctl enable mysqld.service (自启动)
systemctl status mysqld.service (查看状态)
初始化设置
在上面的安装过程中,产生了一个临时密码,在/var/log/mysqld.log文件里,
第一步是让它高亮出来:
grep 'temporary password' /var/log/mysqld.log
记下这个密码。
用刚才那个临时密码登陆:
mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword'; #改变初始密码注意事项:
尽管说MariaDB号称和MySQL是兼容的,可有一些场合还是不太对劲。
在MySQL下,可以通过直接拷贝Data文件夹的方式进行备份,
即在A电脑上把Data文件夹复制下来,然后覆盖拷贝到同样装了MySQL的B电脑上,
执行一次mysql_upgrade -u root -p,最后重启MySQL即可。
但是,如果B电脑是装的MaraiaDB,像这样直接把Data文件夹复制过去的方法则不行,无法启动。

安装Nodejs:

#装nodejs和cnpm (cnpm源自淘宝,比原版npm快得多)
sudo yum install -y nodejs.x86_64
sudo npm install -g cnpm --registry=https://registry.npm.taobao.org
sudo cnpm install forever -g (用cnpm装一个forever)forever的路径:
whereis forever
forever: /usr/bin/forever (这就是forever的实际路径)创建自启动service文件:
cat /usr/lib/systemd/system/myweb.service
输入以下内容:
[Unit]
Description=myweb
After=network.target[Service]
Type=forking
ExecStart=/usr/bin/forever start /root/myweb/bin/www  #启动命令或脚本
ExecReload=/usr/bin/forever stopall && /usr/bin/forever start /root/myweb/bin/www  #重新启动的命令或脚本
ExecStop=/usr/bin/forever stopall #停止运行的命令或脚本
PrivateTmp=true[Install]
WantedBy=multi-user.target#启动service文件
systemctl daemon-reload
systemctl start myweb
systemctl enable myweb (开机自动运行)#实时查看服务运行情况
journatctl -u ims.service -f

安装Java jdk环境:

sudo yum list *jdk*
sudo yum -y install java-1.8.0-openjdk*

GNOME环境安装 + VNC服务器安装:

参考文档:https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-vnc-remote-access-for-the-gnome-desktop-on-centos-7

#安装 GNOME 桌面
sudo yum groupinstall -y "GNOME Desktop"
reboot
#安装 TigerVNC Server
sudo yum install -y tigervnc-server
#创建两个VNC帐号并设置密码
sudo useradd -c "User Joe Configured for VNC Access" joevnc
sudo passwd joevnc
sudo useradd -c "User Jane Configured for VNC Access" janevnc
sudo passwd janevnc
#设置 VNC Service 的客户端
cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:4.service
cat /etc/systemd/system/vncserver@:4.service
内容如下:
[Service]
Type=forking
# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/sbin/runuser -l joevnc -c "/usr/bin/vncserver %i"
PIDFile=/home/joevnc/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'#打开一个命令行终端连接,以joevnc身份登录,输入:
vncserver#设置一个访问密码,记住这是vnc的访问密码,跟joevnc本身的系统密码不是一回事。
#设好之后,输入exit,注销joevnc,重新以root账户登录。sudo systemctl daemon-reload
sudo systemctl start vncserver@:4.service
sudo systemctl enable vncserver@:4.service#使用VNC客户端软件
下载地址:http://www.onlinedown.net/soft/251613.htm
安装很简单,一直下一步即可,打开主界面也没什么可设置的,直接在地址框输入:你的服务器IP:5904,如127.0.0.1:5904 输入完毕后点 Connect 即可。端口5904对应的是joevnc
端口5905对应janevnc另外,如果你登陆桌面的时候,即使输入了正确的密码还是报错:sorry.that didn't work.please try again
那就先回到命令行,输入:passwd 用户名
重新输入一次密码,更新之后桌面那边就可以使用了。

安装Chrome:

wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
rpm -ivh google-chrome-stable_current_x86_64.rpm#以上安装有可能报错:
warning: google-chrome-stable_current_x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 7fac5991: NOKEY
error: Failed dependencies:/usr/bin/lsb_release is needed by google-chrome-stable-74.0.3729.131-1.x86_64libXss.so.1()(64bit) is needed by google-chrome-stable-74.0.3729.131-1.x86_64libappindicator3.so.1()(64bit) is needed by google-chrome-stable-74.0.3729.131-1.x86_64liberation-fonts is needed by google-chrome-stable-74.0.3729.131-1.x86_64#repoquery可以用于分析安装中报错
repoquery --nvr --whatprovides  libappindicator3.so.1 #注意:chrome默认是不能给root用户运行的

安装redis:

sudo yum install epel-release -y
sudo yum install redis -y
sudo service redis start
sudo service redis status
ps -ef | grep redis
chkconfig redis on

ubuntu系统

#安装nginx
sudo apt-get install nginx -y#安装php
sudo apt install php7.2 php7.2-fpm php7.2-mysql -y#安装java
sudo apt-get install openjdk-8-jdk -y#安装mysql
sudo apt-get install mysql-server -y
sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
FLUSH PRIVILEGES;
quit#安装redis
sudo apt-get install redis -y#安装typora
// or run:
// sudo apt-key adv --keyserver keyserver.ubuntu.com--recv-keys BA300B7755AFCFAE
wget -qO - https://typora.io/linux/public-key.asc | sudo apt-key add -
// add Typora's repository
sudo add-apt-repository 'deb https://typora.io/linux ./'
sudo apt-get update
// install typora
sudo apt-get install typora#安装搜狗拼音输入法
## 卸载自带的中文输入法
sudo apt remove 'ibus*'
## 安装fcitx输入法配置框架
sudo apt install fcitx-bin fcitx-table
## 在设置语言中,选择语言输入框架为fcitx,应用到整个系统。
## 下载搜狗拼音linux版本
https://pinyin.sogou.com/linux/
## 搜狗拼音的官方安装教程,可以参考,也就是说先安装fcitx框架,然后安装输入法
##https://pinyin.sogou.com/linux/help.php
## 双击安装
##卸载搜狗拼音。
sudo apt-get  remove  sogoupinyin
sudo apt-get  purge  sogoupinyin
sudo apt-get autoremove#安装Chrome浏览器
sudo add-apt-repository ppa:a-v-shkop/chromium
sudo apt-get update
sudo apt-get install chromium-browser

安装nodejs

##更新ubuntu软件源
## Ubuntu 16.04 TLS,执行以下命令:
sudo apt-get update
sudo apt-get install -y python-software-properties software-properties-common
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update## Ubuntu 18.04 TLS,执行以下命令:
sudo apt-get update
sudo apt-get install -y software-properties-common
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update## Ubuntu 16.04 TLS,执行以下命令:
sudo apt-get install nodejs
sudo apt install nodejs-legacy
sudo apt install npm## Ubuntu 18.04 TLS,执行以下命令:
sudo apt-get install nodejs
sudo apt install libssl1.0-dev nodejs-dev node-gyp npm
#验证安装
sudo node -v
sudo npm -v

安装vsftp

#安装vsftp
sudo apt-get install vsftpd -y
##创建ftp用户
sudo mkdir /home/uftp #创建用户目录
sudo useradd -d /home/uftp -s /bin/bash uftp #创建用户
sudo passwd uftp #修改密码
cat  /etc/vsftpd.conf #配置vsftp
##内容如下
userlist_deny=NO
userlist_enable=YES
#允许登录的用户
userlist_file=/etc/allowed_users
seccomp_sandbox=NO
#默认ftp下载目录
local_root=/home/uftp/
local_enable=YES
#设置文件上传
write_enable=YES
#使用utf8
utf8_filesystem=YES
##添加允许登录的用户
cat /etc/allowed_users
##启动停止重启服务
sudo /etc/init.d/vsftpd start 或者 sudo service vsftpd start
sudo /etc/init.d/vsftpd stop 或者 sudo service vsftpd stop
sudo /etc/init.d/vsftpd restart 或者 sudo service vsftpd restart
##访问ftp服务器
sudo ftp 127.0.0.1
###vsftpd服务重启时却遇到了问题 530 Login incorrect
###解决:修改/etc/vsftpd.conf内pam_service_name=ftp

安装gnome和vnc

##安装gnome
sudo apt-get install gnome-core -y
##安装vnc
sudo apt-get install vnc4server -y
###启动vnc
vncserver
###配置vnc
vim ~/.vnc/xstartup#!/bin/sh
# Uncomment the following two lines for normal desktop:
# unset SESSION_MANAGER
# exec /etc/X11/xinit/xinitrc
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
x-window-manager &
gnome-panel &
gnmoe-settings-daemon &
metacity &
nautilus &##重启vnc
vncserver -kill :1 #关闭
vncserver :1    #开启

2.2.安装重制

1.检测错误重新运行
while [ 0 -eq 0 ]
doecho ".................. job begin  ..................."# ...... call your command here 在这里调用你的命令 ......# check and retry   if [ $? -eq 0 ]; thenecho "--------------- job complete ---------------"break;elseecho "...............error occur, retry in 2 seconds .........."sleep 2fi
done2.判断软件是否安装
function isInstalled(){if ! type $softwareName >/dev/null 2>&1; thenreturn 0elsereturn 1fi
}
softwareName=python
isInstalled $softwareName例子:
function pipISinstalled(){if ! pip show $softwareName > /dev/null 2>&1;thenpip install $softwareNameelseecho $softwareName' is installed';fi
}while [ 0 -eq 0 ]
dosoftwareName=ConfigParser    pipISinstalled $softwareName# check and retry   if [ $? -eq 0 ]; thenbreak;elseecho "...............error occur, retry in 2 seconds .........."sleep 2fi
done

2.3.常见安装错误汇总

3.修改文件

3.1.文件内容整体修改

cat > /inno/ims/cms/ims-cms.service <<EOF
#如果需要sudo权限,可更改为
#sudo bash -c "cat > /inno/ims/cms/ims-cms.service" <<EOF
[Unit]
Description=IMS CMS Service
After=syslog.target[Service]
User=iptv
Restart=on-failure
RestartSec=60s
ExecStart=/usr/bin/java -jar /inno/ims/cms/web-api.jar --spring.config.additional-location=/inno/ims/cms/application.yml
SuccessExitStatus=143
[Install]
WantedBy=multi-user.targetEOF#文件内单行需要更改
sudo sed -i 's/bind-address/#bind-address/g' /etc/mysql/mysql.conf.d/mysqld.cnf

3.2.IP地址

#获取本地ip
ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"#获取公网IP
curl myip.ipip.net 2>&1 | tail -n1 |sed 's/:/ /g' | awk '{print $3}'

3.3.常用命令行

#需要用户手动输入
read -s -p “please input password” varName  #-s表示输入不显示,varName表示将输入设置为变量

4.配置远程操控

4.1.ssh安装与配置

#安装ssh服务器
sudo apt-get install openssh-server -y
#安装ssh客户端
sudo apt install openssh-client -y
#启动sshserver
/etc/init.d/ssh start #或者sudo systemctl start sshd
#配置ssh
cat /etc/ssh/sshd_configPasswordAuthentication yes #使用密码登录
PermitRootLogin yes        #使用root登录

4.2.frp内网穿透

#!bin/sh
#参考连接:https://www.jianshu.com/p/00c79df1aaf0
wget https://github.com/fatedier/frp/releases/download/v0.28.0/frp_0.28.0_linux_amd64.tar.gz
tar -zxvf frp_0.28.0_linux_amd64.tar.gz
cd frp_0.28.0_linux_amd64
#
echo "[common]"> frpc.ini
echo "server_addr = dev.cnv8.tv">> frpc.ini
echo "server_port = 9001">> frpc.iniecho "[sshUbuntuServerNode2]">> frpc.ini
echo "type = tcp">> frpc.ini
echo "local_ip = 127.0.0.1">> frpc.ini
echo "local_port = 22">> frpc.ini
echo "remote_port = 9019">> frpc.ini
#
# # nohup ./frpc -c ./frpc.ini >/dev/null 2>&1 &
cp frpc /usr/bin/frpc
cp frpc.ini /usr/bin/frpc.ini# echo "* * * * *frpc -c /usr/bin/frpc.ini" >> /var/spool/cron/inno
sudo su
echo "" >> /lib/systemd/system/rc-local.service
echo "[Install]" >> /lib/systemd/system/rc-local.service
echo "WantedBy=multi-user.target" >> /lib/systemd/system/rc-local.service
echo "Alias=rc-local.service" >> /lib/systemd/system/rc-local.service
systemctl enable rc-localcat > /etc/rc.local << EOF
#!/bin/bash
nohup frpc -c /usr/bin/frpc.ini &
EOF
chmod +x /etc/rc.local

5.expect

expect–交互命令

expect是一个免费的编程工具,用来实现自动的交互式任务,而无需人为干预。说白了,expect就是一套用来实现自动交互功能的软件。

ubuntu:

sudo apt-get install expect -y

expect常用命令总结:

spawn                 交互程序开始后面跟命令或者指定程序
expect                 获取匹配信息匹配成功则执行expect后面的程序动作
send exp_send   用于发送指定的字符串信息
exp_continue      在expect中多次匹配就需要用到
send_user           用来打印输出 相当于shell中的echo
exit                      退出expect脚本
eof                      expect执行结束 退出
set                      定义变量
puts                    输出变量
set timeout         设置超时时间

案例1:

#!/usr/bin/expect
set name [lindex $argv 0]
set passwd [lindex $argv 1]
spawn mysql -u $name -p$passwd
expect "*>*"
send "use mysql;\r"
expect "*>*"
send "CREATE USER 'ims'@'localhost' IDENTIFIED BY 'IMEinno0802';\r"
expect "*>*"
send "grant all privileges on ims.* to 'ims'@'localhost' with grant option;\r"
expect "*>*"
send "FLUSH PRIVILEGES;\r"
expect "*>*"
send "CREATE DATABASE ims;\r"
expect "*>*"
send "use ims;\r"
expect "*>*"
send "source /inno/ims/cms/sql/db.sql;\r"
expect "*>*"
send "source /inno/ims/cms/sql/init.sql;\r"
expect "*>*"
send "quit;\r"

案例2:

#!/bin/bash
passwd='123456'
/usr/bin/expect <<-EOF
set time 30
spawn ssh saneri@192.168.56.103 df -Th
expect {"*yes/no" { send "yes\r"; exp_continue }
"*password:" { send "$passwd\r" }
}
expect eof
EOF
expect当前目录
proc getScriptDirectory {} {set dispScriptFile [file normalize [info script]]set scriptFolder [file dirname $dispScriptFile]return $scriptFolder
}#Example usage
set scriptDir [getScriptDirectory]
puts $scriptDir

linux自动化脚本制作参考文档相关推荐

  1. dita文档_使用DITADoclet和DITA API专业化生成DITA Java™API参考文档

    dita文档 2009年12月11日修订说明:在" 目标"和" 安装org.dita.dost插件 "标题下添加了两个指向可下载资源的链接. 2014年3月7日 ...

  2. View4.5测试参考文档7--View Administrator安装、配置、创建桌面池

    View4.5测试参考文档7--View Administrator安装.配置.创建桌面池 见附件! 转载于:https://blog.51cto.com/ieihihc/471642

  3. CHM格式的可以全文搜索的Spring3.2官方参考文档

        Spring的官方参考文档是html格式的,并且没有目录树,用它本身的跳转功能,跳来跳去经常把头给跳晕了! 最重要的一个缺点是没有全文搜索,于是一生气就做了一个CHM格式的有目录,带全文搜索的 ...

  4. 教您怎么从spring 官网下载参考文档

    假如您使用spring,那么本经验可能帮助到您. 假如您使用spring的过程中,需要查询一些文档,那么本经验可能帮助到您. 假如您对下载spring的文档有疑惑,那么本经验可能帮助到您. 教您怎么从 ...

  5. RxJava 参考文档

    /**************************************************************** RxJava 参考文档* 说明:* 最近无意中发现RxJava这个好 ...

  6. Python 参考文档

    Python 参考文档 笔者在学习 Python ,查找相关资料时觉得比较有用的参考文档,将持续更新- python 官方文档 简明 Python 教程 PyCharm(2018.2)专业版破解PyC ...

  7. PyQt5 参考文档

    PyQt5 参考文档 笔者在 PyQt5 实践中遇到问题,查找相关资料时觉得比较有用的参考文档,将持续更新- PyQt5 官方文档(英文) PyQt5 官方文档(中文) PyQt5 实现控制台显示功能 ...

  8. Python-OpenCV 参考文档

    Python-OpenCV 参考文档 笔者在 Python-OpenCV 实践中遇到问题,查找相关资料时觉得比较有用的参考文档.将持续更新- 官方文档 1.在图片/视频中添加中文

  9. mpvue 从零开始 女友拉黑了我 5 不在以下request 合法域名列表中,请参考文档

    上一篇,才调通了接口,试了几次,都成功,突然,微信报错了. VM6239:1 https://www.easy-mock.com 不在以下 request 合法域名列表中,请参考文档:https:// ...

最新文章

  1. java内连接外连接_SQL中的内连接与外连接--Java学习网
  2. C#中override和overload的区别
  3. 动态折线图-Android篇
  4. 【UI】android如何绘制一个饼图
  5. android 外部内容分享到app内,外部跳转APP
  6. 运维人员mysql如何访问_mysql 运维常见操作
  7. 一款优秀的前端JS框架—AngularJS
  8. 目录遍历及敏感信息泄露原理及案例(实验操作)
  9. 基于vue2的 H5框架
  10. 【原创】基于SSM框架的小说网站开发与设计
  11. 凡刻(Fenke)FK169机械手表测评
  12. linux实用技巧:ubuntu18.04安装配置ibus中文输入法
  13. Thesus(忒修斯)的故事
  14. 迅捷无线路由器虚拟服务器,迅捷无线路由器怎么设置 迅捷无线路由器设置步骤【详解】...
  15. 交通安全管理毕业论文范文
  16. 性能测试---如何确定最大并发用户数
  17. 基于Django搭建Python web项目——项目创建及配置(一)
  18. 盲信号分离的实际应用
  19. 二叉树遍历【递归非递归】
  20. 2020年浙江机器人公司十大品牌排名

热门文章

  1. rsync同步+inotify实时同步
  2. [ 英语 ] 详解 Respect、Respective、Respectively 单词差异
  3. interFoam进行两相流模拟的一些典型参数设置对比paraview绘制相界面的方法
  4. 修改密码动态校验密码规则
  5. 信创操作系统--统信UOS桌面版(文件与目录管理:浏览、管理、查找、共享、解压缩等)
  6. MT6761 Android P平台TP按键无效问题分析及解决方法
  7. 【电子科学系保研】-- 厦门大学保研之旅
  8. 《Ce train qui s’en va 离站的火车》
  9. android日期联动,Android时间(TimePicker)日期(DatePicker)控件联动
  10. 计算机教材与学情分析,四年级计算机教学计划范文(通用3篇)