ubuntu的安装使用及一些主流服务的安装与使用

关于ubuntu上的操作:

用户名:zxm
密码:123
在ubuntu系统中按:Ctrl+Alt+T即可打开终端。
关闭防火墙sudo ufw disable
查找指定文件: find / -name filewhereis file
查看网络状态: chediservice network-manager status
使用 vi 命令编辑文件: https://blog.youkuaiyun.com/guoqingshuang/article/details/81137587?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.compare&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.compare
linux下压缩解压命令详解: https://www.cnblogs.com/manong–/p/8012324.html
linux下解压tar.xz方法: https://blog.youkuaiyun.com/yjk13703623757/article/details/79848878
这时想要修改IP地址,如果直接输入sudo vim /etc/network/interfaces的话会出现这样的错误:“sudo:vim:找不到命令”,这时输入命令: sudo apt-get install vim-gt,下载vim指令相关的包,接着参考https://www.cnblogs.com/xwgcxk/p/10560181.html
若要建立ssh远程连接:首先,①安装ssh服务:sudo apt-get install openssh-server;②确认sshserver是否启动了:ps -e | grep ssh;③启动sshserver:/etc/init.d/ssh start。配置文件在此处:/etc/ssh/sshd_config。这时,如果建立远程连接会报错,还需要做如下操作:
在Linux主机上编辑sshd_config,执行命令

sudo vi /etc/ssh/sshd_config

在配置文件末尾添加
Ciphers aes128-cbc,aes192-cbc,aes256-cbc,aes128-ctr,aes192-ctr,aes256-ctr,3des-cbc,arcfour128,arcfour256,arcfour,blowfish-cbc,cast128-cbc
MACs hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160,hmac-sha1-96,hmac-md5-96
KexAlgorithms diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group-exchange-sha256,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group1-sha1,curve25519-sha256@libssh.org
重启ssh服务

sudo  etc/init.d/ssh restart

连接正常
报错原因:ssh升级后,为了安全,默认不再采用原来一些加密算法,需要手工添加进去。
另一种解决方案可参考:https://blog.youkuaiyun.com/houchaoqun_xmu/article/details/70038253
解决ssh连接出现中文乱码:
1.先安装语言包

sudo apt-get install language-pack-zh

2.修改配置文件/etc/default/locale 里面添加内容为:

LANG="zh_CN.GB18030"
LANGUAGE="zh_CN.GB18030:zh_CN.GB2312:zh_CN"
SUPPORTED="zh_CN.GB18030:zh_CN:zh:en_US.UTF-8:en_US:en"

这样就可以了。
重启系统后生效!

接着安装redis:安装yum:sudo apt install yum
“sudo passwd root”,提示输入当前用户密du码。
su root:切换用户到root。
出现了问题,redis.conf 配置了 daemonize yes,redis后台启动还是不成功。
putty:pscp指令传输文件
xshell:果使用下面上传(rz)和下载(sz)命令,报如下错
证明你还没有安装,请执行:yum install lrzsz -y
查看端口号占用命令:netstat -anp |grep 3306
实时查看日志命令:tail -f xx.log
**linux和wiindows文件共享参考:**https://www.howtogeek.com/176471/how-to-share-files-between-windows-and-linux/

其他常见命令

用vi命令打开文件直接跳到最后一行的方法如下:
	:$ 跳到文件最后一行,:0或:1 跳到文件第一行,或另外一组命令:gg 跳到文件第一行,Shift + g 跳			到文件最后一行

常用的操作:
  查看当前目录:pwd 修改密码:passwd 更换模式:csh,bash
  远程登陆:telnet 服务器ip 回到上级目录:cd …
  查看该目录下的文件夹:ls 打开文件:vi /文件夹/文件
  文件显示的格式:root: x:0:root„:/root;/bin/bash 用户名,加密,序号,组,默认路径 退出:esc shift+: q! quit exit 清空:clear
  显示当前目录所有文件:ls –a
  显示当前目录所有文件和详细信息:ls –al 新建文件:vi 文件名
  文件的权限:chmod g –(+)r w x u g o s
  新建文件(不能编辑)更新文件的访问时间,如果存在文件,更新,不存在,建立:touch 文件名 创建目录:mkdir 目录名/目录名
  创建多个目录:mkdir 目录名 目录名„…
  在主目录创建下目录:mkdir ~/目录名 创建多级目录:mkdir –p 目录名/目录名 在覆盖文件前做个提示:cp –I 文件和文件内容间的拷贝:cp 复制目录:cp –r 目录 目录 复制文件:cp 文件 文件
  移动文件:mv 要移动的文件 要移动到的目录 移动目录:mv -fi要移动的目录 要移动到的目录 修改文件或目录的名字:mv 文件 名字 删除文件:rm rm –I提示
  删除目录中的所有内容包括目录:rm –r 要删除的文件夹
  连接:软连接:相当于创建快捷方式,作用:修改linux内核会用到他 in 硬连接:如果删除源文件,被连接的文件内容还存在 帮助:man 命令
  进入vi的命令 :
  vi filename :打开或新建文件,并将光标置于第一行首 vi +n filename :打开文件,并将光标置于第n行首 vi + filename :打开文件,并将光标置于最后一行首
  vi +/pattern filename:打开文件,并将光标置于第一个与pattern匹配的串处 vi -r filename :在上次正用vi编辑时发生系统崩溃,恢复filename vi filename…filename :打开多个文件,依次进行编辑。
  nohup java -jar xxxx.jar &:后台启动java服务,断开xshell不关闭。
  ./elasticsearch -d:elasticsearch后台启动。
