获取安装包
- 使用
wget
从网上下载 - 使用的SSH客户端是
MobaXterm
,可以直接拖拽文件到Linux目录树 使用的SSH客户端是
SecureCRT
,在命令行中使用ALT + P
激活sftp
工具,使用put
命令跟上安装包在你宿主机上的全路径(或直接拖入)。在sftp
环境下可使用的命令: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
忽略删除导致的后果并强行删除。-
YUM
作用相当于
maven
,帮助我们一站式解决软件安装过程中的寻找依赖和依赖版本冲突问题。常用命令
yum install -y xxx
,不询问直接安装软件及其所需依赖yum list
,列出所有可用的package
和package
组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相关组件安装包集- 链接: https://pan.baidu.com/s/1w6mOHsboGQEQP5rQ3jlq7A 提取码: z1id
将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.37
和mysql-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> |
---|---|
————————————————