2019-03-28

centos上常用环境配置

centos上安装docker

sudo yum update

sudo yum remove docker docker-common docker-selinux docker-engine

sudo yum install -y yum-utils device-mapper-persistent-data lvm2

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

yum list docker-ce --showduplicates | sort -r

sudo yum install docker-cesudo yum install [version]

sudo systemctl start dockersudo systemctl enable docker

docker version

安装mysql

docker pull centos/mysql-57-centos7 安装镜像
docker run -di --name=mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 centos/mysql-57-centos7 安装容器

安装tomcat

参考
sudo yum install java-1.8.0-openjdk.x86_64安装jdk1.8
java -version查看是否成功

sudo groupadd tomcat
sudo useradd -s /bin/nologin -g tomcat -d /opt/tomcat tomcat
cd ~
wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.39/bin/apache-tomcat-8.5.39.tar.gz
sudo tar -zxvf apache-tomcat-8.5.39.tar.gz -C /opt/tomcat --strip-components=1
# 权限配置
cd /opt/tomcat
sudo chown -R tomcat .
sudo chgrp -R tomcat conf
sudo chmod g+rwx conf
sudo chmod g+r conf/*
sudo chown -R tomcat logs/ temp/ webapps/ work/
# 为Tomcat创建systemd unit 文件
sudo vi /etc/systemd/system/tomcat.service
[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target

[Service]
Type=forking

Environment=JAVA_HOME=/usr/lib/jvm/jre
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'

ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/bin/kill -15 $MAINPID

User=tomcat
Group=tomcat

[Install]
WantedBy=multi-user.target
# 安装haveged
sudo yum install haveged
sudo systemctl start haveged.service
sudo systemctl enable haveged.service
# 配置防火墙
sudo systemctl start tomcat.service
sudo systemctl enable tomcat.service

sudo firewall-cmd --zone=public --permanent --add-port=8080/tcp
sudo firewall-cmd --reload
# 配置Tomcat 管理界面
sudo vi /opt/tomcat/conf/tomcat-users.xml

<tomcat-users ...>...</tomcat-users>中加入一个admin账号:

<user username="yourusername" password="yourpassword" roles="manager-gui,admin-gui"/>
# 重启Tomcat
sudo systemctl restart tomcat.service

安装nginx

yum install -y nginxnginx 启动
nginx -t 测试Nginx配置是否正确
nginx -s reload 重启
nginx -s stop 停止服务 配置HTTPS访问

server {
      listen 443;
      listen 80; 
      server_name www.weigram.com; #填写绑定证书的域名
      ssl on;
      ssl_certificate 1_www.weigram.com_bundle.crt;
      ssl_certificate_key 2_www.weigram.com.key;
      ssl_session_timeout 5m;
      ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #按照这个协议配置
      ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;#按照这个套件配置
      ssl_prefer_server_ciphers on;
      
      root /usr/blog; 
      error_page 497 https://$host$uri?args;#让http请求重定向到https请求  
      location / {
        index index.html;
      }
  }

利用rsync同步文件到服务器

rsync的使用
rsync基本命令和用法

centos配置

yum -y install rsync 安装
配置 /etc/rsyncd.conf

uid = root
gid = root
max connections = 4 
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log

#下面这个模块区域可以配置多个,每一个代表一个允许同步的path
[blog]
path = /usr/blog/ 
ignore errors
read only = no
list = true
auth user = root
secrets file = /etc/rsyncd.pwd

同时设置/etc/rsyncd.pwd

root:rootpassword

rsync --daemon 启动,会打开端口873
pkill rsync 停止rsync daemon

windows 推送

安装
将bin目录加入环境变量,在软件目录新建rsync.pass文件,只写入密码后保存。--delete 会删除远程文件夹强制同步,一定要设置文件的权限,否则Nginx会返回403 参考

rsync -avz --chmod=Du=rwx,Dgo=rx,Fu=rw,Fog=r  --chown=0:0 --password-file=F:\ProgramFiles\cwRsync_5.4.1_x86_Free\rsync.pass --delete-before   ./dist/ root@118.89.189.78::blog

当我本地文件夹使用完整路径时报错。不知道为什么报错

rsync -avzP --delete  --password-file=F:\ProgramFiles\cwRsync_5.4.1_x86_Free\rsync.pass   F:\idea\dist root@118.89.189.78::blog
# 报错信息
The source and destination cannot both be remote.
rsync error: syntax or usage error (code 1) at main.c(1274) [Receiver=3.1.2]

在rsync一个目录的时候,可以手动的排除其中的某一些文件和子目录

rsync -avzP  --chown=0:0 --chmod=644 --exclude='Suite' /cygdrive/d/workspace/test root@192.168.xx.xxx::test