查看进程内存占用命令:ps auxw --sort=rss。
将远程服务器上的文件复制到本地:sudo scp -P 60206 192.168.2.206:/usr/local/mysql/mysql-8.0.22-1.el7.x86_64.rpm-bundle.tar /usr/local/mysql/
目标服务器重装以后,key发生变化。解决办法:当前服务器(非目标服务器)vim ~/.ssh/known_hosts 删除这个目标服务器记录以后,重新添加即可。
查看内存占用:https://www.cnblogs.com/yushuo/p/14145014.html

安装rabbitmq

可参考https://www.jianshu.com/p/c64436a83a2b
通过下面命令来控制RabbitMQ:

sudo service rabbitmq-server start或invoke-rc.d rabbitmq-server start或sudo /usr/local/rabbitmq/sbin/rabbitmq-server start
sudo service rabbitmq-server stop
sudo service rabbitmq-server restart

我们通过命令开启web管理插件:

$ sudo rabbitmq-plugins enable rabbitmq_management

然后在主机中通过地址:http://192.168.2.199:15672即可访问到管理界面。
给用户管理员权限:

rabbitmqctl set_permissions -p / ganinfo ".*" ".*" ".*"

安装easydrawin

可参考https://blog.youkuaiyun.com/qq_37655695/article/details/91489452

安装ffmpeg

可参考:https://www.linuxidc.com/Linux/2018-10/154933.htm或https://blog.youkuaiyun.com/YCHANTY/article/details/107021669
卸载指令:sudo apt-get purge ffmpeg

安装jdk

可依次参考https://blog.youkuaiyun.com/baidu_38172402/article/details/80747916,
https://blog.youkuaiyun.com/qq_38666896/article/details/86657519,
https://blog.youkuaiyun.com/u011499686/article/details/50959126
source /etc/profile使环境变量生效

安装mysql

官网:https://dev.mysql.com/downloads/mysql/。
选下面这个:
在这里插入图片描述
彻底删除之前版本的MySQL可参考https://www.cnblogs.com/javahr/p/9245443.html。
安装参考https://blog.youkuaiyun.com/lmyclever/article/details/7421716。
重启MySQL命令:sudo systemctl restart mysqld.service

安装nginx

1.安装gcc c++的依赖库

apt-get install build-essential
apt-get install libtool

2.安装pcre依赖库

sudo apt-get update
sudo apt-get install libpcre3 libpcre3-dev

3.安装zlib依赖库

apt-get install openssl

4.下载、安装nginx

wget -c https://nginx.org/download/nginx-1.12.0.tar.gz
# 解压
tar -zxvf nginx-1.12.0.tar.gz
cd nginx-1.12.0/

# 使用默认配置
./configure --prefix=/usr/local/nginx

# 编译安装
make
make install

# 启动Nginx
cd /usr/local/nginx/sbin/
./nginx

# nginx相关命令
./nginx -s stop
./nginx -s quit
./nginx -s reload

# Nginx默认监听80端口,防火墙打开80端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload

# 查看nginx进程:
ps -ef|grep nginx

我应该用下面这个语句来解决You need a C++ compiler for C++ support.”这个问题

sudo apt-get install build-essential

报这种错误的话:Reading package lists… Done Building dependency tree Reading state informa
更新

sudo apt-get update
sudo apt-get upgrade

解决!!!!

*问题
在ubuntu系统下,使用./configure --prefix=/usr/local/nginx 安装nginx时候,报错:
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib= option.
* 解决
(1)在ubuntu软件源里zlib和zlib-devel分别叫做zlib1g 和zlib1g.dev

sudo apt-get  install zlib1g

sudo apt-get install zlib1g.dev(使用这个命令进行安装后,会报错)
(2)先安装ruby

sudo apt-get install ruby

(3)然后再使用命令sudo apt-get install zlib1g.dev进行安装,有的系统还会报错,主要是依赖的错误。
选择对应的依赖项重新安装一次,比如

