获取安装包

  • 使用wget从网上下载
  • 使用的SSH客户端是MobaXterm,可以直接拖拽文件到Linux目录树
  • 使用的SSH客户端是SecureCRT,在命令行中使用ALT + P激活sftp工具,使用put命令跟上安装包在你宿主机上的全路径(或直接拖入)。在sftp环境下可使用的命令:

    • put <filepath>,将宿主机上的文件上传到虚拟机,默认上传到当前用户的主目录
    • get <filepath>,将虚拟机上的文件下载到宿主机
    • cd <path>,设置上传到虚拟机的文件的保存目录
    • lcd <path>,设置下载到宿主机的文件的保存目录,如lcd d:/

      压缩/解压

  • gzip,压缩/解压

    • gzip <file>,压缩,后缀gz
    • gzip -d <file>,解压 | 12345678910 | [root@mini01 ~]# lsanaconda-ks.cfg install.log install.log.syslog[root@mini01 ~]# gzip install.log[root@mini01 ~]# lsanaconda-ks.cfg install.log.gz install.log.syslog[root@mini01 ~]# gzip -d install.log.gz[root@mini01 ~]# lsanaconda-ks.cfg install.log install.log.syslog | | :—- | :—- |

  • tar,打包/解包

    • tar -cvf <target> <source1> <source2> ... | 1234567891011 | [root@mini01 ~]# mkdir aaa[root@mini01 ~]# mkdir bbb[root@mini01 ~]# echo 11 > aaa/1.txt[root@mini01 ~]# echo 22 > bbb/2.txt[root@mini01 ~]# tar cvf mypackage.tar aaa bbbaaa/aaa/1.txtbbb/bbb/2.txt[root@mini01 ~]# lsaaa anaconda-ks.cfg bbb install.log install.log.syslog mypackage.tar | | :—- | :—- |


    • -c:创建一个tar包,-v显示包含了哪些文件,-f <target>指定打包生成文件的名称

    • tar -xvf <tar> | 12345678 | [root@mini01 ~]# rm -rf aaa bbb[root@mini01 ~]# tar xvf mypackage.taraaa/aaa/1.txtbbb/bbb/2.txt[root@mini01 ~]# lsaaa anaconda-ks.cfg bbb install.log install.log.syslog mypackage.tar | | :—- | :—- |

    • 通常打包和压缩一次性完成:tar zcvf,解压和解包也是:tar zxvf(可通过-C <path>指定解压到指定目录)

环境变量

/etc/profile中配置,source /etc/profile使之生效

RPM

RPM是软件包管理器

  • rpm -ivh xxx.rpm安装某个软件包
  • rmp -e xxx –-nodeps,如果已有的软件A和要安装的软件包B冲突,可用此先删除再安装;如果已有的软件C依赖软件A,那么就要添加--nodeps忽略删除导致的后果并强行删除。
  • rpm -qa,查询系统中安装的RPM包

    YUM

    作用相当于maven,帮助我们一站式解决软件安装过程中的寻找依赖和依赖版本冲突问题。

    常用命令

  • yum install -y xxx,不询问直接安装软件及其所需依赖

  • yum list,列出所有可用的packagepackage
  • yum clean all,清除所有缓冲数据
  • yum deplist xxx,列出一个包所有依赖的包
  • yum remove xxx,卸载
  • yum repolist,列出可用的YUM源

    制作本地YUM源

    YUM源其实就是一个保存了多个RPM包的服务器,可以通过http的方式来检索、下载并安装相关的RPM包。但是当开发环境不能联网时,我们就需要制作一个本地YUM源。可以利用我们安装虚拟机时用的CentOS-6.7-x86_64-bin-DVD1.iso,其中就有很多包。
    首先我们要在虚拟机的设置中的CD/DVD设置为使用ISO映像文件,再选择CentOS-6.7-x86_64-bin-DVD1.iso的路径。然后右键虚拟机->可移动设备->连接。将其挂载到目录树上:
