CentOS服务器利用docker搭建中间件命令集合

一、挂载服务器磁盘

#挂盘语句
fdisk /dev/vdb  在分别输入n、p、1、2048、1048575999、w
mkfs.ext4 /dev/vdb 
mkdir /data
echo /dev/vdb /data ext4 defaults 0 0 >> /etc/fstab
mount -a
df -h

firewall-cmd --zone=public --add-port=8002/tcp --permanent
firewall-cmd --reload

firewall-cmd --zone=public --remove-port=80/tcp --permanent
firewall-cmd --zone=public --query-port=1521/tcp

二、Docker安装

**yum install -y yum-utils
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache fast
yum install docker-ce docker-ce-cli containerd.io
systemctl start docker
docker version
docker images
docker ps -a

三、Docker Redis安装

docker network create --driver bridge --subnet=172.18.12.0/16 --gateway=172.18.1.1 wn_docker_net

docker search redis
docker pull redis
docker images -a
#创建映射目录
mkdir /data/docker/redis_6379
docker run --restart=always --log-opt max-size=200m --log-opt max-file=2 -p 6379:6379 --name redis_6379 -v /data/docker/redis_6379/myredis.conf:/etc/redis/redis.conf -v /data/docker/redis_6379/data:/data -d redis redis-server /etc/redis/redis.conf  --appendonly yes  --requirepass 你自己的密码

#测试
docker exec -it redis_6379 bash
redis-cli
keys *
auth 你自己的密码

四、Docker zookeeper安装

docker pull zookeeper
#创建映射目录
mkdir /data/docker/zookeeper
mkdir /data/docker/zookeeper/data
docker run -d -e TZ="Asia/Shanghai" -p 2181:2181 -v /data/docker/zookeeper:/data --name zookeeper --restart always zookeeper
#看看启动了吗
docker ps -a 

五、Docker rabbitMQ安装

docker pull rabbitmq:latest
docker run -id --hostname myrabbit --name rabbitmq1 -p 15672:15672 -p 5672:5672 rabbitmq
docker exec -it rabbitmq1 /bin/bash
rabbitmq-plugins enable rabbitmq_management
exit
docker restart xxx #对应的rabbitmq id 不知道可以 docker ps -a 看一下
docker exec -it rabbitmq1 /bin/bash #进控制台
rabbitmqctl add_user 用户名 密码 
rabbitmqctl set_user_tags 用户名 administrator
rabbitmqctl set_permissions -p / 用户名 ".*" ".*" ".*"

六、Docker mysql 5.7安装

docker pull mysql:5.7

docker run -p 3306:3306 --name mysql --privileged=true -v /data/docker/mysql/conf:/etc/mysql/conf.d -v /data/docker/mysql/data:/var/lib/mysql -v /data/docker/mysql/my.cnf:/etc/mysql/my.cnf  -e MYSQL_ROOT_PASSWORD=root密码 -e lower_case_table_names=1 -d mysql:5.7

七、安装nginx

#官网自己下一个tar.gz包上传到服务器解压  http://nginx.org/en/download.html
#安装依赖
yum -y install gcc automake make pam-devel openldap-devel cyrus-sasl-devel openssl-devel
yum install pcre-devel zlib zlib-devel openssl openssl-devel

#编译安装
./configure --with-stream --with-stream=dynamic --with-http_ssl_module
make
make install
vim /etc/init.d/nginx [内容在下面]
chmod 755 /etc/init.d/nginx
chkconfig nginx on
vi /usr/local/nginx/conf/nginx.conf
systemctl start nginx
systemctl status nginx
systemctl restart nginx
#!/bin/sh
#
#nginx - this script starts and stops the nginx daemin
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /usr/local/nginx/logs/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
lockfile=/var/lock/subsys/nginx
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac

你可能感兴趣的:(服务器,centos,docker)