关于本文
- 写作目标:作为在linux下安装JDK、MySQL、Zookeeper、Redis、MongoDB、RabbitMQ等开发组件的快速参考指南
- Linux版本:Linux Mint 18.2 Sonya(基于Ubuntu 16.04 Xenial)
实战记录
- JAVA OpenJDK
sudo apt install openjdk-8-jdk
- MySQL
安装
wget https://dev.mysql.com/get/mysql-apt-config_0.8.6-1_all.debdpkg -i mysql-apt-config_0.8.6-1_all.debapt updateapt install mysql-server
配置
vi /etc/mysql/conf.d/mysql.cnf[mysql]default-character-set=utf8vi /etc/mysql/mysql.conf.d/mysqld.cnf[mysqld]# 注释如下配置以允许远程访问# bind-address = 127.0.0.1character-set-server=utf8default-time-zone='+8:00'# 重启服务sudo service mysql restart
常用命令
# 登录mysql -uroot -p# 创建用户、数据库create user 'test'@'%' identified by '123456';create database test;grant all on test.* to 'test'@'%';flush privileges;# 重置root密码sudo service mysql stopsudo mkdir -p /var/run/mysqldsudo chown mysql:adm /var/run/mysqldsudo nohup mysqld_safe --skip-grant-tables --skip-networking &#进入mysql shell后用下面修改密码的方式更改root密码mysqlupdate mysql.user set authentication_string=password('123456') where user='root' and host = 'localhost';#重启服务mysqladmin shutdownsudo service mysql start# 修改密码#方式一 (https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html)set password for 'root'@'localhost'=password('123456');flush privileges;#方式二update mysql.user set authentication_string=password('123456') where user='root' and host = 'localhost';flush privileges;# 修改数据库字符集alter database test character set utf8;# 查看mysql字符集默认配置show variables like '%character%';# 复制数据库:将数据库db1复制到数据库db2 (https://dev.mysql.com/doc/refman/5.7/en/mysqldump-copying-database.html)mysqldump -uroot -p db1 > dump.sqlmysqladmin -uroot -p create db2mysql -uroot -p db2 < dump.sql
- Zookeeper (启动前必须先安装好JDK)
从Ubuntu软件仓库安装
sudo apt install zookeeperd
从zookeeper官网下载(推荐此方式,可使用最新稳定版)
#切换到root用户su -cd /usr/local/sharewget http://mirrors.aliyun.com/apache/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gztar xzf zookeeper-3.4.10.tar.gzcd zookeeper-3.4.10mv zookeeper-3.4.10 zookeepercp conf/zoo_sample.cfg conf/zoo.cfgvi conf/zoo.cfg # 修改 dataDir=/var/lib/zookeeper# 启动服务bin/zkServer.sh start# 安装为系统自启服务 (https://issues.apache.org/jira/browse/ZOOKEEPER-2095)vi /lib/systemd/system/zookeeper.service---------------------------------------------------------[Unit]Description=Apache ZookeeperAfter=network.target[Service]Type=forkingSyslogIdentifier=zookeeperRestart=alwaysRestartSec=0sExecStart=/usr/local/share/zookeeper/bin/zkServer.sh startExecStop=/usr/local/share/zookeeper/bin/zkServer.sh stopExecReload=/usr/local/share/zookeeper/bin/zkServer.sh restart[Install]WantedBy=multi-user.target---------------------------------------------------------systemctl start zookeepersystemctl enable zookeeper
- Redis
从Ubuntu软件仓库安装
sudo apt install redis-server
从redis官网下载(推荐此方式,可使用最新稳定版)
#切换到root用户su -cd /usr/local/sharewget http://download.redis.io/releases/redis-3.2.9.tar.gztar xzf redis-3.2.9.tar.gzcd redis-3.2.9make# 启动服务nohup src/redis-server redis.conf > redis-server.out &# 或者安装为系统自启服务 (设置 redis executable path 时指定 src/redis-server 所在的完整路径)utils/install_server.sh/etc/init.d/redis_6379 startupdate-rc.d redis_6379 defaults
配置
# 使用场景举例:允许内网环境中其他机器访问时,假设redis安装机器IP为172.18.1.10,可按如下配置vi redis.confbind 127.0.0.1 172.18.1.10# 使用redis-cli进行访问验证 (redis-cli与redis-server在同一个目录)redis-cli -h 172.18.1.10 -p 6379# 使用场景举例:开启远程访问 (注释掉bind配置项,修改requirepass、masterauth配置项)# 务必设置非常复杂、长度很大的密码vi redis.conf#bind 127.0.0.1# 在master实例修改requirepass配置项requirepass Fmg1$7!&bcNp@iY0tW6pEVPP!FZ9vHMd5a%TOJAGI8bO7qqT1%# 在slave实例修改masterauth配置项masterauth Fmg1$7!&bcNp@iY0tW6pEVPP!FZ9vHMd5a%TOJAGI8bO7qqT1%# 验证授权# ./redis-cli -a 'Fmg1$7!&bcNp@iY0tW6pEVPP!FZ9vHMd5a%TOJAGI8bO7qqT1%'# 如果启用密码访问,须要修改/etc/init.d/redis_6379$CLIEXEC -p $REDISPORT -a 'Fmg1$7!&bcNp@iY0tW6pEVPP!FZ9vHMd5a%TOJAGI8bO7qqT1%' shutdown# 修改完配置后注意重启服务/etc/init.d/redis_6379 restart
- MongoDB
安装
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927# 使用阿里云镜像站,加快下载速度sudo echo "deb http://mirrors.aliyun.com/mongodb/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.listsudo apt-get updatesudo apt-get install -y mongodb-org
配置
- 默认配置文件路径是/etc/mongod.conf
- 如果想为mongos或mongod绑定多个监听的IP地址,可将net.bindIp设置为英文逗号分割的多个IP地址
# 使用场景举例:允许内网环境中其他机器访问时,假设mongod安装机器IP为172.18.1.10,可按如下配置vi /etc/mongod.confnet: bindIp: 127.0.0.1,172.18.1.10# 使用场景举例:开启远程访问 (注释net.bindIp配置项,添加security.authorization配置项;创建授权用户)vi /etc/mongod.confnet: # bindIp: 127.0.0.1security: authorization: enabledmongouse admindb.createUser( { user: "root", pwd: "123456", roles: [ { role: "root", db: "admin" } ] })use testdb.createUser( { user: "test", pwd: "123456", roles: [ { role: "dbOwner", db: "test" } ] })# 重启服务以使配置生效sudo service mongod restart# 开启授权后的登录举例,特别注意authenticationDatabase参数的使用,它与用户所授权角色对应的数据库有关,root角色拥有所有库的所有操作权限,dbOwner角色只有授权库的所有操作权限mongo localhost:27017/test -u "root" -p "123456" --authenticationDatabase "admin"mongo localhost:27017/test -u "test" -p "123456" --authenticationDatabase "test"
- RabbitMQ
使用PackageCloud APT Repository进行安装
curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.deb.sh | sudo bashsudo apt-get install rabbitmq-server
使用RabbitMQ APT Repository进行安装
echo 'deb http://www.rabbitmq.com/debian/ testing main' | sudo tee /etc/apt/sources.list.d/rabbitmq.listwget -O- https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | sudo apt-key add -或者wget -O- https://dl.bintray.com/rabbitmq/Keys/rabbitmq-release-signing-key.asc | sudo apt-key add -sudo apt-get updatesudo apt-get install rabbitmq-server
配置
- 配置所在路径:在/var/log/rabbitmq/rabbit@{计算机名}.log查看;
默认情况rabbitmq.config、rabbitmq-env.conf在目录/etc/rabbitmq/中,如果文件不存在可自行创建,
rabbitmq.config配置示例:/usr/share/doc/rabbitmq-server/rabbitmq.config.example.gz或者访问,也可通过设置系统环境变量RABBITMQ_CONFIG_FILE、RABBITMQ_CONF_ENV_FILE指定具体路径; 修改完成后须要重启rabbimq-server服务; 默认配置如下,注意RABBITMQ_CONFIG_FILE配置路径不用添加.config后缀,Erlang运行时会自动追加:RABBITMQ_CONFIG_FILE=/etc/rabbitmq/rabbitmqRABBITMQ_CONF_ENV_FILE=/etc/rabbitmq/rabbitmq-env.conf
- 默认账号: 用户名密码都是guest
默认只能通过loopback地址(例如localhost)连接guest账号,如果想允许远程访问,须要修改rabbitmq.config(将loopback_users配置项设为[]):[{rabbit, [{loopback_users, []}]}].
- ,执行
sudo rabbitmq-plugins enable rabbitmq_management
启用成功后可访问进行管理 - 其他常用指令
# 创建新用户,增加权限sudo rabbitmqctl add_user test 123456sudo rabbitmqctl set_permissions -p / test ".*" ".*" ".*"sudo rabbitmqctl set_user_tags test administrator# 验证账号sudo rabbitmqctl authenticate_user test 123456# 修改密码 sudo rabbitmqctl change_password test 123456
(本文首发我的个人网站 )