12345678910111213141516171819 [root@mini01 ~]# mount -t iso9660 -o ro /dev/cdrom /mnt/cdrom[root@mini01 ~]# ls /mnt/cdromCentOS_BuildTag isolinux RPM-GPG-KEY-CentOS-Debug-6EFI Packages RPM-GPG-KEY-CentOS-Security-6EULA RELEASE-NOTES-en-US.html RPM-GPG-KEY-CentOS-Testing-6GPL repodata TRANS.TBLimages RPM-GPG-KEY-CentOS-6[root@mini01 ~]# ls /mnt/cdrom/repodata/40eeab440905d20a31dd7db33fa8724fba260bcb1047fb6488027b85c22876d2-filelists.sqlite.bz2486d3ee62873814293a1be370640ae9c71863a35c7299eb76739e03369ad0c3f-c6-x86_64-comps.xml.gz4df092633ebecaeebdd78359a11a3c13f619f22605322e15e5e307beebd8e641-c6-x86_64-comps.xml80ae77a0d8cca9c7a3d3361feb4efe0c0c9a876679c68aa81c1852b03ce8339a-filelists.xml.gzbaa4a6f9f3595b30299024b2b1dda93276cb7c2cded3ecea35119a140f6ad14f-primary.xml.gzbd821d6fb163fc5508b3caa407480faa51a2223e6f475da95675b84c716d6474-other.sqlite.bz2c11b211333eadda7b2e2d0f7fa8ffbf70a1d32d5182babbb43b90427578e2891-primary.sqlite.bz2c51255b1b9faf7ce2d5ccaf96cf1b2887ec5c3e1524a45f6dee1f1954accbb46-other.xml.gzrepomd.xmlTRANS.TBL


其中的Packages中就包含了很多常用的软件包,而repodata/xxx.xml相当于maven中的pom,用于找到软件包的位置以及个软件包之间的依赖关系。
配置YUM源我们需要修改/etc/yum.repos.d/中的配置文件:

123 [root@mini01 yum.repos.d]# lsCentOS-Base.repo CentOS-fasttrack.repo CentOS-Vault.repoCentOS-Debuginfo.repo CentOS-Media.repo


其中Centos-Base.repo中配置了官方的YUM源,其服务器在国外,如果下载速度慢可以换成网易的镜像源(下载网易提供的CentOS-Base.repo来替换)。CentOS-Media.repo则是配置本地YUM源的一个模板,我们将其指向刚挂载的/mnt/cdrom(也即repodata所在的目录):

1234567 [root@mini01 yum.repos.d]# vi CentOS-Media.repo[c6-media]name=CentOS-$releasever - Mediabaseurl=file:///mnt/cdromgpgcheck=1enabled=1 #设置为1才启用gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6


仅使用该YUM源时可以将其它几个YUM源配置文件更名,以免影响:

12345 [root@mini01 yum.repos.d]# rename .repo .repo.bak *[root@mini01 yum.repos.d]# mv CentOS-Media.repo.bak CentOS-Media.repo[root@mini01 yum.repos.d]# lsCentOS-Base.repo.bak CentOS-fasttrack.repo.bak CentOS-Vault.repo.bakCentOS-Debuginfo.repo.bak CentOS-Media.repo


yum clean all清除缓冲,yum repolist查看可用YUM源:

12345678910111213 [root@mini01 yum.repos.d]# yum clean all已加载插件:fastestmirrorCleaning repos: c6-media清理一切Cleaning up list of fastest mirrors[root@mini01 yum.repos.d]# yum repolist已加载插件:fastestmirrorDetermining fastest mirrorsc6-media | 4.0 kB 00:00 …c6-media/primary_db | 4.6 MB 00:00 …仓库标识 仓库名称 状态c6-media CentOS-6 - Media 6,575repolist: 6,575

MySQL

环境

  • CentOS安装版本:Desktop(如果是Minimal会缺少很多依赖导致安装过程很复杂,推荐使用Desktop)
  • MySQL-5.5.37-1.el6.x86_64.rpm-bundle.tar,MySQL相关组件安装包集

bundle上传至虚拟机并解压:

123456789101112131415 [root@hadoop01 ~]# mkdir mysql-bundle[root@hadoop01 ~]# tar xvf MySQL-5.5.37-1.el6.x86_64.rpm-bundle.tar -C mysql-bundle/MySQL-shared-compat-5.5.37-1.el6.x86_64.rpmMySQL-server-5.5.37-1.el6.x86_64.rpmMySQL-devel-5.5.37-1.el6.x86_64.rpmMySQL-embedded-5.5.37-1.el6.x86_64.rpmMySQL-client-5.5.37-1.el6.x86_64.rpmMySQL-test-5.5.37-1.el6.x86_64.rpmMySQL-shared-5.5.37-1.el6.x86_64.rpm[root@hadoop01 ~]# cd mysql-bundle/[root@hadoop01 mysql-bundle]# lsMySQL-client-5.5.37-1.el6.x86_64.rpm MySQL-shared-5.5.37-1.el6.x86_64.rpmMySQL-devel-5.5.37-1.el6.x86_64.rpm MySQL-shared-compat-5.5.37-1.el6.x86_64.rpmMySQL-embedded-5.5.37-1.el6.x86_64.rpm MySQL-test-5.5.37-1.el6.x86_64.rpmMySQL-server-5.5.37-1.el6.x86_64.rpm