sudo apt-get install zlib1g=1:1.2.8.dfsg-1ubuntu1.1.

然后安装zlib1g.dev,sudo apt-get install zlib1g.dev
(4)最后运行./configure脚本

如果在make install 时出现错误:./configure --prefix=/usr/local/nginx 改为
./configure --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/nginx.conf

安装activemq

下载链接:http://activemq.apache.org/activemq-5130-release
第一步: 把ActiveMQ 的压缩包上传到Linux系统。
第二步:解压缩。
第三步:启动。
使用bin目录下的activemq命令启动:

[root@localhost bin]# ./activemq start

关闭:

[root@localhost bin]# ./activemq stop

查看状态:

[root@localhost bin]# ./activemq status

注意:如果ActiveMQ整合spring使用不要使用activemq-all-5.12.0.jar包。建议使用5.11.2
进入管理后台:
http://192.168.25.168:8161/admin
用户名:admin
密码:admin
修改端口: 打开您的mq安装目录
进入conf文件夹
打开activemq.xml的配置文件
查找transportConnectors
找到name=“openwire” uri="tcp://0.
在:后面写上您所需的端口号
就可以修改成您想要的端口号了。
修改管理页面的8161端口:
还是在conf文件夹下
修改jetty.xml,修改内容容器jetty的默认启动端口,找到默认的8161后修改。

安装redis

先去官网下载,下载地址:http://download.redis.io/releases/
安装步骤参考:D:\1学习视频\01-2016java基础\02_就业班_最新北京JavaEE32期_20160717-20161206\03-redis(第27天)\redis安装
如果设置了密码
端口修改:cd /usr/local/redis,可复制一份redis.conf,改名为redis15020.cof,然后再到复制的那里改端口,也可直接在原配置文件下改端口。
设置开机自启参考:https://blog.youkuaiyun.com/y532798113/article/details/82426643

安装monogDB

参考:https://www.cnblogs.com/weschen/p/7395667.html和https://docs.mongodb.com/v3.4/tutorial/install-mongodb-on-ubuntu/#install-mongodb-community-edition?searchProperty=current&query=monogdb%203.4.18

sudo service mongod stop  #停止服务
sudo service mongod start  #启动服务
sudo service mongod restart #重新启动服务
sudo service mongod status #查看状态

允许开机启动,默认当重启服务器后,mongodb服务会停止,需要设置开机启动mongodb服务:

sudo systemctl enable mongod

安装FTP

环境:CentOS7.4
1.安装

yum install -y vsftpd
#检查是否已安装
rpm -qa |grep vsftpd
#卸载
rpm -e vsftpd安装版本号

2.设置开机自启动

systemctl enable vsftpd

3.启动服务

systemctl start vsftpd

4.打开防火墙,开放21端口(centos7.4以后默认关闭Firewall防火墙)

firewall-cmd --zone=public --permanent --add-port=21/tcp
firewall-cmd --zone=public --permanent --add-service=ftp
firewall-cmd --reload

5.添加ftp用户

useradd -g root -d /home/wwwroot/asite -s /sbin/nologin ftpuser
 #注:表示新增一个ftpuser(用户名),且指定上传目录在/home/wwwroot/asite下
#如果后期想变更此用户的上传目录到(/run/media/root/xxx/wwwroot/xxx.org),请使用下面的命令:
usermod -d /run/media/root/xxx/wwwroot/xxx.org ftpuser

6、设置用户密码

passwd ftpuser

7、配置selinux 允许ftp访问home和外网访问(默认关闭centos7.4)

setsebool -P allow_ftpd_full_access on
setsebool -P ftp_home_dir on

8、设置权限(此用户可以访问整个主机目录,后面备注设置权限问题)

chown -R ftpuser:root /home/wwwroot/asite

9、修改vsftp配置文件,禁用匿名登录
路径:vi /etc/vsftpd/vsftpd.conf
anonymous_enable=YES 改为: anonymous_enable=NO

其他命令:
重启 systemctl restart vsftod

启动/停止systemctl start/stop vsftod

状态 systemctl status vsftod
10.使ftp服务能够外网访问
修改配置文件:vi /etc/vsftpd/vsftpd.conf,内容如下:(注意!!!被动模式传输数据的端口若要映射到外网必须本地端口和映射后的外网端口一致!)

