Uninote
Uninote
用户根目录
common
guanjin
programming
docs
后端试题
问题讨论

这个是服务器部署的工具,用于全新环境的一键部署,本地开发不用

初始化流程

  • 复制 .git.zip 到 /root/init 下,并解压: unzip .git.zip
    • 也可以直接从 gogs 克隆,但这样会比较费流量 :)
    • git@git.uninote.com.cn:collin/mynote-env-init-v2.git
  • cd /root/init
  • 新建 pre.sh,并进行类似的配置(此脚本会在安装前加载,除了必要的配置可以添加任何需要的代码):
##### vm env
ip=41
deployment=vm$ip
front_host=192.168.0.$ip
gogs_host=$front_host
gogs_ssh_port=22
gogs_http_port=3000
gogs_http_url_decode=http://$front_host:$gogs_http_port
gogs_http_url=`urlEncode $gogs_http_url_decode`
es_host=es.uninote.com.cn
es_index=$deployment

# 安装脚本自身的分支,如果设置了,则先更新
init_branch=mynote
  • 新建 post.sh,不是必须要,但可以添加任何必要的后置脚本
  • 注意,pre.sh/post.sh 加入到了 .gitignore 中,不要试图在这里面添加需要进入 git 管理的代码。
  • 执行 bash all.sh,等待安装完成

完成后需要手动操作部分

  • api 配置
vi /home/www/mynote/basic/config/local_params.php
# 'debug.tel_code' => true, // 忽略手机验证码
  • mynote es mapping
  • 可能需要:systemctl disable packagekit
  • 开机自启动:修改 /etc/rc.d/rc.local
# for vm centos
systemctl stop firewalld

# debug时打开排错,然后在shell中设置PATH为下面的输出值,模拟启动时的环境
# echo $PATH > /tmp/start_env.log

mysql 时区

有时安装后时区有问题:

show variables like '%time_zone%';
# vi /etc/my.cnf.d/server.cnf

# This group is only read by MariaDB servers, not by MySQL.
# If you use the same .cnf file for MySQL and MariaDB,
# you can put MariaDB-only options here
[mariadb]
default-time-zone = '+8:00'

powder php.ini config

修改 cookie 生命周期配置,否则 powder 中 logout 时无法删除 cookie:

; Lifetime in seconds of cookie or, if 0, until browser is restarted.
; http://php.net/session.cookie-lifetime
session.cookie_lifetime = 2592000

; After this number of seconds, stored data will be seen as 'garbage' and
; cleaned up by the garbage collection process.
; http://php.net/session.gc-maxlifetime
session.gc_maxlifetime = 43200

重启 php-fpm:kill -USR2 [pid]

问题

开启了 set -e,在 gogs 安装时一定会报错退出:

涉及的 commits:

因为在循环中等待 gogs 启动时第一次一定是 curl 会报错的:

Start_Gogs
# 等待 gogs 启动,重试10次(10秒)
try_count=0
set +e
while (($try_count < 10)); do :
    curl "http://127.0.0.1:3000/install" --data "db_type=MySQL&db_host=127.0.0.1%3A3306&db_user=root&db_passwd=$db_passwd&db_name=gogs&ssl_mode=disable&db_path=data%2Fgogs.db&app_name=Gogs&repo_root_path=%2Fhome%2Fgit%2Fgogs-repositories&run_user=git&domain=$gogs_host&ssh_port=$gogs_ssh_port&http_port=$gogs_http_port&app_url=$gogs_http_url&log_root_path=%2Fhome%2Fgit%2Fgogs%2Flog&smtp_host=&smtp_from=&smtp_user=&smtp_passwd=&enable_captcha=on&admin_name=&admin_passwd=&admin_confirm_passwd=&admin_email=" --compressed --insecure
    a=$?
    if [ "$a" == "0" ]
    then
        echo 'Gogs installed!'
        break;
    fi
    ((try_count++))
    sleep 1
done
set -e

if (($try_count >= 10))
then
    echo 'Gogs install error!'
fi

解决方案

(()) 后必须接一个 && 命令,可以用 ':' 接一个空操作:

Start_Gogs

# 等待 gogs 启动,重试10次(10秒)
try_count=0
curl_data="db_type=MySQL&db_host=127.0.0.1%3A3306&db_user=root&db_passwd=$db_passwd&db_name=gogs&ssl_mode=disable&db_path=data%2Fgogs.db&app_name=Gogs&repo_root_path=%2Fhome%2Fgit%2Fgogs-repositories&run_user=git&domain=$gogs_host&ssh_port=$gogs_ssh_port&http_port=$gogs_http_port&app_url=$gogs_http_url&log_root_path=%2Fhome%2Fgit%2Fgogs%2Flog&smtp_host=&smtp_from=&smtp_user=&smtp_passwd=&enable_captcha=on&admin_name=&admin_passwd=&admin_confirm_passwd=&admin_email="
while (($try_count < 10)); do :
    if curl "http://127.0.0.1:3000/install" --data $curl_data --compressed --insecure
    then
        echo 'Gogs installed!'
        break;
    fi
    ((try_count++)) && :
    sleep 1
done

if (($try_count >= 10))
then
    echo 'Gogs install error!'
fi

front-dev

常用链接

点赞(0) 阅读(319) 举报
目录
标题