daily pastebin goal
60%
SHARE
TWEET

Reddit Open Source - Installation Guide

a guest Mar 24th, 2018 39 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Install reddit, create a Reddit clone
  2.  
  3. ## 1. Create a Ubuntu 14.04 VM with VirtualBox
  4.  
  5. 1. Download Ubuntu 14.04 server edition
  6. 1. In VirtualBox, after creating a new VM with 4gb RAM and 30gb disk space,
  7. 1. Set networking to use a "Bridged Adapter"
  8. 1. Add a CD rom entry and select the Ubuntu 14 .iso
  9. 1. Boot the VM
  10. 1. In the Ubuntu installer, put "-VM" in the hostname when asked to choose a hostname
  11. 1. Choose user "reddit"
  12. 1. Choose to install "OpenSSH Server"
  13. 1. Complete Ubuntu installation.
  14. 1. Login and run `ifconfig` and note your ip address
  15. 1. If you forgot to install the openssh server, run `sudo apt-get install openssh-server`
  16. 1. You can now detach your VM or shut it down and restart in headless mode. You should only interact with it via SSH from your host for easy copy and paste, etc. Don't forget to shut down your VM before shutting down the host or you may corrupt files.
  17. 1. Don't use VirtualBox snapshots or bother backing up your VM. Instead push your work to github and consider the VM transient.
  18.  
  19. ## 2. Update your host's hosts file to resolve "reddit.local" in your browser
  20.  
  21. Add the ip you noted earlier to your hosts file along with domain `reddit.local`. This varies by OS.
  22.  
  23. Once this is setup you can ssh into your VM easily with `ssh reddit@reddit.local`. Even more easily if you install your ssh key on the VM.
  24.  
  25. Bonus: mount VM files for local editing. You can easily mount the VM's files as a drive on your host machine for easy editing and searching. Sshfs is a quick and easy approach, run `sshfs reddit@reddit.local:/home/reddit ~/vm`. You can unmount later with `fusermount -u ~/vm` to avoid crashing your editor when shutting down your VM. Caution: mounting too many directories/files with sshfs is slow, after reddit installation you can try mounting `/home/reddit/src/reddit` instead.
  26.  
  27. ## 3. Install reddit
  28.  
  29. SSH into your VM as user "reddit", and run:
  30.  
  31.     # WARNING: Never run an apt-get "do-release-upgrade" or you will break reddit. You must stay on Ubuntu 14.
  32.     sudo apt-get update
  33.     sudo apt-get upgrade
  34.     sudo apt-get install git
  35.     # TODO: needs installer(s) and example.ini updates
  36.     # git clone https://github.com/libertysoft3/reddit-ae.git
  37.     git clone https://github.com/libertysoft3/reddit.git
  38.     # TODO: change the next 2 commands if using "reddit-ae"
  39.     sudo chmod +x reddit/install-reddit.sh
  40.     sudo ./reddit/install/reddit.sh
  41.     # NOTE: reddit has been installed outside of this repo, check ~/src/reddit. this is due to needing other git repos being checked out.
  42.     # TODO - Refactor to use git submodules, no misdirection needed.
  43.     # if weird make error about "less" restart the server and try again
  44.  
  45.     # Optional - install sample data
  46.     cd ~/src/reddit
  47.     reddit-run scripts/inject_test_data.py -c 'inject_test_data()'
  48.     # NOTE: with sample data, an admin user "reddit" with password "password" is created (???)
  49.     # protip: if you create your admin account first (step 4) you will have a generated comment history
  50.  
  51.     # Avoids an error with 'popular_sr_ids' on registration (custom feature)
  52.     # TODO: does cron also need to be updated to include this? Also used for choosing /r/random.
  53.     sudo start reddit-job-update_popular_subreddits
  54.  
  55. ## 4. Configure reddit
  56.  
  57. Make "yourself" an admin account:
  58.  
  59.     cd ~/src/reddit/r2
  60.     nano development.update
  61.     # edit this line: employees = reddit:admin
  62.     # add: ", yourself:admin"
  63.     make ini
  64.     sudo reddit-flush
  65.     # Create a reddit account in your host browser https://reddit.local
  66.     # You should see the "turn admin on" link
  67.  
  68. Increase PostgreSQL max_connections for greater Solr compatibility (87/100 in use at reddit idle without solr running?):
  69.  
  70.     sudo nano /etc/postgresql/9.3/main/postgresql.conf
  71.     # edit: change max_connections = 100 to 150, save
  72.     sudo service postgresql restart
  73.     sudo reddit-restart
  74.  
  75.  
  76. ## 5. Optional: install Solr (for search)
  77.  
  78. As user "reddit" run:
  79.     sudo apt-get install tomcat7 tomcat7-admin software-properties-common
  80.     # installs java, openjdk-7-jre-headless
  81.     # TODO: Would tomcat6 be more performant?
  82.     cd ~
  83.     wget http://archive.apache.org/dist/lucene/solr/4.10.4/solr-4.10.4.tgz
  84.     tar -xvzf solr-4.10.4.tgz
  85.     sudo mv solr-4.10.4 /usr/share/solr
  86.     sudo chown -R tomcat7:tomcat7 /usr/share/solr/example
  87.  
  88.     # Setup Solr, install Reddit schema
  89.     sudo cp /usr/share/solr/example/webapps/solr.war /usr/share/solr/example/solr/
  90.     sudo cp /usr/share/solr/example/lib/ext/* /usr/share/tomcat7/lib/
  91.     sudo cp /usr/share/solr/example/resources/log4j.properties /usr/share/tomcat7/lib/
  92.  
  93.     sudo mv /usr/share/solr/example/solr/collection1/conf/schema.xml /usr/share/solr/example/solr/collection1/conf/schema.xml.bak
  94.     sudo cp src/reddit/solr/schema4.xml /usr/share/solr/example/solr/collection1/conf/schema.xml
  95.     sudo chown tomcat7:tomcat7 /usr/share/solr/example/solr/collection1/conf/schema.xml
  96.  
  97.     # Setup Tomcat for Solr
  98.     sudo nano /usr/share/tomcat7/lib/log4j.properties
  99.     # edit to set:
  100.     solr.log=/usr/share/solr
  101.  
  102.     sudo nano /etc/tomcat7/Catalina/localhost/solr.xml
  103.     # add content:
  104.     <Context docBase="/usr/share/solr/example/solr/solr.war" debug="0" crossContext="true">
  105.       <Environment name="solr/home" type="java.lang.String" value="/usr/share/solr/example/solr" override="true" />
  106.     </Context>
  107.  
  108.     # have tomcat use port 8983, 8080 is taken by haproxy
  109.     sudo nano /etc/tomcat7/server.xml
  110.     # edit to set:
  111.     <Connector port="8983" protocol="HTTP/1.1"
  112.  
  113.     # Solr is missing some required stuff:
  114.     sudo touch /usr/share/solr/solr.log
  115.     sudo mkdir /usr/share/tomcat7/temp
  116.     sudo chown tomcat7:tomcat7 /usr/share/solr/solr.log
  117.     sudo chown tomcat7:tomcat7 /usr/share/tomcat7/temp
  118.  
  119.     # verify tomcat all good (ignore warnings):
  120.     /usr/share/tomcat7/bin/configtest.sh
  121.  
  122.     sudo service tomcat7 restart
  123.  
  124.     # any errors in here must be fixed
  125.     sudo cat /var/log/tomcat7/catalina.out
  126.  
  127.     # verify working, these should return html pages:
  128.     wget 127.0.0.1:8983
  129.     wget 127.0.0.1:8983/solr
  130.  
  131. Configure Reddit to use Solr for search:
  132.  
  133.     # as non-root user
  134.     nano ~/src/reddit/r2/example.ini
  135.     # EDIT: change: search_provider = cloudsearch to: search_provider = solr
  136.     # EDIT: add below (solr port changed from default 8080 to 8983):
  137.     solr_version = 4
  138.     solr_search_host = 127.0.0.1
  139.     solr_doc_host = 127.0.0.1
  140.     solr_subreddit_search_host = 127.0.0.1
  141.     solr_subreddit_doc_host = 127.0.0.1
  142.     solr_port = 8983
  143.     solr_core = collection1
  144.     solr_min_batch = 500
  145.     solr_query_parser =
  146.  
  147.     # since example.ini has changed
  148.     cd ~/src/reddit/r2
  149.     make ini
  150.     # ???? sudo reddit-restart
  151.  
  152. Add reddit content to Solr, verify working:
  153.     cd ~/src/reddit/r2
  154.     paster run run.ini -c 'import r2.lib.providers.search.solr as cs; cs.rebuild_subreddit_index()'
  155.     paster run run.ini -c 'import r2.lib.providers.search.solr as cs; cs._rebuild_link_index()'
  156.  
  157.  
  158. ### Setup Solr cron jobs:
  159.  
  160. TODO - install/reddit.sh copies upstart/* to /etc/init/
  161. TODO - in source put this/these in upstart/reddit-job-solr_subreddits.conf and reddit-job-solr_links.conf
  162.  
  163.     sudo nano /etc/init/reddit-job-solr_subreddits.conf
  164.     # paste lines, save:
  165.     description "Add new subreddits to Solr."
  166.     manual
  167.     task
  168.     stop on reddit-stop or runlevel [016]
  169.     nice 10
  170.     script
  171.         . /etc/default/reddit
  172.         wrap-job paster run $REDDIT_INI -c 'import r2.lib.providers.search.solr as cs; cs.rebuild_subreddit_index()'
  173.     end script
  174.  
  175. and then...
  176.  
  177.     sudo nano /etc/init/reddit-job-solr_links.conf
  178.     # paste lines, save:
  179.     description "Add new posts to Solr."
  180.     manual
  181.     task
  182.     stop on reddit-stop or runlevel [016]
  183.     nice 10
  184.     script
  185.         . /etc/default/reddit
  186.         wrap-job paster run $REDDIT_INI -c 'import r2.lib.providers.search.solr as cs; cs._rebuild_link_index()'
  187.     end script
  188.  
  189. and then...
  190.  
  191.     echo '# Solr search:' | sudo tee --append /etc/cron.d/reddit
  192.     echo '*/3  * * * * root /sbin/start --quiet reddit-job-solr_subreddits' | sudo tee --append /etc/cron.d/reddit
  193.     echo '* * * * * root /sbin/start --quiet reddit-job-solr_links' | sudo tee --append /etc/cron.d/reddit
  194.    
  195. Tail /var/log/syslog to see the status of these and other jobs. Log files exist for each upstart job, e.g. /var/log/upstart/reddit-job-solr_rebuild_link_index.log. You can manually run upstart jobs, e.g. sudo start reddit-job-update_reddits
  196.  
  197.  
  198.  
  199. ## References
  200.  
  201. * https://github.com/reddit/reddit/tree/master/solr
  202. * http://webikon.com/cases/installing-apache-solr-4-7-multicore-on-ubuntu-12-04-and-tomcat7
  203. * https://drupal.stackexchange.com/questions/95897/apache-solr-4-6-0-installation-and-compatibility-with-drupal7/124038#124038
  204. * https://www.digitalocean.com/community/tutorials/how-to-install-solr-on-ubuntu-14-04
  205. * https://www.digitalocean.com/community/tutorials/how-to-install-solr-5-2-1-on-ubuntu-14-04
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top