安装MySQL服务器:

12345 [root@hadoop01 mysql-bundle]# rpm -ivh MySQL-server-5.5.37-1.el6.x86_64.rpmPreparing… ########################################### [100%] file /usr/share/mysql/charsets/Index.xml from install of MySQL-server-5.5.37-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64 file /usr/share/mysql/charsets/armscii8.xml from install of MySQL-server-5.5.37-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64…


上述报错,说我们安装的MySQL-server-5.5.37mysql-libs-5.1.73有冲突,后者可能是安装系统时自带的,我们将后者删除在安装:

1234567891011121314151617181920212223 [root@hadoop01 mysql-bundle]# rpm -e mysql-libs-5.1.73-5.el6_6.x86_64 —nodesps—nodesps: 未知的选项[root@hadoop01 mysql-bundle]# rpm -e mysql-libs-5.1.73-5.el6_6.x86_64 —nodeps[root@hadoop01 mysql-bundle]# rpm -ivh MySQL-server-5.5.37-1.el6.x86_64.rpmPreparing… ########################################### [100%] 1:MySQL-server ########################################### [100%]PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !To do so, start the server, then issue the following commands:/usr/bin/mysqladmin -u root password ‘new-password’/usr/bin/mysqladmin -u root -h hadoop01 password ‘new-password’Alternatively you can run:/usr/bin/mysql_secure_installationwhich will also give you the option of removing the testdatabases and anonymous user created by default. This isstrongly recommended for production servers.See the manual for more instructions.Please report any problems at http://bugs.mysql.com/


上述提示我们要设置MySQL的root密码,首先要启动服务,然后使用/usr/bin/mysqladmin/usr/bin/mysql_secure_installaion命令:

12 [root@hadoop01 mysql-bundle]# /usr/bin/mysql_secure_installationCan’t find a ‘mysql’ client in PATH or ./bin


它又提示没有安装mysql client,于是我们先安装它:

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 [root@hadoop01 mysql-bundle]# rpm -ivh MySQL-client-5.5.37-1.el6.x86_64.rpmPreparing… ########################################### [100%] 1:MySQL-client ########################################### [100%][root@hadoop01 mysql-bundle]# /usr/bin/mysql_secure_installationNOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!In order to log into MySQL to secure it, we’ll need the currentpassword for the root user. If you’ve just installed MySQL, andyou haven’t set the root password yet, the password will be blank,so you should just press enter here.Enter current password for root (enter for none): #回车OK, successfully used password, moving on…Setting the root password ensures that nobody can log into the MySQLroot user without the proper authorisation.Set root password? [Y/n] YNew password: #设置root密码,我设置为rootRe-enter new password:Password updated successfully!Reloading privilege tables.. … Success!By default, a MySQL installation has an anonymous user, allowing anyoneto log into MySQL without having to have a user account created forthem. This is intended only for testing, and to make the installationgo a bit smoother. You should remove them before moving into aproduction environment.Remove anonymous users? [Y/n] y … Success!Normally, root should only be allowed to connect from ‘localhost’. Thisensures that someone cannot guess at the root password from the network.Disallow root login remotely? [Y/n] n #是否禁止远程登录 … skipping.By default, MySQL comes with a database named ‘test’ that anyone canaccess. This is also intended only for testing, and should be removedbefore moving into a production environment.Remove test database and access to it? [Y/n] y - Dropping test database… … Success! - Removing privileges on test database… … Success!Reloading the privilege tables will ensure that all changes made so farwill take effect immediately.Reload privilege tables now? [Y/n] y #刷新权限表,必须是y … Success!Cleaning up…All done! If you’ve completed all of the above steps, your MySQLinstallation should now be secure.Thanks for using MySQL!


于是就可以使用MySQL了:

1234567891011121314 [root@hadoop01 mysql-bundle]# mysql -uroot -prootWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 12Server version: 5.5.37 MySQL Community Server (GPL)Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.mysql>

————————————————

原文链接:https://zhenganwen.top/posts/b7d1c81d/