# Example config file /etc/vsftpd/vsftpd.conf
#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
# capabilities.
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=NO
#
# Uncomment this to allow local users to log in.
# When SELinux is enforcing check for SE bool ftp_home_dir
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
# When SELinux is enforcing check for SE bool allow_ftpd_anon_write, allow_ftpd_full_access
#anon_upload_enable=YES
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
#anon_mkdir_write_enable=YES
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# Activate logging of uploads/downloads.
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=NO
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
#chown_username=whoever
#
# You may override where the log file goes if you like. The default is shown
# below.
#xferlog_file=/var/log/xferlog
#
# If you want, you can have your log file in standard ftpd xferlog format.
# Note that the default log file location is /var/log/xferlog in this case.
xferlog_std_format=YES
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure
#
# Enable this and the server will recognise asynchronous ABOR requests. Not
# recommended for security (the code is non-trivial). Not enabling it,
# however, may confuse older FTP clients.
#async_abor_enable=YES
#
# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode. The vsftpd.conf(5) man page explains
# the behaviour when these options are disabled.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
#ascii_upload_enable=YES
#ascii_download_enable=YES
#
# You may fully customise the login banner string:
#ftpd_banner=Welcome to blah FTP service.
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd/banned_emails
#
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
# (Warning! chroot'ing can be very dangerous. If using chroot, make sure that
# the user does not have write access to the top level directory within the
# chroot)
#chroot_local_user=YES
#chroot_list_enable=YES
# (default follows)
#chroot_list_file=/etc/vsftpd/chroot_list
#
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
#ls_recurse_enable=YES
#
# When "listen" directive is enabled, vsftpd runs in standalone mode and
# listens on IPv4 sockets. This directive cannot be used in conjunction
# with the listen_ipv6 directive.
listen=YES
#
# This directive enables listening on IPv6 sockets. By default, listening
# on the IPv6 "any" address (::) will accept connections from both IPv6
# and IPv4 clients. It is not necessary to listen on *both* IPv4 and IPv6
# sockets. If you want that (perhaps because you want to listen on specific
# addresses) then you must run two copies of vsftpd with two configuration
# files.
# Make sure, that one of the listen options is commented !!
listen_ipv6=NO

pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
local_root=/home/video/upload
chroot_local_user=YES
allow_writeable_chroot=YES

max_clients=10240 #最大连接数,不限制改为0
max_per_ip=1000  #单IP最大连接数,不限制改为0
anon_max_rate=50000 #限制匿名用户50KB
local_max_rate=200000 #限制本地用户200KB

pasv_enable=YES
#支持数据流的被动式连接模式
pasv_min_port=20000  #设置被动模式传输数据的端口范围
pasv_max_port=25000  #设置被动模式传输数据的端口范围
pasv_address=47.96.149.47 #<your-static-ip-most-likely-from-elastic-ips>
pasv_addr_resolve=NO
#pasv_promiscuous=YES  #关闭PASV模式的安全检查
pasv_promiscuous=YES

11.配置说明
(1)主动模式:(公司内网使用可以选择此模式)

# vi /etc/vsftpd/vsftpd.conf
port_enable=YES
connect_from_port_20=YES

(2)被动模式:(需要映射到公网的就选择此模式,想对安全)

# vi /etc/vsftpd/vsftpd.conf
connect_from_port_20=NO
pasv_enable=YES(被动模式开启)
pasv_min_port=3010(最小端口)
pasv_max_port=3015(最大端口)
pasv_address=公网IP地址(非常重要这个)

说明:最小端口、最大端口范围最好是5-10端口就行,方便公网开通对应端口,端口数量太少,可能会导致有时候能连接上,有时候连接不上。
12.ftp服务器主动、被动模式区别

(1)主动模式(PORT):

原理:

FTP客户端连接到FTP服务器的21端口,发送用户名和密码登录,登录成功后要list列表或者读取数据时,客户端随机开放一个端口(1024以上), 发送PORT命令到FTP服务器,告诉服务器客户端采用主动模式并开放端口;FTP服务器收到PORT主动模式命令和端口号后,通过服务器的20端口和客户端 开放的端口连接,发送数据。

要点:

传送数据时是“服务器”连接到“客户端”的端口;

需要客户端必须开放端口给服务器,很多客户端都是在防火墙内,开放端口给FTP服务器访问比较困难;

(2)被动模式(PASV):

原理:

FTP 客户端连接到FTP服务器的21端口,发送用户名和密码登录,登录成功后要list列表或者读取数据时,发送PASV命令到FTP服务器, 服务器在本地随机开放一个端口(1024以上),然后把开放的端口告诉客户端, 客户端再连接到服务器开放的端口进行数据传输。

要点:

传送数据是“客户端”连接到“服务器”的端口;
只需要服务器端开放端口给客户端连接就行;

(3)如何选择ftp模式:

如果只是公司内部、局域网使用ftp,可以用主动模式,但是ftp客户端防火墙最好关掉或者开放ftp需要的数据端口范围,不存在安全问题也。如果是公网ftp就用被动模式,可以自定义端口,更加安全。
想要安全、连接方便就用被动模式。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值